Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
<PropertyGroup>
<LangVersion>latest</LangVersion>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<NoWarn>$(NoWarn);EnableGenerateDocumentationFile</NoWarn>
</PropertyGroup>
</Project>
6 changes: 5 additions & 1 deletion src/UniGetUI.Core.Classes.Tests/TaskRecyclerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace UniGetUI.Core.Classes.Tests;

public class TaskRecyclerTests
Expand All @@ -8,16 +10,18 @@ private int MySlowMethod1()
return new Random().Next();
}

private class TestClass
private sealed class TestClass
{
public TestClass() {}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Instance methods are required to validate TaskRecycler instance-bound delegate behavior.")]
public string SlowMethod2()
{
Thread.Sleep(1000);
return new Random().Next().ToString();
}

[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Instance methods are required to validate TaskRecycler instance-bound delegate behavior.")]
public string SlowMethod3()
{
Thread.Sleep(1000);
Expand Down
1 change: 0 additions & 1 deletion src/UniGetUI.Core.Classes/TaskRecycler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public static void RemoveFromCache(Func<ReturnT> method)

// ---------------------------------------------------------------------------------------------------------------


/// <summary>
/// Handles running the task if no such task was found on cache, and returning the cached task if it was found.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI.Core.Data/CoreCredentialStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public static void DeleteSecret(string resourceName, string userName)
}
}

#if !WINDOWS
private static string GetStorageDirectory()
=> Path.Join(CoreData.UniGetUIDataDirectory, "SecureStorage");

Expand All @@ -104,4 +105,5 @@ private static string GetStableFileName(string resourceName, string userName)
byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes($"{resourceName}\n{userName}"));
return Convert.ToHexString(hash) + ".secret";
}
#endif
}
2 changes: 1 addition & 1 deletion src/UniGetUI.Core.Data/CoreData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static string UniGetUIDataDirectory
}
} else if (IS_PORTABLE is true)
{
return PORTABLE_PATH ?? throw new Exception("This shouldn't be possible");
return PORTABLE_PATH ?? throw new InvalidOperationException("This shouldn't be possible");
}

string old_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".wingetui");
Expand Down
3 changes: 0 additions & 3 deletions src/UniGetUI.Core.IconStore/IconDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public struct IconCount
public IconCount() { }
}


private static IconDatabase? __instance;
public static IconDatabase Instance
{
Expand Down Expand Up @@ -57,7 +56,6 @@ public async Task LoadIconAndScreenshotsDatabaseAsync()

Logger.ImportantInfo("Downloaded new icons and screenshots successfully!");


if (!File.Exists(IconsAndScreenshotsFile))
{
Logger.Error("Icon Database file not found");
Expand All @@ -74,7 +72,6 @@ public async Task LoadIconAndScreenshotsDatabaseAsync()
await LoadFromCacheAsync();
}


public async Task LoadFromCacheAsync()
{
try
Expand Down
1 change: 0 additions & 1 deletion src/UniGetUI.Core.SecureSettings/SecureSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public static string ResolveKey(K key)
};
}


private static readonly Dictionary<string, bool> _cache = new();

public static class Args
Expand Down
7 changes: 4 additions & 3 deletions src/UniGetUI.Core.Settings.Tests/SettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class SerializableTest
public SerializableTestSub sub { get; set; }
}

public class SettingsTest
public class SettingsTest : IDisposable
{
private readonly string _testRoot;

Expand Down Expand Up @@ -50,7 +50,6 @@ public void Dispose()
private string GetNewSettingPath(string fileName) => Path.Combine(_newConfigurationDirectory, fileName);
private string GetOldSettingsPath(string fileName) => Path.Combine(_oldConfigurationDirectory, fileName);


[Fact]
public void TestSettingsSaveToNewDirectory()
{
Expand Down Expand Up @@ -175,7 +174,9 @@ public void TestListSettings(string SettingName, string[] ls1Array, int[] ls2Arr
Assert.Equal("this is now a test case", Settings.GetListItem<string>(SettingName, 3));
Assert.Null(Settings.GetListItem<string>(SettingName, 4));

Assert.Equal(Settings.GetListItem<string>(SettingName, 0), JsonSerializer.Deserialize<List<string>>(File.ReadAllText(Path.Join(CoreData.UniGetUIUserConfigurationDirectory, $"{SettingName}.json")), Settings.SerializationOptions)[0]);
List<string>? persistedList = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(Path.Join(CoreData.UniGetUIUserConfigurationDirectory, $"{SettingName}.json")), Settings.SerializationOptions);
Assert.NotNull(persistedList);
Assert.Equal(Settings.GetListItem<string>(SettingName, 0), persistedList[0]);
Settings.ClearList(SettingName);
Assert.Empty(Settings.GetList<object>(SettingName) ?? ["this shouldn't be null; something's wrong"]);

Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.Settings/SettingsEngine_Dictionaries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static partial class Settings
private static readonly ConcurrentDictionary<K, Dictionary<object, object?>> _dictionarySettings = new();

// Returns an empty dictionary if the setting doesn't exist and null if the types are invalid
private static Dictionary<KeyT, ValueT?> _getDictionary<KeyT, ValueT>(K key)
private static Dictionary<KeyT, ValueT?>? _getDictionary<KeyT, ValueT>(K key)
where KeyT : notnull
{
string setting = ResolveKey(key);
Expand Down Expand Up @@ -73,7 +73,7 @@ public static partial class Settings
}

// Returns an empty dictionary if the setting doesn't exist and null if the types are invalid
public static IReadOnlyDictionary<KeyT, ValueT?> GetDictionary<KeyT, ValueT>(K settingsKey)
public static IReadOnlyDictionary<KeyT, ValueT?>? GetDictionary<KeyT, ValueT>(K settingsKey)
where KeyT : notnull
{
return _getDictionary<KeyT, ValueT?>(settingsKey);
Expand Down
1 change: 0 additions & 1 deletion src/UniGetUI.Core.Tools/DWMThreadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ private static void ChangeState(bool suspend, IntPtr expectedAdress, ref bool Is
return;
}


if (suspend)
{
uint res = SuspendThread(hThread);
Expand Down
4 changes: 2 additions & 2 deletions src/UniGetUI.Core.Tools/IntegrityTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public static class IntegrityTester
{
public class MismatchedHash
{
public string Got;
public string Expected;
public string Got = string.Empty;
public string Expected = string.Empty;
}

public struct Result
Expand Down
6 changes: 3 additions & 3 deletions src/UniGetUI.Core.Tools/SerializationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static string xml_to_json(string XML)
}

// Attributes dictionary
var dict = new Dictionary<string, object>();
var dict = new Dictionary<string, object?>();
if (node.Attributes?.Count > 0)
{
foreach (XmlAttribute attr in node.Attributes)
Expand All @@ -52,14 +52,14 @@ private static string xml_to_json(string XML)
}

// Group child elements
var children = new Dictionary<string, List<object>>();
var children = new Dictionary<string, List<object?>>();
foreach (XmlNode child in node.ChildNodes)
{
if (child is XmlElement childElement)
{
var value = _convertXmlNode(childElement);
if (!children.ContainsKey(childElement.Name))
children[childElement.Name] = new List<object>();
children[childElement.Name] = new List<object?>();
children[childElement.Name].Add(value);
}
}
Expand Down
24 changes: 15 additions & 9 deletions src/UniGetUI.Core.Tools/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ public static bool IsAdministrator()
public static Task<long> GetFileSizeAsLongAsync(Uri? url)
=> Task.Run(() => GetFileSizeAsLong(url));


public static long GetFileSizeAsLong(Uri? url)
{
if (url is null) return 0;
Expand Down Expand Up @@ -318,7 +317,6 @@ or HttpStatusCode.RedirectMethod or HttpStatusCode.TemporaryRedirect
public static Task<string> GetFileNameAsync(Uri url)
=> Task.Run(() => GetFileName(url));


public struct Version: IComparable
{
public static readonly Version Null = new(-1, -1, -1, -1);
Expand Down Expand Up @@ -679,13 +677,22 @@ public static string TextProgressGenerator(int length, int progressPercent, stri
int done = (int)((progressPercent / 100.0) * (length));
int rest = length - done;

return new StringBuilder()
StringBuilder builder = new StringBuilder()
.Append('[')
.Append(new string('#', done))
.Append(new string('.', rest))
.Append($"] {progressPercent}%")
.Append(extra is null ? "" : $" ({extra})")
.ToString();
.Append('#', done)
.Append('.', rest)
.Append("] ")
.Append(progressPercent)
.Append('%');

if (extra is not null)
{
builder.Append(" (")
.Append(extra)
.Append(')');
}

return builder.ToString();
}

public static string FormatAsSize(long number, int decimals = 1)
Expand Down Expand Up @@ -782,7 +789,6 @@ public static string GetCurrentLocale()
public static string MakeValidFileName(string name)
=> string.Concat(name.Where(x => !_illegalPathChars.Contains(x)));


// Safely wait for a task that may throw an exception we don't care about
public static async void FinalizeDangerousTask(Task t)
{
Expand Down
19 changes: 11 additions & 8 deletions src/UniGetUI.Interface.BackgroundApi/BackgroundApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class BackgroundApiRunner
public event EventHandler<string>? OnUpgradePackage;

private IHost? _host;
private bool _running;

public BackgroundApiRunner()
{
Expand Down Expand Up @@ -86,7 +85,6 @@ public async Task Start()
webBuilder.UseUrls("http://localhost:7058");
});
_host = builder.Build();
_running = true;
await _host.StartAsync();
Logger.Info("Api running on http://localhost:7058");
}
Expand All @@ -100,7 +98,9 @@ private async Task V2_ShowPackage(HttpContext context)
return;
}

OnShowSharedPackage?.Invoke(null, new KeyValuePair<string, string>(query["pid"], query["psource"]));
string packageId = query["pid"].ToString();
string packageSource = query["psource"].ToString();
OnShowSharedPackage?.Invoke(null, new KeyValuePair<string, string>(packageId, packageSource));

await context.Response.WriteAsync("{\"status\": \"success\"}");
}
Expand Down Expand Up @@ -193,7 +193,8 @@ private async Task WIDGETS_V1_UpdatePackage(HttpContext context)
return;
}

OnUpgradePackage?.Invoke(null, id);
string packageId = id.ToString();
OnUpgradePackage?.Invoke(null, packageId);
context.Response.StatusCode = 200;
}

Expand Down Expand Up @@ -225,8 +226,9 @@ private async Task WIDGETS_V1_UpdateAllPackagesForSource(HttpContext context)
return;
}

Logger.Info($"[WIDGETS] Updating all packages for manager {source}");
OnUpgradeAllForManager?.Invoke(null, source);
string sourceName = source.ToString();
Logger.Info($"[WIDGETS] Updating all packages for manager {sourceName}");
OnUpgradeAllForManager?.Invoke(null, sourceName);
context.Response.StatusCode = 200;
}

Expand All @@ -248,7 +250,8 @@ private async Task WIDGETS_V2_GetIconForPackage(HttpContext context)

string iconPath = Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Images", "package_color.png");

IPackage? package = UpgradablePackagesLoader.Instance.GetPackageForId(packageId, packageSource);
string resolvedPackageId = packageId.ToString();
IPackage? package = UpgradablePackagesLoader.Instance.GetPackageForId(resolvedPackageId, packageSource);
if (package != null)
{
var iconUrl = await Task.Run(package.GetIconUrl);
Expand All @@ -266,7 +269,7 @@ private async Task WIDGETS_V2_GetIconForPackage(HttpContext context)
var bytes = await File.ReadAllBytesAsync(iconPath);
var ext = Path.GetExtension(iconPath).TrimStart('.').ToLower();
context.Response.ContentType = IconCacheEngine.ExtensionToMime.GetValueOrDefault(ext, "image/png");
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
await context.Response.Body.WriteAsync(bytes.AsMemory());
}

public async Task Stop()
Expand Down
3 changes: 1 addition & 2 deletions src/UniGetUI.Interface.Telemetry/TelemetryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static async void PackageEndpoint(IPackage package, string endpoint, TEL
{
try
{
if (result is null && eventSource is null) throw new NullReferenceException("result and eventSource cannot be both null!");
if (result is null && eventSource is null) throw new ArgumentException("result and eventSource cannot both be null");
if (Settings.Get(Settings.K.DisableTelemetry)) return;
await CoreTools.WaitForInternetConnection();
string ID = GetRandomizedId();
Expand Down Expand Up @@ -187,7 +187,6 @@ private static async void PackageEndpoint(IPackage package, string endpoint, TEL
}
}


// -------------------------------------------------------------------------

public static void ImportBundle(BundleFormatType type)
Expand Down
4 changes: 3 additions & 1 deletion src/UniGetUI.PAckageEngine.Interfaces/ManagerProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace UniGetUI.PackageEngine.ManagerClasses.Manager
{
public struct ManagerProperties
{
private const IconType DefaultIconId = (IconType)'\uE916';

public bool IsDummy = false;
public string Name { get; set; } = "Unset";
public string? DisplayName { get; set; }
public string Description { get; set; } = "Unset";
public IconType IconId { get; set; } = IconType.Help;
public IconType IconId { get; set; } = DefaultIconId;
public string ColorIconId { get; set; } = "Unset";
// public string ExecutableCallArgs { get; set; } = "Unset";
public string ExecutableFriendlyName { get; set; } = "Unset";
Expand Down
14 changes: 7 additions & 7 deletions src/UniGetUI.PackageEngine.Managers.Cargo/CratesIOClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

namespace UniGetUI.PackageEngine.Managers.CargoManager;

internal record CargoManifest
internal sealed record CargoManifest
{
public CargoManifestCategory[]? categories { get; init; }
public required CargoManifestCrate crate { get; init; }
public required CargoManifestVersion[] versions { get; init; }
}

internal record CargoManifestCategory
internal sealed record CargoManifestCategory
{
public required string category { get; init; }
public required string description { get; init; }
public required string id { get; init; }
}

internal record CargoManifestCrate
internal sealed record CargoManifestCrate
{
public string[]? categories { get; init; }
public string? description { get; init; }
Expand All @@ -34,7 +34,7 @@ internal record CargoManifestCrate
public string? updated_at { get; init; }
}

internal record CargoManifestVersion
internal sealed record CargoManifestVersion
{
public string[]? bin_names { get; init; }
public required string checksum { get; init; }
Expand All @@ -48,19 +48,19 @@ internal record CargoManifestVersion
public bool yanked { get; init; }
}

internal record CargoManifestVersionWrapper
internal sealed record CargoManifestVersionWrapper
{
public required CargoManifestVersion version { get; init; }
}

internal class CargoManifestPublisher
internal sealed class CargoManifestPublisher
{
public string? avatar { get; init; }
public required string name { get; init; }
public string? url { get; init; }
}

internal class CratesIOClient
internal sealed class CratesIOClient
{
public const string ApiUrl = "https://crates.io/api/v1";

Expand Down
Loading
Loading