Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings part 1 #3251

Merged
merged 9 commits into from
Feb 5, 2025
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.Classes.Tests/ObservableQueueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public void TestObservableQueue()
{
var queue = new ObservableQueue<int>();

List<int> enqueuedElements = new();
List<int> dequeuedElements = new();
List<int> enqueuedElements = [];
List<int> dequeuedElements = [];

queue.ItemEnqueued += (_, e) => enqueuedElements.Add(e.Item);
queue.ItemDequeued += (_, e) => dequeuedElements.Add(e.Item);
Expand Down
58 changes: 29 additions & 29 deletions src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
return new Random().Next();
}

private class TestClass

Check warning on line 11 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Type 'TestClass' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check warning on line 11 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Type 'TestClass' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
{
public TestClass() {}

public string SlowMethod2()

Check warning on line 15 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Member 'SlowMethod2' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 15 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Member 'SlowMethod2' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
Thread.Sleep(1000);
return new Random().Next().ToString();
}

public string SlowMethod3()

Check warning on line 21 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Member 'SlowMethod3' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)

Check warning on line 21 in src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Member 'SlowMethod3' does not access instance data and can be marked as static (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1822)
{
Thread.Sleep(1000);
return new Random().Next().ToString();
Expand All @@ -32,42 +32,42 @@
}

[Fact]
public void TestTaskRecycler_Static_Int()
public async Task TestTaskRecycler_Static_Int()
{
// The same static method should be cached, and therefore the return value should be the same
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1);
int result1 = task1.GetAwaiter().GetResult();
int result2 = task2.GetAwaiter().GetResult();
int result1 = await task1;
int result2 = await task2;
Assert.Equal(result1, result2);

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

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

[Fact]
public void TestTaskRecycler_Static_Int_WithCache()
public async Task TestTaskRecycler_Static_Int_WithCache()
{
// The same static method should be cached, and therefore the return value should be the same
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
int result1 = task1.GetAwaiter().GetResult();
int result2 = task2.GetAwaiter().GetResult();
int result1 = await task1;
int result2 = await task2;
Assert.Equal(result1, result2);

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

Expand All @@ -77,8 +77,8 @@
// The same static method should be cached, but cached runs should have been removed. This results should differ from previous ones
var task5 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
var task6 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
int result5 = task6.GetAwaiter().GetResult();
int result6 = task5.GetAwaiter().GetResult();
int result5 = await task6;
int result6 = await task5;
Assert.Equal(result5, result6);
Assert.NotEqual(result4, result5);

Expand All @@ -88,37 +88,37 @@
// The same static method should be cached, but cached runs should have been cleared manually. This results should differ from previous ones
var task7 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
var task8 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod1, 2);
int result7 = task7.GetAwaiter().GetResult();
int result8 = task8.GetAwaiter().GetResult();
int result7 = await task7;
int result8 = await task8;
Assert.Equal(result7, result8);
Assert.NotEqual(result6, result7);
}

[Fact]
public void TestTaskRecycler_StaticWithArgument_Int()
public async Task TestTaskRecycler_StaticWithArgument_Int()
{
// The same static method should be cached, and therefore the return value should be the same
var task1 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
var task2 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
var task3 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 3);
int result1 = task1.GetAwaiter().GetResult();
int result2 = task2.GetAwaiter().GetResult();
int result3 = task3.GetAwaiter().GetResult();
int result1 = await task1;
int result2 = await task2;
int result3 = await task3;
Assert.Equal(result1, result2);
Assert.NotEqual(result1, result3);

// The same static method should be cached, and therefore the return value should be the same, but different from previous runs
var task4 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 2);
var task5 = TaskRecycler<int>.RunOrAttachAsync(MySlowMethod4, 3);
int result4 = task4.GetAwaiter().GetResult();
int result5 = task5.GetAwaiter().GetResult();
int result4 = await task4;
int result5 = await task5;
Assert.NotEqual(result4, result5);
Assert.NotEqual(result1, result4);
Assert.NotEqual(result3, result5);
}

[Fact]
public void TestTaskRecycler_Class_String()
public async Task TestTaskRecycler_Class_String()
{
var class1 = new TestClass();
var class2 = new TestClass();
Expand All @@ -127,8 +127,8 @@
// and therefore the return value should be the same
var task1 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
var task2 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
string result1 = task1.GetAwaiter().GetResult();
string result2 = task2.GetAwaiter().GetResult();
string result1 = await task1;
string result2 = await task2;
Assert.Equal(result1, result2);

var class1_copy = class1;
Expand All @@ -137,16 +137,16 @@
// from different variable names should be cached, and therefore the return value should be the same
var task5 = TaskRecycler<string>.RunOrAttachAsync(class1_copy.SlowMethod2);
var task6 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod2);
string result5 = task5.GetAwaiter().GetResult();
string result6 = task6.GetAwaiter().GetResult();
string result5 = await task5;
string result6 = await task6;
Assert.Equal(result5, result6);

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

// Ensure the last call was not permanently cached
Expand All @@ -156,8 +156,8 @@
// cached, so the results should differ
var task7 = TaskRecycler<string>.RunOrAttachAsync(class1.SlowMethod3);
var task8 = TaskRecycler<string>.RunOrAttachAsync(class2.SlowMethod2);
string result7 = task7.GetAwaiter().GetResult();
string result8 = task8.GetAwaiter().GetResult();
string result7 = await task7;
string result8 = await task8;
Assert.NotEqual(result7, result8);
}
}
10 changes: 4 additions & 6 deletions src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ public static string UniGetUIDataDirectory
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
return path;
}
else
{
string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
}

string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
string new_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UniGetUI");
return GetNewDataDirectoryOrMoveOld(old_path, new_path);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.IconEngine.Tests/IconCacheEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static void TestCacheEngineForPackageSize()
string managerName = "TestManager";
string packageId = "Package3";

// Clear any cache for reproducable data
// Clear any cache for reproducible data
string extension = ICON_1.ToString().Split(".")[^1];
string expectedFile = Path.Join(CoreData.UniGetUICacheDirectory_Icons, managerName, packageId, $"icon.{extension}");
if (File.Exists(expectedFile))
Expand Down
8 changes: 5 additions & 3 deletions src/UniGetUI.Core.IconStore/IconCacheEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
/// <summary>
/// The given image will be downsized to the expected size of an icon, if required
/// </summary>
private static void DownsizeImage(string cachedIconFile, string extension)

Check warning on line 233 in src/UniGetUI.Core.IconStore/IconCacheEngine.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Remove unused parameter 'extension' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)

Check warning on line 233 in src/UniGetUI.Core.IconStore/IconCacheEngine.cs

View workflow job for this annotation

GitHub Actions / test-codebase

Remove unused parameter 'extension' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0060)
{ // Yes, the extension parameter could be extracted from cachedIconFile
try
{
Expand All @@ -248,7 +248,7 @@
if (width > MAX_SIDE || height > MAX_SIDE)
{
File.Move(cachedIconFile, $"{cachedIconFile}.copy");
var image = MagicImageProcessor.BuildPipeline($"{cachedIconFile}.copy", new ProcessImageSettings()
var image = MagicImageProcessor.BuildPipeline($"{cachedIconFile}.copy", new ProcessImageSettings
{
Width = MAX_SIDE,
Height = MAX_SIDE,
Expand Down Expand Up @@ -351,15 +351,17 @@
try
{
foreach (string file in Directory.GetFiles(iconLocation))
{
File.Delete(file);
}
}
catch (Exception e)
{
Logger.Warn($"An error occurred while deleting old icon cache: {e.Message}");
}
}

public static readonly ReadOnlyDictionary<string, string> MimeToExtension = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
public static readonly ReadOnlyDictionary<string, string> MimeToExtension = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
{
{"image/avif", "avif"},
{"image/gif", "gif"},
Expand All @@ -374,7 +376,7 @@
{"image/tiff", "tif"},
});

public static readonly ReadOnlyDictionary<string, string> ExtensionToMime = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
public static readonly ReadOnlyDictionary<string, string> ExtensionToMime = new ReadOnlyDictionary<string, string>(new Dictionary<string, string>
{
{"avif", "image/avif"},
{"gif", "image/gif"},
Expand Down
6 changes: 4 additions & 2 deletions src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
{

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

if (!File.Exists(BundledLangFileToLoad))
{
Expand Down Expand Up @@ -89,7 +89,7 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
{
Logger.Warn("User has updated translations disabled");
}
else if(!File.Exists(CachedLangFileToLoad))
else if (!File.Exists(CachedLangFileToLoad))
{
Logger.Warn($"Tried to access a non-existing cached language file! file={CachedLangFileToLoad}");
}
Expand All @@ -99,7 +99,9 @@ public Dictionary<string, string> LoadLanguageFile(string LangKey)
{
if (JsonNode.Parse(File.ReadAllText(CachedLangFileToLoad)) is JsonObject parsedObject)
foreach (var keyval in parsedObject.ToDictionary(x => x.Key, x => x.Value))
{
LangDict[keyval.Key] = keyval.Value?.ToString() ?? "";
}
else
throw new ArgumentException($"parsedObject was null for lang file {CachedLangFileToLoad}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.Settings/SettingsEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static bool Get(string setting, bool invert = false)
return result ^ invert;
}

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

// Otherwhise, load the setting from disk and cache that setting
// Otherwise, load the setting from disk and cache that setting
value = "";
if (File.Exists(Path.Join(CoreData.UniGetUIDataDirectory, setting)))
{
Expand Down
Loading
Loading