1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-04 17:34:07 +02:00

Minor refactoring and warning suppression

This commit is contained in:
chylex 2019-05-11 15:25:19 +02:00
parent fe2269c838
commit 6c65d0771d
15 changed files with 49 additions and 66 deletions

View File

@ -22,8 +22,8 @@ public static bool HasFlag(string flag){
return Current.HasFlag(flag);
}
public static string GetValue(string key, string defaultValue){
return Current.GetValue(key, defaultValue);
public static string GetValue(string key){
return Current.GetValue(key);
}
public static CommandLineArgs GetCurrentClean(){

View File

@ -1,4 +1,5 @@
using System.Windows.Forms;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Core.Management;
using TweetDuck.Core.Notification;
@ -6,6 +7,7 @@
using TweetDuck.Core.Utils;
namespace TweetDuck.Core.Bridge{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
class TweetDeckBridge{
public static string FontSize { get; private set; }
public static string NotificationHeadLayout { get; private set; }
@ -63,7 +65,7 @@ public void DisplayTooltip(string text){
}
// Notification only
public sealed class Notification : TweetDeckBridge{
public Notification(FormBrowser form, FormNotificationMain notification) : base(form, notification){}

View File

@ -1,10 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
using TweetDuck.Updates;
using TweetLib.Core.Features.Updates;
namespace TweetDuck.Core.Bridge{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
class UpdateBridge{
private readonly UpdateHandler updates;
private readonly Control sync;

View File

@ -17,8 +17,6 @@ public static bool TryBringToFront<T>() where T : Form{
else return false;
}
public static bool HasAnyDialogs => Application.OpenForms.OfType<IAppDialog>().Any();
public static void CloseAllDialogs(){
foreach(IAppDialog dialog in Application.OpenForms.OfType<IAppDialog>().Reverse()){
((Form)dialog).Close();

View File

@ -107,7 +107,7 @@ public sealed class Builder{
private string unsafeLinkUrl = string.Empty;
private string mediaUrl = string.Empty;
private ChirpInfo chirp = default(ChirpInfo);
private ChirpInfo chirp = default;
public void AddContext(IContextMenuParams parameters){
ContextMenuType flags = parameters.TypeFlags;

View File

@ -1,8 +1,10 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Windows.Forms;
using TweetDuck.Core.Controls;
namespace TweetDuck.Core.Notification.Screenshot{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
sealed class ScreenshotBridge{
private readonly Control owner;

View File

@ -195,7 +195,7 @@ private void control_MouseWheel(object sender, MouseEventArgs e){
private sealed class SettingsTab{
public Button Button { get; }
public BaseTabSettings Control => control ?? (control = constructor());
public BaseTabSettings Control => control ??= constructor();
public bool IsInitialized => control != null;
private readonly Func<BaseTabSettings> constructor;

View File

@ -5,8 +5,6 @@
namespace TweetDuck.Core.Other.Settings.Dialogs{
sealed partial class DialogSettingsAnalytics : Form{
public string CefArgs => textBoxReport.Text;
public DialogSettingsAnalytics(AnalyticsReport report){
InitializeComponent();

View File

@ -18,7 +18,7 @@ public DialogSettingsRestart(CommandLineArgs currentArgs){
tbDataFolder.Enabled = false;
}
else{
tbDataFolder.Text = currentArgs.GetValue(Arguments.ArgDataFolder, string.Empty);
tbDataFolder.Text = currentArgs.GetValue(Arguments.ArgDataFolder) ?? string.Empty;
tbDataFolder.TextChanged += control_Change;
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
using TweetLib.Core.Collections;
@ -10,6 +11,7 @@
using TweetLib.Core.Utils;
namespace TweetDuck.Plugins{
[SuppressMessage("ReSharper", "UnusedMember.Global")]
sealed class PluginBridge{
private static string SanitizeCacheKey(string key){
return key.Replace('\\', '/').Trim();

View File

@ -124,7 +124,7 @@ private static void Main(){
}
try{
RequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze, null));
RequestHandlerBase.LoadResourceRewriteRules(Arguments.GetValue(Arguments.ArgFreeze));
}catch(Exception e){
FormMessage.Error("Resource Freeze", "Error parsing resource rewrite rules: "+e.Message, FormMessage.OK);
return;
@ -173,7 +173,7 @@ private static void Main(){
}
private static string GetDataStoragePath(){
string custom = Arguments.GetValue(Arguments.ArgDataFolder, null);
string custom = Arguments.GetValue(Arguments.ArgDataFolder);
if (custom != null && (custom.Contains(Path.DirectorySeparatorChar) || custom.Contains(Path.AltDirectorySeparatorChar))){
if (Path.GetInvalidPathChars().Any(custom.Contains)){

View File

@ -84,12 +84,8 @@ public void SetValue(string key, string value){
values[key.ToLower()] = value;
}
public bool HasValue(string key){
return values.ContainsKey(key.ToLower());
}
public string GetValue(string key, string defaultValue){
return values.TryGetValue(key.ToLower(), out string val) ? val : defaultValue;
public string? GetValue(string key){
return values.TryGetValue(key.ToLower(), out string val) ? val : null;
}
public void RemoveValue(string key){

View File

@ -13,7 +13,7 @@ public static void Initialize(){
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
#if DEBUG
CultureInfo.DefaultThreadCurrentUICulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); // force english exceptions
#endif

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TweetLib.Core.Serialization;
@ -6,6 +7,7 @@
namespace TweetTest.Data{
[TestClass]
public class TestFileSerializer : TestIO{
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private enum TestEnum{
A, B, C, D, E
}

View File

@ -139,52 +139,33 @@ module Flags =
module Values =
[<Theory>]
[<InlineData("val1")>]
[<InlineData("val2")>]
let ``HasValue returns false if key is missing`` (key: string) =
Assert.False(_TestData.empty.HasValue(key))
Assert.False(_TestData.flags.HasValue(key))
[<Fact>]
let ``GetValue returns null if key is missing`` () =
Assert.Null(_TestData.values.GetValue("missing"))
[<Theory>]
[<InlineData("flag1")>]
[<InlineData("flag2")>]
[<InlineData("flag3")>]
let ``HasValue returns false if the name specifies a flag`` (key: string) =
Assert.False(_TestData.flags.HasValue(key))
let ``GetValue returns null if the name specifies a flag`` (key: string) =
Assert.Null(_TestData.flags.GetValue(key))
[<Fact>]
let ``HasValue returns true if the name specifies both a flag and a value key`` () =
Assert.True(_TestData.duplicate.HasValue("duplicate"))
[<Theory>]
[<InlineData("val1")>]
[<InlineData("val2")>]
let ``HasValue returns true if key is present`` (key: string) =
Assert.True(_TestData.values.HasValue(key))
[<Theory>]
[<InlineData("VAL1")>]
[<InlineData("VaL1")>]
let ``HasValue is case-insensitive`` (key: string) =
Assert.True(_TestData.values.HasValue(key))
let ``GetValue returns correct value if the name specifies both a flag and a value key`` () =
Assert.NotNull(_TestData.duplicate.GetValue("duplicate"))
[<Theory>]
[<InlineData("val1", "hello")>]
[<InlineData("val2", "world")>]
let ``GetValue returns correct value if key is present`` (key: string, expectedValue: string) =
Assert.Equal(expectedValue, _TestData.values.GetValue(key, ""))
Assert.Equal(expectedValue, _TestData.values.GetValue(key))
[<Theory>]
[<InlineData("VAL1", "hello")>]
[<InlineData("VaL1", "hello")>]
let ``GetValue is case-insensitive`` (key: string, expectedValue: string) =
Assert.Equal(expectedValue, _TestData.values.GetValue(key, ""))
[<Fact>]
let ``GetValue returns default value if key is missing`` () =
Assert.Equal("oh no", _TestData.values.GetValue("missing", "oh no"))
Assert.Equal(expectedValue, _TestData.values.GetValue(key))
[<Fact>]
let ``SetValue adds new value`` () =
@ -192,7 +173,7 @@ module Values =
args.SetValue("val3", "this is nice")
Assert.Equal(3, args.Count)
Assert.Equal("this is nice", args.GetValue("val3", ""))
Assert.Equal("this is nice", args.GetValue("val3"))
[<Fact>]
let ``SetValue replaces existing value`` () =
@ -200,7 +181,7 @@ module Values =
args.SetValue("val2", "mom")
Assert.Equal(2, args.Count)
Assert.Equal("mom", args.GetValue("val2", ""))
Assert.Equal("mom", args.GetValue("val2"))
[<Theory>]
[<InlineData("val1")>]
@ -210,7 +191,7 @@ module Values =
args.RemoveValue(key)
Assert.Equal(1, args.Count)
Assert.False(args.HasValue(key))
Assert.Null(args.GetValue(key))
[<Theory>]
[<InlineData("VAL1")>]
@ -220,7 +201,7 @@ module Values =
args.RemoveValue(key)
Assert.Equal(1, args.Count)
Assert.False(args.HasValue(key))
Assert.Null(args.GetValue(key))
[<Fact>]
let ``RemoveValue does nothing if key is missing`` () =
@ -239,8 +220,8 @@ module Clone =
Assert.True(clone.HasFlag("flag1"))
Assert.True(clone.HasFlag("flag2"))
Assert.True(clone.HasFlag("flag3"))
Assert.Equal("hello", clone.GetValue("val1", ""))
Assert.Equal("world", clone.GetValue("val2", ""))
Assert.Equal("hello", clone.GetValue("val1"))
Assert.Equal("world", clone.GetValue("val2"))
[<Fact>]
let ``cloning creates a new object`` () =
@ -259,7 +240,7 @@ module Clone =
Assert.True(original.HasFlag("flag1"))
Assert.False(original.HasFlag("flag4"))
Assert.Equal("hello", original.GetValue("val1", ""))
Assert.Equal("hello", original.GetValue("val1"))
module ToDictionary =
@ -327,8 +308,8 @@ module FromStringArray =
Assert.True(args.HasFlag("-flag1"))
Assert.True(args.HasFlag("-flag2"))
Assert.True(args.HasFlag("-flag3"))
Assert.Equal("first value", args.GetValue("-val1", ""))
Assert.Equal("second value", args.GetValue("-val2", ""))
Assert.Equal("first value", args.GetValue("-val1"))
Assert.Equal("second value", args.GetValue("-val2"))
module ReadCefArguments =
@ -346,23 +327,23 @@ module ReadCefArguments =
let args = CommandLineArgs.ReadCefArguments("--first-value=10 --second-value=\"long string with spaces\"")
Assert.Equal(2, args.Count)
Assert.Equal("10", args.GetValue("first-value", ""))
Assert.Equal("long string with spaces", args.GetValue("second-value", ""))
Assert.Equal("10", args.GetValue("first-value"))
Assert.Equal("long string with spaces", args.GetValue("second-value"))
[<Fact>]
let ``reads flags as value keys with values of 1`` () =
let args = CommandLineArgs.ReadCefArguments("--first-flag-as-value --second-flag-as-value")
Assert.Equal(2, args.Count)
Assert.Equal("1", args.GetValue("first-flag-as-value", ""))
Assert.Equal("1", args.GetValue("second-flag-as-value", ""))
Assert.Equal("1", args.GetValue("first-flag-as-value"))
Assert.Equal("1", args.GetValue("second-flag-as-value"))
[<Fact>]
let ``reads complex string with whitespace correctly`` () =
let args = CommandLineArgs.ReadCefArguments("\t--first-value=55.5\r\n--first-flag-as-value\r\n --second-value=\"long string\"\t--second-flag-as-value ")
Assert.Equal(4, args.Count)
Assert.Equal("55.5", args.GetValue("first-value", ""))
Assert.Equal("long string", args.GetValue("second-value", ""))
Assert.Equal("1", args.GetValue("first-flag-as-value", ""))
Assert.Equal("1", args.GetValue("second-flag-as-value", ""))
Assert.Equal("55.5", args.GetValue("first-value"))
Assert.Equal("long string", args.GetValue("second-value"))
Assert.Equal("1", args.GetValue("first-flag-as-value"))
Assert.Equal("1", args.GetValue("second-flag-as-value"))