1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-04-09 06:15:49 +02:00

Fuck CultureInfo some more and fix analysis violations (dispose pattern, lang features)

This commit is contained in:
chylex 2017-07-07 23:53:04 +02:00
parent eb8159ca0f
commit 14d44528b0
15 changed files with 38 additions and 42 deletions

View File

@ -198,7 +198,7 @@ private void browser_LoadError(object sender, LoadErrorEventArgs e){
return;
}
if (!e.FailedUrl.StartsWith("http://td/")){
if (!e.FailedUrl.StartsWith("http://td/", StringComparison.Ordinal)){
string errorPage = ScriptLoader.LoadResource("pages/error.html", true);
if (errorPage != null){

View File

@ -113,7 +113,7 @@ protected void SetClipboardText(string text){
form.InvokeAsyncSafe(() => WindowsUtils.SetClipboard(text, TextDataFormat.UnicodeText));
}
protected void AddDebugMenuItems(IMenuModel model){
protected static void AddDebugMenuItems(IMenuModel model){
model.AddItem((CefMenuCommand)MenuOpenDevTools, "Open dev tools");
}

View File

@ -18,12 +18,8 @@ partial class FormNotificationMain : FormNotificationBase{
private static readonly string NotificationScriptIdentifier = ScriptLoader.GetRootIdentifier(NotificationScriptFile);
private static readonly string PluginScriptIdentifier = ScriptLoader.GetRootIdentifier(PluginManager.PluginNotificationScriptFile);
private static readonly string NotificationJS, PluginJS;
static FormNotificationMain(){
NotificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
PluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile);
}
private static readonly string NotificationJS = ScriptLoader.LoadResource(NotificationScriptFile);
private static readonly string PluginJS = ScriptLoader.LoadResource(PluginManager.PluginNotificationScriptFile);
private readonly PluginManager plugins;

View File

@ -68,10 +68,10 @@ public TabSettingsNotifications(FormNotificationMain notification){
checkNonIntrusive.Checked = Config.NotificationNonIntrusiveMode;
trackBarScrollSpeed.SetValueSafe(Config.NotificationScrollSpeed);
labelScrollSpeedValue.Text = trackBarScrollSpeed.Value.ToString(CultureInfo.InvariantCulture)+"%";
labelScrollSpeedValue.Text = trackBarScrollSpeed.Value+"%";
trackBarEdgeDistance.SetValueSafe(Config.NotificationEdgeDistance);
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value.ToString(CultureInfo.InvariantCulture)+" px";
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value+" px";
this.notification.CanMoveWindow = () => radioLocCustom.Checked;
this.notification.CanResizeWindow = radioSizeCustom.Checked;
@ -233,7 +233,7 @@ private void comboBoxIdlePause_SelectedValueChanged(object sender, EventArgs e){
private void trackBarScrollSpeed_ValueChanged(object sender, EventArgs e){
if (trackBarScrollSpeed.AlignValueToTick()){
labelScrollSpeedValue.Text = trackBarScrollSpeed.Value.ToString(CultureInfo.InvariantCulture)+"%";
labelScrollSpeedValue.Text = trackBarScrollSpeed.Value+"%";
Config.NotificationScrollSpeed = trackBarScrollSpeed.Value;
}
}
@ -244,7 +244,7 @@ private void comboBoxDisplay_SelectedValueChanged(object sender, EventArgs e){
}
private void trackBarEdgeDistance_ValueChanged(object sender, EventArgs e){
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value.ToString(CultureInfo.InvariantCulture)+" px";
labelEdgeDistanceValue.Text = trackBarEdgeDistance.Value+" px";
Config.NotificationEdgeDistance = trackBarEdgeDistance.Value;
notification.ShowNotificationForSettings(false);
}

View File

@ -18,7 +18,7 @@ public static string HeaderAcceptLanguage{
return "en-us,en";
}
else{
return culture.ToLowerInvariant()+",en;q=0.9";
return culture.ToLower()+",en;q=0.9";
}
}
}

View File

@ -14,7 +14,7 @@ public static int[] ParseInts(string str, char separator){
}
public static string ConvertPascalCaseToScreamingSnakeCase(string str){
return Regex.Replace(str, @"(\p{Ll})(\P{Ll})|(\P{Ll})(\P{Ll}\p{Ll})", "$1$3_$2$4").ToUpperInvariant();
return Regex.Replace(str, @"(\p{Ll})(\P{Ll})|(\P{Ll})(\P{Ll}\p{Ll})", "$1$3_$2$4").ToUpper();
}
}
}

View File

@ -38,31 +38,31 @@ public static void ReadStringArray(char entryChar, string[] array, CommandLineAr
public int Count => flags.Count+values.Count;
public void AddFlag(string flag){
flags.Add(flag.ToLowerInvariant());
flags.Add(flag.ToLower());
}
public bool HasFlag(string flag){
return flags.Contains(flag.ToLowerInvariant());
return flags.Contains(flag.ToLower());
}
public void RemoveFlag(string flag){
flags.Remove(flag.ToLowerInvariant());
flags.Remove(flag.ToLower());
}
public void SetValue(string key, string value){
values[key.ToLowerInvariant()] = value;
values[key.ToLower()] = value;
}
public bool HasValue(string key){
return values.ContainsKey(key.ToLowerInvariant());
return values.ContainsKey(key.ToLower());
}
public string GetValue(string key, string defaultValue){
return values.TryGetValue(key.ToLowerInvariant(), out string val) ? val : defaultValue;
return values.TryGetValue(key.ToLower(), out string val) ? val : defaultValue;
}
public void RemoveValue(string key){
values.Remove(key.ToLowerInvariant());
values.Remove(key.ToLower());
}
public CommandLineArgs Clone(){

View File

@ -132,8 +132,7 @@ public override int GetHashCode(){
}
public override bool Equals(object obj){
Plugin plugin = obj as Plugin;
return plugin != null && plugin.Identifier.Equals(Identifier);
return obj is Plugin plugin && plugin.Identifier.Equals(Identifier);
}
public static Plugin CreateFromFolder(string path, PluginGroup group, out string error){
@ -184,7 +183,7 @@ private static bool LoadMetadata(string path, Plugin plugin, out string error){
plugin.metadata[currentTag] = currentContents;
}
currentTag = line.Substring(1, line.Length-2).ToUpperInvariant();
currentTag = line.Substring(1, line.Length-2).ToUpper();
currentContents = "";
if (line.Equals(endTag[0])){

View File

@ -1,5 +1,4 @@
using System.Globalization;
using TweetDuck.Plugins.Enums;
using TweetDuck.Plugins.Enums;
namespace TweetDuck.Plugins{
static class PluginScriptGenerator{
@ -11,7 +10,7 @@ public static string GeneratePlugin(string pluginIdentifier, string pluginConten
return PluginGen
.Replace("%params", environment.GetScriptVariables())
.Replace("%id", pluginIdentifier)
.Replace("%token", pluginToken.ToString(CultureInfo.InvariantCulture))
.Replace("%token", pluginToken.ToString())
.Replace("%contents", pluginContents);
}

View File

@ -51,7 +51,7 @@ static class Program{
public static UserConfig UserConfig { get; private set; }
public static SystemConfig SystemConfig { get; private set; }
public static Reporter Reporter { get; private set; }
public static Reporter Reporter { get; }
public static CultureInfo Culture { get; }
public static event EventHandler UserConfigReplaced;
@ -61,21 +61,22 @@ static Program(){
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
Reporter = new Reporter(ErrorLogFilePath);
Reporter.SetupUnhandledExceptionHandler(BrandName+" Has Failed :(");
}
[STAThread]
private static void Main(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WindowRestoreMessage = NativeMethods.RegisterWindowMessage("TweetDuckRestore");
if (!WindowsUtils.CheckFolderWritePermission(StoragePath)){
MessageBox.Show(BrandName+" does not have write permissions to the storage folder: "+StoragePath, "Permission Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Reporter = new Reporter(ErrorLogFilePath);
Reporter.SetupUnhandledExceptionHandler(BrandName+" Has Failed :(");
if (Arguments.HasFlag(Arguments.ArgRestart)){
for(int attempt = 0; attempt < 21; attempt++){
LockManager.Result lockResult = LockManager.Lock();

View File

@ -16,9 +16,7 @@ public Reporter(string logFile){
public void SetupUnhandledExceptionHandler(string caption){
AppDomain.CurrentDomain.UnhandledException += (sender, args) => {
Exception ex = args.ExceptionObject as Exception;
if (ex != null){
if (args.ExceptionObject is Exception ex) {
HandleException(caption, "An unhandled exception has occurred.", false, ex);
}
};

View File

@ -31,6 +31,11 @@ public static AudioPlayer New(){
public abstract void Play(string file);
public abstract void Stop();
public abstract void Dispose();
protected abstract void Dispose(bool disposing);
public void Dispose(){
Dispose(true);
GC.SuppressFinalize(this);
}
}
}

View File

@ -38,7 +38,7 @@ public override void Stop(){
player.Stop();
}
public override void Dispose(){
protected override void Dispose(bool disposing){
player.Dispose();
}

View File

@ -56,7 +56,7 @@ public override void Stop(){
}
}
public override void Dispose(){
protected override void Dispose(bool disposing){
player.close();
Marshal.ReleaseComObject(player);
}

View File

@ -82,9 +82,7 @@ private static ISimpleAudioVolume GetVolumeObject(string name){
ISimpleAudioVolume volumeObj = null;
for(int index = sessions.GetCount()-1; index >= 0; index--){
IAudioSessionControl2 ctl = sessions.GetSession(index) as IAudioSessionControl2;
if (ctl != null){
if (sessions.GetSession(index) is IAudioSessionControl2 ctl){
string identifier = ctl.GetSessionIdentifier();
if (identifier != null && identifier.Contains(name)){