Skip to content

Commit 550a8b3

Browse files
authored
Merge pull request #3251 from Saibamen/fix_warnings_part1
Fix warnings part 1
2 parents d8a4862 + 0c438b4 commit 550a8b3

File tree

76 files changed

+589
-586
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+589
-586
lines changed

src/UniGetUI.Core.Classes.Tests/ObservableQueueTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public void TestObservableQueue()
77
{
88
var queue = new ObservableQueue<int>();
99

10-
List<int> enqueuedElements = new();
11-
List<int> dequeuedElements = new();
10+
List<int> enqueuedElements = [];
11+
List<int> dequeuedElements = [];
1212

1313
queue.ItemEnqueued += (_, e) => enqueuedElements.Add(e.Item);
1414
queue.ItemDequeued += (_, e) => dequeuedElements.Add(e.Item);

src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,42 @@ private int MySlowMethod4(int argument)
3232
}
3333

3434
[Fact]
35-
public void TestTaskRecycler_Static_Int()
35+
public async Task TestTaskRecycler_Static_Int()
3636
{
3737
// The same static method should be cached, and therefore the return value should be the same
3838
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
3939
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
40-
int result1 = task1.GetAwaiter().GetResult();
41-
int result2 = task2.GetAwaiter().GetResult();
40+
int result1 = await task1;
41+
int result2 = await task2;
4242
Assert.Equal(result1, result2);
4343

4444
// The same static method should be cached, and therefore the return value should be the same, but different from previous runs
4545
var task3 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
4646
var task4 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
47-
int result4 = task4.GetAwaiter().GetResult();
48-
int result3 = task3.GetAwaiter().GetResult();
47+
int result4 = await task4;
48+
int result3 = await task3;
4949
Assert.Equal(result3, result4);
5050

5151
// Ensure the last call was not permanently cached
5252
Assert.NotEqual(result1, result3);
5353
}
5454

5555
[Fact]
56-
public void TestTaskRecycler_Static_Int_WithCache()
56+
public async Task TestTaskRecycler_Static_Int_WithCache()
5757
{
5858
// The same static method should be cached, and therefore the return value should be the same
5959
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
6060
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
61-
int result1 = task1.GetAwaiter().GetResult();
62-
int result2 = task2.GetAwaiter().GetResult();
61+
int result1 = await task1;
62+
int result2 = await task2;
6363
Assert.Equal(result1, result2);
6464

6565
// The same static method should be cached, and therefore the return value should be the same,
6666
// and equal to previous runs due to 3 seconds cache
6767
var task3 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
6868
var task4 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
69-
int result4 = task4.GetAwaiter().GetResult();
70-
int result3 = task3.GetAwaiter().GetResult();
69+
int result4 = await task4;
70+
int result3 = await task3;
7171
Assert.Equal(result3, result4);
7272
Assert.Equal(result1, result3);
7373

@@ -77,8 +77,8 @@ public void TestTaskRecycler_Static_Int_WithCache()
7777
// The same static method should be cached, but cached runs should have been removed. This results should differ from previous ones
7878
var task5 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
7979
var task6 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
80-
int result5 = task6.GetAwaiter().GetResult();
81-
int result6 = task5.GetAwaiter().GetResult();
80+
int result5 = await task6;
81+
int result6 = await task5;
8282
Assert.Equal(result5, result6);
8383
Assert.NotEqual(result4, result5);
8484

@@ -88,37 +88,37 @@ public void TestTaskRecycler_Static_Int_WithCache()
8888
// The same static method should be cached, but cached runs should have been cleared manually. This results should differ from previous ones
8989
var task7 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
9090
var task8 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
91-
int result7 = task7.GetAwaiter().GetResult();
92-
int result8 = task8.GetAwaiter().GetResult();
91+
int result7 = await task7;
92+
int result8 = await task8;
9393
Assert.Equal(result7, result8);
9494
Assert.NotEqual(result6, result7);
9595
}
9696

9797
[Fact]
98-
public void TestTaskRecycler_StaticWithArgument_Int()
98+
public async Task TestTaskRecycler_StaticWithArgument_Int()
9999
{
100100
// The same static method should be cached, and therefore the return value should be the same
101101
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
102102
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
103103
var task3 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 3);
104-
int result1 = task1.GetAwaiter().GetResult();
105-
int result2 = task2.GetAwaiter().GetResult();
106-
int result3 = task3.GetAwaiter().GetResult();
104+
int result1 = await task1;
105+
int result2 = await task2;
106+
int result3 = await task3;
107107
Assert.Equal(result1, result2);
108108
Assert.NotEqual(result1, result3);
109109

110110
// The same static method should be cached, and therefore the return value should be the same, but different from previous runs
111111
var task4 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
112112
var task5 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 3);
113-
int result4 = task4.GetAwaiter().GetResult();
114-
int result5 = task5.GetAwaiter().GetResult();
113+
int result4 = await task4;
114+
int result5 = await task5;
115115
Assert.NotEqual(result4, result5);
116116
Assert.NotEqual(result1, result4);
117117
Assert.NotEqual(result3, result5);
118118
}
119119

120120
[Fact]
121-
public void TestTaskRecycler_Class_String()
121+
public async Task TestTaskRecycler_Class_String()
122122
{
123123
var class1 = new TestClass();
124124
var class2 = new TestClass();
@@ -127,8 +127,8 @@ public void TestTaskRecycler_Class_String()
127127
// and therefore the return value should be the same
128128
var task1 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
129129
var task2 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
130-
string result1 = task1.GetAwaiter().GetResult();
131-
string result2 = task2.GetAwaiter().GetResult();
130+
string result1 = await task1;
131+
string result2 = await task2;
132132
Assert.Equal(result1, result2);
133133

134134
var class1_copy = class1;
@@ -137,16 +137,16 @@ public void TestTaskRecycler_Class_String()
137137
// from different variable names should be cached, and therefore the return value should be the same
138138
var task5 = TaskRecycler<string>.RunOrAttachAsync(class1_copy.SlowMethod2);
139139
var task6 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
140-
string result5 = task5.GetAwaiter().GetResult();
141-
string result6 = task6.GetAwaiter().GetResult();
140+
string result5 = await task5;
141+
string result6 = await task6;
142142
Assert.Equal(result5, result6);
143143

144144
// The SAME method from two DIFFERENT instances should NOT be
145145
// cached, so the results should differ
146146
var task3 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
147147
var task4 = TaskRecycler<string>.RunOrAttachAsync(class2.SlowMethod2);
148-
string result4 = task4.GetAwaiter().GetResult();
149-
string result3 = task3.GetAwaiter().GetResult();
148+
string result4 = await task4;
149+
string result3 = await task3;
150150
Assert.NotEqual(result3, result4);
151151

152152
// Ensure the last call was not permanently cached
@@ -156,8 +156,8 @@ public void TestTaskRecycler_Class_String()
156156
// cached, so the results should differ
157157
var task7 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod3);
158158
var task8 = TaskRecycler<string>.RunOrAttachAsync(class2.SlowMethod2);
159-
string result7 = task7.GetAwaiter().GetResult();
160-
string result8 = task8.GetAwaiter().GetResult();
159+
string result7 = await task7;
160+
string result8 = await task8;
161161
Assert.NotEqual(result7, result8);
162162
}
163163
}

src/UniGetUI.Core.Data/CoreData.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ public static string UniGetUIDataDirectory
4545
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
4646
return path;
4747
}
48-
else
49-
{
50-
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
51-
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
52-
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
53-
}
48+
49+
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
50+
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
51+
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
5452
}
5553
}
5654

src/UniGetUI.Core.IconEngine.Tests/IconCacheEngineTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public static void TestCacheEngineForPackageSize()
158158
string managerName = "TestManager";
159159
string packageId = "Package3";
160160

161-
// Clear any cache for reproducable data
161+
// Clear any cache for reproducible data
162162
string extension = ICON_1.ToString().Split(".")[^1];
163163
string expectedFile = Path.Join(CoreData.UniGetUICacheDirectory_Icons, managerName, packageId, $"icon.{extension}");
164164
if (File.Exists(expectedFile))

src/UniGetUI.Core.IconStore/IconCacheEngine.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private static void DownsizeImage(string cachedIconFile, string extension)
248248
if (width > MAX_SIDE || height > MAX_SIDE)
249249
{
250250
File.Move(cachedIconFile, $"{cachedIconFile}.copy");
251-
var image = MagicImageProcessor.BuildPipeline($"{cachedIconFile}.copy", new ProcessImageSettings()
251+
var image = MagicImageProcessor.BuildPipeline($"{cachedIconFile}.copy", new ProcessImageSettings
252252
{
253253
Width = MAX_SIDE,
254254
Height = MAX_SIDE,
@@ -351,15 +351,17 @@ private static void DeteteCachedFiles(string iconLocation)
351351
try
352352
{
353353
foreach (string file in Directory.GetFiles(iconLocation))
354+
{
354355
File.Delete(file);
356+
}
355357
}
356358
catch (Exception e)
357359
{
358360
Logger.Warn($"An error occurred while deleting old icon cache: {e.Message}");
359361
}
360362
}
361363

362-
public static readonly ReadOnlyDictionary<string, string> MimeToExtension = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
364+
public static readonly ReadOnlyDictionary<string, string> MimeToExtension = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
363365
{
364366
{"image/avif", "avif"},
365367
{"image/gif", "gif"},
@@ -374,7 +376,7 @@ private static void DeteteCachedFiles(string iconLocation)
374376
{"image/tiff", "tif"},
375377
});
376378

377-
public static readonly ReadOnlyDictionary<string, string> ExtensionToMime = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
379+
public static readonly ReadOnlyDictionary<string, string> ExtensionToMime = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
378380
{
379381
{"avif", "image/avif"},
380382
{"gif", "image/gif"},

src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
5959
{
6060

6161
string BundledLangFileToLoad = Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Languages", "lang_" + LangKey + ".json");
62-
JsonObject BundledContents = new();
62+
JsonObject BundledContents = [];
6363

6464
if (!File.Exists(BundledLangFileToLoad))
6565
{
@@ -89,7 +89,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
8989
{
9090
Logger.Warn("User has updated translations disabled");
9191
}
92-
else if(!File.Exists(CachedLangFileToLoad))
92+
else if (!File.Exists(CachedLangFileToLoad))
9393
{
9494
Logger.Warn($"Tried to access a non-existing cached language file! file={CachedLangFileToLoad}");
9595
}
@@ -99,7 +99,9 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
9999
{
100100
if (JsonNode.Parse(File.ReadAllText(CachedLangFileToLoad)) is JsonObject parsedObject)
101101
foreach (var keyval in parsedObject.ToDictionary(x => x.Key, x => x.Value))
102+
{
102103
LangDict[keyval.Key] = keyval.Value?.ToString() ?? "";
104+
}
103105
else
104106
throw new ArgumentException($"parsedObject was null for lang file {CachedLangFileToLoad}");
105107
}

src/UniGetUI.Core.Settings/SettingsEngine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static bool Get(string setting, bool invert = false)
1616
return result ^ invert;
1717
}
1818

19-
// Otherwhise, load the value from disk and cache that setting
19+
// Otherwise, load the value from disk and cache that setting
2020
result = File.Exists(Path.Join(CoreData.UniGetUIDataDirectory, setting));
2121
booleanSettings[setting] = result;
2222
return result ^ invert;
@@ -59,7 +59,7 @@ public static string GetValue(string setting)
5959
return value;
6060
}
6161

62-
// Otherwhise, load the setting from disk and cache that setting
62+
// Otherwise, load the setting from disk and cache that setting
6363
value = "";
6464
if (File.Exists(Path.Join(CoreData.UniGetUIDataDirectory, setting)))
6565
{

0 commit comments

Comments
 (0)