From 61651877ab26a07e3473e4c385121e05ba858bca Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Fri, 19 Jul 2024 12:31:31 +0200 Subject: [PATCH 1/4] Performance: use Array Empty --- .../AbstractPackageLoader.cs | 10 +++++----- src/UniGetUI/Interface/Dialogs/AboutUniGetUI.xaml.cs | 2 +- src/UniGetUI/Interface/Dialogs/IgnoredUpdates.xaml.cs | 2 +- src/UniGetUI/Interface/Dialogs/InstallOptions.xaml.cs | 2 +- .../Interface/Pages/PackageDetailsPage.xaml.cs | 4 ++-- .../PackageEngine/Operations/SourceOperations.cs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/UniGetUI.PackageEngine.PackageLoader/AbstractPackageLoader.cs b/src/UniGetUI.PackageEngine.PackageLoader/AbstractPackageLoader.cs index c43b03b1a..25d58d8e4 100644 --- a/src/UniGetUI.PackageEngine.PackageLoader/AbstractPackageLoader.cs +++ b/src/UniGetUI.PackageEngine.PackageLoader/AbstractPackageLoader.cs @@ -77,7 +77,7 @@ public virtual async Task ReloadPackages() LoadOperationIdentifier = new Random().Next(); int current_identifier = LoadOperationIdentifier; IsLoading = true; - StartedLoading?.Invoke(this, new EventArgs()); + StartedLoading?.Invoke(this, EventArgs.Empty); List> tasks = []; @@ -124,7 +124,7 @@ public virtual async Task ReloadPackages() if (LoadOperationIdentifier == current_identifier) { - FinishedLoading?.Invoke(this, new EventArgs()); + FinishedLoading?.Invoke(this, EventArgs.Empty); IsLoaded = true; } IsLoading = false; @@ -140,7 +140,7 @@ public void ClearPackages(bool emitFinishSignal = true) PackageReference.Clear(); IsLoaded = false; IsLoading = false; - PackagesChanged?.Invoke(this, new EventArgs()); + PackagesChanged?.Invoke(this, EventArgs.Empty); } /// @@ -213,7 +213,7 @@ public void AddForeign(Package? package) } AddPackage(package); - PackagesChanged?.Invoke(this, new EventArgs()); + PackagesChanged?.Invoke(this, EventArgs.Empty); } /// @@ -234,7 +234,7 @@ public void Remove(Package? package) Packages.Remove(package); PackageReference.Remove(HashPackage(package)); - PackagesChanged?.Invoke(this, new EventArgs()); + PackagesChanged?.Invoke(this, EventArgs.Empty); } /// diff --git a/src/UniGetUI/Interface/Dialogs/AboutUniGetUI.xaml.cs b/src/UniGetUI/Interface/Dialogs/AboutUniGetUI.xaml.cs index 2c0585059..63907f86d 100644 --- a/src/UniGetUI/Interface/Dialogs/AboutUniGetUI.xaml.cs +++ b/src/UniGetUI/Interface/Dialogs/AboutUniGetUI.xaml.cs @@ -49,7 +49,7 @@ private void SelectorBar_SelectionChanged(SelectorBar sender, SelectorBarSelecti private void CloseButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { - Close?.Invoke(this, new EventArgs()); + Close?.Invoke(this, EventArgs.Empty); } } } diff --git a/src/UniGetUI/Interface/Dialogs/IgnoredUpdates.xaml.cs b/src/UniGetUI/Interface/Dialogs/IgnoredUpdates.xaml.cs index 9347dfc34..e3bfb3d14 100644 --- a/src/UniGetUI/Interface/Dialogs/IgnoredUpdates.xaml.cs +++ b/src/UniGetUI/Interface/Dialogs/IgnoredUpdates.xaml.cs @@ -77,7 +77,7 @@ public async void ManageIgnoredUpdates_SecondaryButtonClick(ContentDialog sender private void CloseButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { - Close?.Invoke(this, new EventArgs()); + Close?.Invoke(this, EventArgs.Empty); } } diff --git a/src/UniGetUI/Interface/Dialogs/InstallOptions.xaml.cs b/src/UniGetUI/Interface/Dialogs/InstallOptions.xaml.cs index 3d9fd80f1..d8b91f9be 100644 --- a/src/UniGetUI/Interface/Dialogs/InstallOptions.xaml.cs +++ b/src/UniGetUI/Interface/Dialogs/InstallOptions.xaml.cs @@ -215,7 +215,7 @@ private void ResetDir_Click(object sender, RoutedEventArgs e) private void CloseButton_Click(object sender, RoutedEventArgs e) { - Close?.Invoke(this, new EventArgs()); + Close?.Invoke(this, EventArgs.Empty); } } } diff --git a/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs b/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs index 9d98cb2ce..b5309039f 100644 --- a/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs +++ b/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs @@ -296,7 +296,7 @@ public async void LoadScreenshots() public async void ActionButton_Click(object sender, RoutedEventArgs e) { - Close?.Invoke(this, new EventArgs()); + Close?.Invoke(this, EventArgs.Empty); InstallOptionsPage.SaveToDisk(); switch (OperationRole) { @@ -403,7 +403,7 @@ public async void DownloadInstallerButton_Click(object sender, RoutedEventArgs e } public void CloseButton_Click(object sender, RoutedEventArgs e) { - Close?.Invoke(this, new EventArgs()); + Close?.Invoke(this, EventArgs.Empty); } public void PackageDetailsPage_SizeChanged(object? sender = null, SizeChangedEventArgs? e = null) diff --git a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs index 70cb99d76..15f890b4a 100644 --- a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs @@ -102,7 +102,7 @@ protected override async Task HandleFailure() protected override async Task HandleSuccess() { - OperationSucceeded?.Invoke(this, new EventArgs()); + OperationSucceeded?.Invoke(this, EventArgs.Empty); LineInfoText = CoreTools.Translate("The source {source} was added to {manager} successfully", new Dictionary { { "source", Source.Name }, { "manager", Source.Manager.Name } }); if (!Settings.Get("DisableSuccessNotifications") && !Settings.Get("DisableNotifications")) { @@ -206,7 +206,7 @@ protected override async Task HandleFailure() protected override async Task HandleSuccess() { - OperationSucceeded?.Invoke(this, new EventArgs()); + OperationSucceeded?.Invoke(this, EventArgs.Empty); LineInfoText = CoreTools.Translate("The source {source} was removed from {manager} successfully", new Dictionary { { "source", Source.Name }, { "manager", Source.Manager.Name } }); if (!Settings.Get("DisableSuccessNotifications") && !Settings.Get("DisableNotifications")) { From 6afc32b446593423c38e2e6fbdac55781cf1db8b Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Fri, 19 Jul 2024 12:32:22 +0200 Subject: [PATCH 2/4] Use collection expression --- .../IconCacheEngine.cs | 2 +- .../Chocolatey.cs | 2 +- .../DotNet.cs | 2 +- .../BundledWinGetLegacyMethods.cs | 6 ++--- .../WinGet.cs | 2 +- .../WinGetHelpers/BundledWinGetHelper.cs | 2 +- .../WinGetHelpers/NativeWinGetHelper.cs | 6 ++--- .../Manager/Classes/ManagerCapabilities.cs | 2 +- src/UniGetUI/EntryPoint.cs | 4 ++-- .../SoftwarePages/PackageBundle.xaml.cs | 8 +++---- .../Operations/PackageOperations.cs | 24 +++++++++---------- .../Operations/SourceOperations.cs | 12 +++++----- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/UniGetUI.Core.IconStore/IconCacheEngine.cs b/src/UniGetUI.Core.IconStore/IconCacheEngine.cs index 2241775f4..b33522a2a 100644 --- a/src/UniGetUI.Core.IconStore/IconCacheEngine.cs +++ b/src/UniGetUI.Core.IconStore/IconCacheEngine.cs @@ -17,7 +17,7 @@ public enum CachedIconVerificationMethod public readonly struct CacheableIcon { public readonly Uri Url; - public readonly byte[] Sha256 = { }; + public readonly byte[] Sha256 = []; public readonly string Version = ""; public readonly long Size = -1; public readonly CachedIconVerificationMethod VerificationMethod; diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs index 97d5dbe4a..a6e57bb8e 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs @@ -28,7 +28,7 @@ public Chocolatey() : base() CanRunInteractively = true, SupportsCustomVersions = true, SupportsCustomArchitectures = true, - SupportedCustomArchitectures = new Architecture[] { Architecture.X86 }, + SupportedCustomArchitectures = [Architecture.X86], SupportsPreRelease = true, SupportsCustomSources = true, SupportsCustomPackageIcons = true, diff --git a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs index 9fc95549f..a1ea2011c 100644 --- a/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs +++ b/src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs @@ -32,7 +32,7 @@ public DotNet() : base() CanRunAsAdmin = true, SupportsCustomScopes = true, SupportsCustomArchitectures = true, - SupportedCustomArchitectures = new Architecture[] { Architecture.X86, Architecture.X64, Architecture.Arm64, Architecture.Arm }, + SupportedCustomArchitectures = [Architecture.X86, Architecture.X64, Architecture.Arm64, Architecture.Arm], SupportsPreRelease = true, SupportsCustomLocations = true, SupportsCustomPackageIcons = true, diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs index f7ecc8888..5d22116b0 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs @@ -11,7 +11,7 @@ internal static partial class BundledWinGetLegacyMethods { public static async Task FindPackages_UnSafe(WinGet Manager, string query) { - List Packages = new(); + List Packages = []; Process p = new() { StartInfo = new() @@ -79,7 +79,7 @@ public static async Task FindPackages_UnSafe(WinGet Manager, string q public static async Task GetAvailableUpdates_UnSafe(WinGet Manager) { - List Packages = new(); + List Packages = []; Process p = new() { StartInfo = new() @@ -164,7 +164,7 @@ public static async Task GetAvailableUpdates_UnSafe(WinGet Manager) public static async Task GetInstalledPackages_UnSafe(WinGet Manager) { - List Packages = new(); + List Packages = []; Process p = new() { StartInfo = new() diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs index e073dfbe9..7d2186c39 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs @@ -76,7 +76,7 @@ public WinGet() : base() CanRunInteractively = true, SupportsCustomVersions = true, SupportsCustomArchitectures = true, - SupportedCustomArchitectures = new Architecture[] { Architecture.X86, Architecture.X64, Architecture.Arm64 }, + SupportedCustomArchitectures = [Architecture.X86, Architecture.X64, Architecture.Arm64], SupportsCustomScopes = true, SupportsCustomLocations = true, SupportsCustomSources = true, diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs index 8ef3624e6..eb6a7b564 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs @@ -522,7 +522,7 @@ public async Task GetPackageDetails_UnSafe(WinGet Manager, PackageDetails detail } else if (line.Contains("Tags")) { - details.Tags = new string[0]; + details.Tags = []; IsLoadingTags = true; } } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs index 2f522c245..94006efdf 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs @@ -138,7 +138,7 @@ public async Task FindPackages_UnSafe(WinGet Manager, string query) public async Task GetAvailableUpdates_UnSafe(WinGet Manager) { var logger = Manager.TaskLogger.CreateNew(LoggableTaskType.ListUpdates); - List packages = new(); + List packages = []; foreach (var nativePackage in await Task.Run(() => GetLocalWinGetPackages(logger))) { if (nativePackage.IsUpdateAvailable) @@ -158,7 +158,7 @@ public async Task GetAvailableUpdates_UnSafe(WinGet Manager) public async Task GetInstalledPackages_UnSafe(WinGet Manager) { var logger = Manager.TaskLogger.CreateNew(LoggableTaskType.ListInstalledPackages); - List packages = new(); + List packages = []; foreach (var nativePackage in await Task.Run(() => GetLocalWinGetPackages(logger))) { ManagerSource source; @@ -205,7 +205,7 @@ private IEnumerable GetLocalWinGetPackages(NativeTaskLogger logg findPackagesOptions.Filters.Add(filter); var TaskResult = ConnectResult.PackageCatalog.FindPackages(findPackagesOptions); - List foundPackages = new(); + List foundPackages = []; foreach(var match in TaskResult.Matches.ToArray()) foundPackages.Add(match.CatalogPackage); return foundPackages; diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerCapabilities.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerCapabilities.cs index 8b6675474..310a1e640 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerCapabilities.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerCapabilities.cs @@ -12,7 +12,7 @@ public struct ManagerCapabilities public bool CanRemoveDataOnUninstall = false; public bool SupportsCustomVersions = false; public bool SupportsCustomArchitectures = false; - public Architecture[] SupportedCustomArchitectures = new Architecture[0]; + public Architecture[] SupportedCustomArchitectures = []; public bool SupportsCustomScopes = false; public bool SupportsPreRelease = false; public bool SupportsCustomLocations = false; diff --git a/src/UniGetUI/EntryPoint.cs b/src/UniGetUI/EntryPoint.cs index 03c3e1489..bbcc98470 100644 --- a/src/UniGetUI/EntryPoint.cs +++ b/src/UniGetUI/EntryPoint.cs @@ -145,7 +145,7 @@ static private void WingetUIToUniGetUIMigrator() try { string[] BasePaths = - { + [ // User desktop icon Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), @@ -157,7 +157,7 @@ static private void WingetUIToUniGetUIMigrator() // User start menu icon Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), - }; + ]; foreach (string path in BasePaths) { diff --git a/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs b/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs index 06b535801..09ed7065b 100644 --- a/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs +++ b/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs @@ -830,10 +830,10 @@ public async Task AddPackagesFromBundleString(string content, BundleFormatType f // Load individual packages Dictionary> InvalidPackages = new() { - {DeserializedPackageStatus.ManagerNotFound, new List() }, - {DeserializedPackageStatus.ManagerNotEnabled, new List() }, - {DeserializedPackageStatus.ManagerNotReady, new List() }, - {DeserializedPackageStatus.SourceNotFound, new List() }, + {DeserializedPackageStatus.ManagerNotFound, [] }, + {DeserializedPackageStatus.ManagerNotEnabled, [] }, + {DeserializedPackageStatus.ManagerNotReady, [] }, + {DeserializedPackageStatus.SourceNotFound, [] }, }; // Get a list of all managers diff --git a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs index af87e8ba6..7fa41bdee 100644 --- a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs @@ -101,11 +101,11 @@ protected override async Task BuildProcessInstance(ProcessStartInfo sta protected override string[] GenerateProcessLogHeader() { - return new string[] - { + return + [ "Starting package install operation for package id=" + Package.Id + " with Manager name=" + Package.Manager.Name, - "Given installation options are " + Options.ToString() - }; + "Given installation options are " + Options.ToString(), + ]; } protected override OperationVeredict GetProcessVeredict(int ReturnCode, string[] Output) @@ -220,11 +220,11 @@ protected override async Task BuildProcessInstance(ProcessStartInfo sta protected override string[] GenerateProcessLogHeader() { - return new string[] - { + return + [ "Starting package update operation for package id=" + Package.Id + " with Manager name=" + Package.Manager.Name, - "Given installation options are " + Options.ToString() - }; + "Given installation options are " + Options.ToString(), + ]; } protected override OperationVeredict GetProcessVeredict(int ReturnCode, string[] Output) @@ -351,11 +351,11 @@ protected override async Task BuildProcessInstance(ProcessStartInfo sta protected override string[] GenerateProcessLogHeader() { - return new string[] - { + return + [ "Starting package uninstall operation for package id=" + Package.Id + " with Manager name=" + Package.Manager.Name, - "Given installation options are " + Options.ToString() - }; + "Given installation options are " + Options.ToString(), + ]; } protected override OperationVeredict GetProcessVeredict(int ReturnCode, string[] Output) diff --git a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs index 15f890b4a..7ce147b84 100644 --- a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs @@ -52,10 +52,10 @@ protected override async Task BuildProcessInstance(ProcessStartInfo sta protected override string[] GenerateProcessLogHeader() { - return new string[] - { + return + [ "Starting adding source operation for source name=" + Source.Name + "with Manager name=" + Source.Manager.Name, - }; + ]; } protected override OperationVeredict GetProcessVeredict(int ReturnCode, string[] Output) @@ -165,10 +165,10 @@ protected override async Task BuildProcessInstance(ProcessStartInfo sta protected override string[] GenerateProcessLogHeader() { - return new string[] - { + return + [ "Starting remove source operation for source name=" + Source.Name + "with Manager name=" + Source.Manager.Name, - }; + ]; } protected override OperationVeredict GetProcessVeredict(int ReturnCode, string[] Output) From 5bcbcf3daf6a0ceeb86e4c2bb4988604b22e3266 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Fri, 19 Jul 2024 12:35:57 +0200 Subject: [PATCH 3/4] Remove redundant else --- src/UniGetUI.Core.Data/CoreData.cs | 46 +++++++++---------- .../LanguageData.cs | 12 ++--- .../LanguageEngine.cs | 12 ++--- src/UniGetUI.Core.Tools/Tools.cs | 8 ++-- .../Chocolatey.cs | 14 ++++-- .../Pip.cs | 8 ++-- .../WinGet.cs | 3 +- .../WinGetHelpers/BundledWinGetHelper.cs | 24 ++++------ .../WinGetSourceProvider.cs | 6 +-- .../DiscoverablePackagesLoader.cs | 12 ++--- .../BasePackageDetailsProvider.cs | 14 ++---- .../Manager/Classes/ManagerLogger.cs | 18 ++++---- .../Manager/Classes/ManagerSource.cs | 6 +-- .../Manager/PackageManager.cs | 24 +++++----- .../Packages/Package.cs | 12 ++--- src/UniGetUI/EntryPoint.cs | 3 +- src/UniGetUI/Interface/MainWindow.xaml.cs | 6 +-- .../Interface/Pages/LogPage/AppLogPage.cs | 9 ++-- .../PackageEngine/Classes/ImportExport.cs | 6 +-- .../Operations/PackageOperations.cs | 18 +++----- .../Operations/SourceOperations.cs | 12 ++--- 21 files changed, 118 insertions(+), 155 deletions(-) diff --git a/src/UniGetUI.Core.Data/CoreData.cs b/src/UniGetUI.Core.Data/CoreData.cs index 4ea03a78c..8e07b2e3c 100644 --- a/src/UniGetUI.Core.Data/CoreData.cs +++ b/src/UniGetUI.Core.Data/CoreData.cs @@ -8,7 +8,7 @@ public static class CoreData { private static int? __code_page; public static int CODE_PAGE { get => __code_page ??= GetCodePage(); } - + private static int GetCodePage() { try @@ -26,7 +26,7 @@ private static int GetCodePage() p.Start(); string contents = p.StandardOutput.ReadToEnd(); return int.Parse(contents.Split(':')[^1].Trim()); - } + } catch (Exception e) { Logger.Error(e); @@ -184,10 +184,8 @@ public static string UniGetUIExecutableDirectory { return dir; } - else - { - Logger.Error("System.Reflection.Assembly.GetExecutingAssembly().Location returned an empty path"); - } + + Logger.Error("System.Reflection.Assembly.GetExecutingAssembly().Location returned an empty path"); return Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UiGetUI"); } @@ -205,10 +203,8 @@ public static string UniGetUIExecutableFile { return filename.Replace(".dll", ".exe"); } - else - { - Logger.Error("System.Reflection.Assembly.GetExecutingAssembly().Location returned an empty path"); - } + + Logger.Error("System.Reflection.Assembly.GetExecutingAssembly().Location returned an empty path"); return Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniGetUI", "UniGetUI.exe"); } @@ -232,7 +228,8 @@ private static string GetNewDataDirectoryOrMoveOld(string old_path, string new_p { return new_path; } - else if (Directory.Exists(new_path) && Directory.Exists(old_path)) + + if (Directory.Exists(new_path) && Directory.Exists(old_path)) { try { @@ -287,7 +284,8 @@ private static string GetNewDataDirectoryOrMoveOld(string old_path, string new_p return new_path; } } - else if (/*Directory.Exists(new_path)*/Directory.Exists(old_path)) + + if (/*Directory.Exists(new_path)*/Directory.Exists(old_path)) { try { @@ -302,20 +300,18 @@ private static string GetNewDataDirectoryOrMoveOld(string old_path, string new_p return old_path; } } - else + + try { - try - { - Logger.Debug("Creating non-existing data directory at: " + new_path); - Directory.CreateDirectory(new_path); - return new_path; - } - catch (Exception e) - { - Logger.Error("Could not create new directory. You may perhaps need to disable Controlled Folder Access from Windows Settings or make an exception for UniGetUI."); - Logger.Error(e); - return new_path; - } + Logger.Debug("Creating non-existing data directory at: " + new_path); + Directory.CreateDirectory(new_path); + return new_path; + } + catch (Exception e) + { + Logger.Error("Could not create new directory. You may perhaps need to disable Controlled Folder Access from Windows Settings or make an exception for UniGetUI."); + Logger.Error(e); + return new_path; } } diff --git a/src/UniGetUI.Core.LanguageEngine/LanguageData.cs b/src/UniGetUI.Core.LanguageEngine/LanguageData.cs index 18c3cb221..4d5fe1cff 100644 --- a/src/UniGetUI.Core.LanguageEngine/LanguageData.cs +++ b/src/UniGetUI.Core.LanguageEngine/LanguageData.cs @@ -62,10 +62,8 @@ private static ReadOnlyDictionary LoadTranslationPercentages() { return new(val.ToDictionary(x => x.Key, x => (x.Value ?? ("404%" + x.Key)).ToString())); } - else - { - return new(new Dictionary()); - } + + return new(new Dictionary()); } private static ReadOnlyDictionary LoadLanguageReference() @@ -74,10 +72,8 @@ private static ReadOnlyDictionary LoadLanguageReference() { return new(val.ToDictionary(x => x.Key, x => (x.Value ?? ("NoNameLang_" + x.Key)).ToString())); } - else - { - return new(new Dictionary()); - } + + return new(new Dictionary()); } private static Person[] LoadLanguageTranslatorList() diff --git a/src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs b/src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs index 13bc8b6ae..dd902ba68 100644 --- a/src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs +++ b/src/UniGetUI.Core.LanguageEngine/LanguageEngine.cs @@ -152,7 +152,8 @@ public string Translate(string key) return "UniGetUI (formerly WingetUI)"; } - else if (key == "Formerly known as WingetUI") + + if (key == "Formerly known as WingetUI") { if (MainLangDict.ContainsKey(key)) { @@ -166,14 +167,13 @@ public string Translate(string key) { return ""; } - else if (MainLangDict.ContainsKey(key) && MainLangDict[key] != "") + + if (MainLangDict.ContainsKey(key) && MainLangDict[key] != "") { return MainLangDict[key].Replace("WingetUI", "UniGetUI"); } - else - { - return key.Replace("WingetUI", "UniGetUI"); - } + + return key.Replace("WingetUI", "UniGetUI"); } public string Translate(string key, Dictionary dict) diff --git a/src/UniGetUI.Core.Tools/Tools.cs b/src/UniGetUI.Core.Tools/Tools.cs index 2e1b1b1fd..f0a7fe451 100644 --- a/src/UniGetUI.Core.Tools/Tools.cs +++ b/src/UniGetUI.Core.Tools/Tools.cs @@ -112,11 +112,9 @@ public static async Task> Which(string command) Logger.ImportantInfo($"Command {command} was not found on the system"); return new Tuple(false, ""); } - else - { - Logger.Debug($"Command {command} was found on {output}"); - return new Tuple(File.Exists(output), output); - } + + Logger.Debug($"Command {command} was found on {output}"); + return new Tuple(File.Exists(output), output); } /// diff --git a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs index a6e57bb8e..20ac24cd7 100644 --- a/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs +++ b/src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs @@ -174,15 +174,18 @@ public override OperationVeredict GetInstallOperationVeredict(Package package, I { return OperationVeredict.Succeeded; } - else if (ReturnCode == 3010) + + if (ReturnCode == 3010) { return OperationVeredict.Succeeded; // TODO: Restart required } - else if ((output_string.Contains("Run as administrator") || output_string.Contains("The requested operation requires elevation") || output_string.Contains("ERROR: Exception calling \"CreateDirectory\" with \"1\" argument(s): \"Access to the path")) && !options.RunAsAdministrator) + + if ((output_string.Contains("Run as administrator") || output_string.Contains("The requested operation requires elevation") || output_string.Contains("ERROR: Exception calling \"CreateDirectory\" with \"1\" argument(s): \"Access to the path")) && !options.RunAsAdministrator) { options.RunAsAdministrator = true; return OperationVeredict.AutoRetry; } + return OperationVeredict.Failed; } @@ -199,15 +202,18 @@ public override OperationVeredict GetUninstallOperationVeredict(Package package, { return OperationVeredict.Succeeded; } - else if (ReturnCode == 3010) + + if (ReturnCode == 3010) { return OperationVeredict.Succeeded; // TODO: Restart required } - else if ((output_string.Contains("Run as administrator") || output_string.Contains("The requested operation requires elevation")) && !options.RunAsAdministrator) + + if ((output_string.Contains("Run as administrator") || output_string.Contains("The requested operation requires elevation")) && !options.RunAsAdministrator) { options.RunAsAdministrator = true; return OperationVeredict.AutoRetry; } + return OperationVeredict.Failed; } public override string[] GetInstallParameters(Package package, InstallationOptions options) diff --git a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs index 3f71a4144..2469f8518 100644 --- a/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs +++ b/src/UniGetUI.PackageEngine.Managers.Pip/Pip.cs @@ -264,15 +264,13 @@ public override OperationVeredict GetInstallOperationVeredict(Package package, I { return OperationVeredict.Succeeded; } - else if (output_string.Contains("--user") && package.Scope == PackageScope.Global) + + if (output_string.Contains("--user") && package.Scope == PackageScope.Global) { package.Scope = PackageScope.User; return OperationVeredict.AutoRetry; } - else - { - return OperationVeredict.Failed; - } + return OperationVeredict.Failed; } public override OperationVeredict GetUpdateOperationVeredict(Package package, InstallationOptions options, int ReturnCode, string[] Output) diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs index 7d2186c39..a5fbc37b8 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs @@ -288,7 +288,8 @@ public override OperationVeredict GetInstallOperationVeredict(Package package, I { return OperationVeredict.Succeeded; // TODO: Needs restart } - else if (ReturnCode == -1978335215) + + if (ReturnCode == -1978335215) { return OperationVeredict.Failed; // TODO: Needs skip checksum } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs index eb6a7b564..004294370 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs @@ -103,11 +103,9 @@ function Print-WinGetPackage { { return Packages.ToArray(); } - else - { - Logger.Warn("WinGet updates returned zero packages, attempting legacy..."); - return await BundledWinGetLegacyMethods.GetAvailableUpdates_UnSafe(Manager); - } + + Logger.Warn("WinGet updates returned zero packages, attempting legacy..."); + return await BundledWinGetLegacyMethods.GetAvailableUpdates_UnSafe(Manager); } public async Task GetInstalledPackages_UnSafe(WinGet Manager) @@ -202,11 +200,9 @@ function Print-WinGetPackage { { return Packages.ToArray(); } - else - { - Logger.Warn("WinGet installed packages returned zero packages, attempting legacy..."); - return await BundledWinGetLegacyMethods.GetInstalledPackages_UnSafe(Manager); - } + + Logger.Warn("WinGet installed packages returned zero packages, attempting legacy..."); + return await BundledWinGetLegacyMethods.GetInstalledPackages_UnSafe(Manager); } @@ -293,11 +289,9 @@ function Print-WinGetPackage { { return Packages.ToArray(); } - else - { - Logger.Warn("WinGet package fetching returned zero packages, attempting legacy..."); - return await BundledWinGetLegacyMethods.FindPackages_UnSafe(Manager, query); - } + + Logger.Warn("WinGet package fetching returned zero packages, attempting legacy..."); + return await BundledWinGetLegacyMethods.FindPackages_UnSafe(Manager, query); } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetSourceProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetSourceProvider.cs index 8f82626c4..67f63f5d5 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetSourceProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetSourceProvider.cs @@ -41,10 +41,8 @@ protected override async Task GetSources_UnSafe() { return await WinGetHelper.Instance.GetSources_UnSafe(manager); } - else - { - throw new Exception("WinGetSourceProvider.GetSources_UnSafe: Manager is supposed to be WinGet"); - } + + throw new Exception("WinGetSourceProvider.GetSources_UnSafe: Manager is supposed to be WinGet"); } } } diff --git a/src/UniGetUI.PackageEngine.PackageLoader/DiscoverablePackagesLoader.cs b/src/UniGetUI.PackageEngine.PackageLoader/DiscoverablePackagesLoader.cs index e9889c9c6..13dba7025 100644 --- a/src/UniGetUI.PackageEngine.PackageLoader/DiscoverablePackagesLoader.cs +++ b/src/UniGetUI.PackageEngine.PackageLoader/DiscoverablePackagesLoader.cs @@ -25,10 +25,8 @@ public override async Task ReloadPackages() { return; } - else - { - await base.ReloadPackages(); - } + + await base.ReloadPackages(); } #pragma warning disable @@ -46,10 +44,8 @@ protected override Task LoadPackagesFromManager(PackageManager manage { return new Task(() => { return []; }); } - else - { - return manager.FindPackages(text); - } + + return manager.FindPackages(text); } #pragma warning disable diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs index a9b645361..e71034e42 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/BaseProviders/BasePackageDetailsProvider.cs @@ -28,11 +28,9 @@ public async Task GetPackageVersions(Package package) Logger.Debug($"Found {result.Length} versions for package Id={package.Id} on manager {Manager.Name}"); return result; } - else - { - Logger.Warn($"Manager {Manager.Name} does not support version retrieving, this method should have not been called"); - return []; - } + + Logger.Warn($"Manager {Manager.Name} does not support version retrieving, this method should have not been called"); + return []; } public async Task GetPackageIconUrl(Package package) @@ -65,10 +63,8 @@ public async Task GetPackageVersions(Package package) Logger.Warn($"Icon for package {package.Id} was not found, returning default icon"); return null; } - else - { - Logger.Info($"Loaded icon with URL={Icon.ToString()} for package Id={package.Id}"); - } + + Logger.Info($"Loaded icon with URL={Icon.ToString()} for package Id={package.Id}"); return Icon; } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerLogger.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerLogger.cs index bf630879f..74594c6ed 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerLogger.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerLogger.cs @@ -182,7 +182,8 @@ public override IEnumerable AsColoredString(bool verbose = false) { return CachedMessage; } - else if (verbose && CachedVerboseMessage != null && isComplete) + + if (verbose && CachedVerboseMessage != null && isComplete) { return CachedVerboseMessage; } @@ -263,10 +264,8 @@ public override IEnumerable AsColoredString(bool verbose = false) { return CachedVerboseMessage = result; } - else - { - return CachedMessage = result; - } + + return CachedMessage = result; } } @@ -346,7 +345,8 @@ public override IEnumerable AsColoredString(bool verbose = false) { return CachedMessage; } - else if (verbose && CachedVerboseMessage != null && isComplete) + + if (verbose && CachedVerboseMessage != null && isComplete) { return CachedVerboseMessage; } @@ -409,10 +409,8 @@ public override IEnumerable AsColoredString(bool verbose = false) { return CachedVerboseMessage = result; } - else - { - return CachedMessage = result; - } + + return CachedMessage = result; } } } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerSource.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerSource.cs index a20bc4b2a..6feabe775 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerSource.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/Classes/ManagerSource.cs @@ -41,10 +41,8 @@ public override string ToString() { return Manager.Name + ": " + Name; } - else - { - return Manager.Name; - } + + return Manager.Name; } /// diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs index 6da88deda..543982962 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Manager/PackageManager.cs @@ -55,15 +55,18 @@ public virtual async Task InitializeAsync() { throw new Exception($"The Manager {Properties.Name} has not called the base constructor."); } - else if (Capabilities.IsDummy) + + if (Capabilities.IsDummy) { throw new Exception($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Capabilities object"); } - else if (Properties.IsDummy) + + if (Properties.IsDummy) { throw new Exception($"The current instance of PackageManager with name ${Properties.Name} does not have a valid Properties object"); } - else if (Capabilities.SupportsCustomSources && SourceProvider == null) + + if (Capabilities.SupportsCustomSources && SourceProvider == null) { throw new Exception($"Manager {Name} has been declared as SupportsCustomSources but has no helper associated with it"); } @@ -149,7 +152,7 @@ public bool IsReady() } /// - /// Returns an array of Package objects that the manager lists for the given query. Depending on the manager, the list may + /// Returns an array of Package objects that the manager lists for the given query. Depending on the manager, the list may /// also include similar results. This method is fail-safe and will return an empty array if an error occurs. /// /// @@ -176,7 +179,7 @@ public async Task FindPackages(string query) } /// - /// Returns an array of UpgradablePackage objects that represent the available updates reported by the manager. + /// Returns an array of UpgradablePackage objects that represent the available updates reported by the manager. /// This method is fail-safe and will return an empty array if an error occurs. /// /// @@ -205,7 +208,7 @@ public async Task GetAvailableUpdates() } /// - /// Returns an array of Package objects that represent the installed reported by the manager. + /// Returns an array of Package objects that represent the installed reported by the manager. /// This method is fail-safe and will return an empty array if an error occurs. /// /// @@ -342,7 +345,8 @@ private void AssertSourceCompatibility(string MethodName) { throw new Exception($"Manager {Name} does not support custom sources but yet {MethodName} method was called.\n {Environment.StackTrace}"); } - else if (SourceProvider == null) + + if (SourceProvider == null) { throw new Exception($"Manager {Name} does support custom sources but yet the source helper is null"); } @@ -447,10 +451,8 @@ public async Task GetPackageVersions(Package package) { return await PackageDetailsProvider.GetPackageVersions(package); } - else - { - return []; - } + + return []; } catch (Exception e) { diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs index bb4f3207f..565052a7e 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Package.cs @@ -315,10 +315,8 @@ public async Task HasUpdatesIgnoredAsync(string Version = "*") { return true; } - else - { - return false; - } + + return false; } catch (Exception ex) { @@ -350,10 +348,8 @@ public async Task GetIgnoredUpdatesVersionAsync() { return IgnoredUpdatesJson[IgnoredId]?.ToString() ?? ""; } - else - { - return ""; - } + + return ""; } catch (Exception ex) { diff --git a/src/UniGetUI/EntryPoint.cs b/src/UniGetUI/EntryPoint.cs index bbcc98470..b93bee8a1 100644 --- a/src/UniGetUI/EntryPoint.cs +++ b/src/UniGetUI/EntryPoint.cs @@ -171,7 +171,8 @@ static private void WingetUIToUniGetUIMigrator() { continue; } - else if (File.Exists(old_file) && File.Exists(new_file)) + + if (File.Exists(old_file) && File.Exists(new_file)) { Logger.Info("Deleting shortcut " + old_file + " since new shortcut already exists"); File.Delete(old_file); diff --git a/src/UniGetUI/Interface/MainWindow.xaml.cs b/src/UniGetUI/Interface/MainWindow.xaml.cs index d849425e1..9a4beb3a2 100644 --- a/src/UniGetUI/Interface/MainWindow.xaml.cs +++ b/src/UniGetUI/Interface/MainWindow.xaml.cs @@ -797,10 +797,8 @@ private bool IsRectangleFullyVisible(int x, int y, int width, int height) { return false; } - else - { - return true; - } + + return true; } } } diff --git a/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs b/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs index 113f0e1ae..af21566c6 100644 --- a/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs +++ b/src/UniGetUI/Interface/Pages/LogPage/AppLogPage.cs @@ -40,15 +40,18 @@ public override void LoadLog() { continue; } - else if (LOG_LEVEL == 2 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success)) + + if (LOG_LEVEL == 2 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info || log_entry.Severity == LogEntry.SeverityLevel.Success)) { continue; } - else if (LOG_LEVEL == 3 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info)) + + if (LOG_LEVEL == 3 && (log_entry.Severity == LogEntry.SeverityLevel.Debug || log_entry.Severity == LogEntry.SeverityLevel.Info)) { continue; } - else if (LOG_LEVEL == 4 && (log_entry.Severity == LogEntry.SeverityLevel.Debug)) + + if (LOG_LEVEL == 4 && (log_entry.Severity == LogEntry.SeverityLevel.Debug)) { continue; } diff --git a/src/UniGetUI/PackageEngine/Classes/ImportExport.cs b/src/UniGetUI/PackageEngine/Classes/ImportExport.cs index db953700a..ec61afad8 100644 --- a/src/UniGetUI/PackageEngine/Classes/ImportExport.cs +++ b/src/UniGetUI/PackageEngine/Classes/ImportExport.cs @@ -100,10 +100,8 @@ public virtual string version { return CoreTools.Translate("Latest"); } - else - { - return Package.Version; - } + + return Package.Version; } } diff --git a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs index 7fa41bdee..9ae3294cd 100644 --- a/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/PackageOperations.cs @@ -147,10 +147,8 @@ protected override async Task HandleFailure() { return AfterFinshAction.Retry; } - else - { - return AfterFinshAction.ManualClose; - } + + return AfterFinshAction.ManualClose; } protected override async Task HandleSuccess() @@ -266,10 +264,8 @@ protected override async Task HandleFailure() { return AfterFinshAction.Retry; } - else - { - return AfterFinshAction.ManualClose; - } + + return AfterFinshAction.ManualClose; } protected override async Task HandleSuccess() @@ -397,10 +393,8 @@ protected override async Task HandleFailure() { return AfterFinshAction.Retry; } - else - { - return AfterFinshAction.ManualClose; - } + + return AfterFinshAction.ManualClose; } protected override async Task HandleSuccess() diff --git a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs index 7ce147b84..743103620 100644 --- a/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs +++ b/src/UniGetUI/PackageEngine/Operations/SourceOperations.cs @@ -94,10 +94,8 @@ protected override async Task HandleFailure() { return AfterFinshAction.Retry; } - else - { - return AfterFinshAction.ManualClose; - } + + return AfterFinshAction.ManualClose; } protected override async Task HandleSuccess() @@ -198,10 +196,8 @@ protected override async Task HandleFailure() { return AfterFinshAction.Retry; } - else - { - return AfterFinshAction.ManualClose; - } + + return AfterFinshAction.ManualClose; } protected override async Task HandleSuccess() From 92d82c02fec160c023cc47eebbfacca68ce4c111 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Fri, 19 Jul 2024 12:37:41 +0200 Subject: [PATCH 4/4] Performance: use count access --- .../BundledWinGetLegacyMethods.cs | 18 +++++++++--------- .../WinGet.cs | 4 ++-- .../WinGetHelpers/BundledWinGetHelper.cs | 6 +++--- .../WinGetHelpers/NativeWinGetHelper.cs | 4 ++-- .../WinGetPackageDetailsProvider.cs | 2 +- .../Interface/Pages/PackageDetailsPage.xaml.cs | 2 +- .../SoftwarePages/AbstractPackagesPage.xaml.cs | 6 +++--- .../SoftwarePages/PackageBundle.xaml.cs | 4 ++-- .../SoftwarePages/SoftwareUpdatesPage.cs | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs index 5d22116b0..8a249e983 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/BundledWinGetLegacyMethods.cs @@ -26,9 +26,9 @@ public static async Task FindPackages_UnSafe(WinGet Manager, string q StandardOutputEncoding = System.Text.Encoding.UTF8 } }; - + ProcessTaskLogger logger = Manager.TaskLogger.CreateNew(LoggableTaskType.FindPackages, p); - + p.Start(); string OldLine = ""; @@ -96,7 +96,7 @@ public static async Task GetAvailableUpdates_UnSafe(WinGet Manager) }; ProcessTaskLogger logger = Manager.TaskLogger.CreateNew(LoggableTaskType.ListUpdates, p); - + p.Start(); string OldLine = ""; @@ -112,7 +112,7 @@ public static async Task GetAvailableUpdates_UnSafe(WinGet Manager) if (line.Contains("have pins")) continue; - + if (!DashesPassed && line.Contains("---")) { string HeaderPrefix = OldLine.Contains("SearchId") ? "Search" : ""; @@ -178,9 +178,9 @@ public static async Task GetInstalledPackages_UnSafe(WinGet Manager) StandardOutputEncoding = System.Text.Encoding.UTF8 } }; - + ProcessTaskLogger logger = Manager.TaskLogger.CreateNew(LoggableTaskType.ListInstalledPackages, p); - + p.Start(); string OldLine = ""; @@ -235,7 +235,7 @@ public static async Task GetInstalledPackages_UnSafe(WinGet Manager) Logger.Error(e); } } - + logger.AddToStdErr(await p.StandardError.ReadToEndAsync()); await p.WaitForExitAsync(); logger.Close(p.ExitCode); @@ -259,11 +259,11 @@ private static ManagerSource GetLocalSource(WinGet Manager, string id) return Manager.AndroidSubsystemSource; // Check if source is Steama - if ((id == "Steam" || id.Contains("Steam App ")) && id.Split("Steam App").Count() >= 2 && id.Split("Steam App")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) + if ((id == "Steam" || id.Contains("Steam App ")) && id.Split("Steam App").Length >= 2 && id.Split("Steam App")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) return Manager.SteamSource; // Check if source is Ubisoft Connect - if (id == "Uplay" || id.Contains("Uplay Install ") && id.Split("Uplay Install").Count() >= 2 && id.Split("Uplay Install")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) + if (id == "Uplay" || id.Contains("Uplay Install ") && id.Split("Uplay Install").Length >= 2 && id.Split("Uplay Install")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) return Manager.UbisoftConnectSource; // Check if source is GOG diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs index a5fbc37b8..6bfd22712 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGet.cs @@ -153,13 +153,13 @@ public ManagerSource GetLocalSource(string id) } // Check if source is Steam - if ((id == "Steam" || id.Contains("Steam App ")) && id.Split("Steam App").Count() >= 2 && id.Split("Steam App")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) + if ((id == "Steam" || id.Contains("Steam App ")) && id.Split("Steam App").Length >= 2 && id.Split("Steam App")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0) { return SteamSource; } // Check if source is Ubisoft Connect - if (id == "Uplay" || (id.Contains("Uplay Install ") && id.Split("Uplay Install").Count() >= 2 && id.Split("Uplay Install")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0)) + if (id == "Uplay" || (id.Contains("Uplay Install ") && id.Split("Uplay Install").Length >= 2 && id.Split("Uplay Install")[1].Trim().Count(x => !"1234567890".Contains(x)) == 0)) { return UbisoftConnectSource; } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs index 004294370..164b87dc4 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/BundledWinGetHelper.cs @@ -99,7 +99,7 @@ function Print-WinGetPackage { await p.WaitForExitAsync(); logger.Close(p.ExitCode); - if (Packages.Count() > 0) + if (Packages.Count > 0) { return Packages.ToArray(); } @@ -196,7 +196,7 @@ function Print-WinGetPackage { await p.WaitForExitAsync(); logger.Close(p.ExitCode); - if (Packages.Count() > 0) + if (Packages.Count > 0) { return Packages.ToArray(); } @@ -285,7 +285,7 @@ function Print-WinGetPackage { await p.WaitForExitAsync(); logger.Close(p.ExitCode); - if (Packages.Count() > 0) + if (Packages.Count > 0) { return Packages.ToArray(); } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs index 94006efdf..55f4a7ad6 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetHelpers/NativeWinGetHelper.cs @@ -269,7 +269,7 @@ public async Task GetPackageVersions_Unsafe(WinGet Manager, Package pa Task.Run(() => ConnectResult.PackageCatalog.FindPackages(packageMatchFilter)); if (SearchResult.Result == null || SearchResult.Result.Matches == null || - SearchResult.Result.Matches.Count() == 0) + SearchResult.Result.Matches.Count == 0) { logger.Error("Failed to find package " + package.Id + " in catalog " + package.Source.Name); logger.Close(1); @@ -340,7 +340,7 @@ public async Task GetPackageDetails_UnSafe(WinGet Manager, PackageDetails detail Task.Run(() => ConnectResult.PackageCatalog.FindPackages(packageMatchFilter)); if (SearchResult.Result == null || SearchResult.Result.Matches == null || - SearchResult.Result.Matches.Count() == 0) + SearchResult.Result.Matches.Count == 0) { logger.Error("WinGet: Failed to find package " + details.Package.Id + " in catalog " + details.Package.Source.Name); diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetPackageDetailsProvider.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetPackageDetailsProvider.cs index 8d9419133..c35fe0938 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetPackageDetailsProvider.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/WinGetPackageDetailsProvider.cs @@ -232,7 +232,7 @@ protected override async Task GetPackageScreenshots_Unsafe(Package packag packageMatchFilter.ResultLimit = 1; Task SearchResult = Task.Run(() => ConnectResult.PackageCatalog.FindPackages(packageMatchFilter)); - if (SearchResult.Result == null || SearchResult.Result.Matches == null || SearchResult.Result.Matches.Count() == 0) + if (SearchResult.Result == null || SearchResult.Result.Matches == null || SearchResult.Result.Matches.Count == 0) { Logger.Error("[WINGET COM] Failed to find package " + package.Id + " in catalog " + package.Source.Name); return null; diff --git a/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs b/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs index b5309039f..4b107d9ff 100644 --- a/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs +++ b/src/UniGetUI/Interface/Pages/PackageDetailsPage.xaml.cs @@ -277,7 +277,7 @@ public async void LoadIcon() public async void LoadScreenshots() { Uri[] screenshots = await Package.GetPackageScreenshots(); - PackageHasScreenshots = screenshots.Count() > 0; + PackageHasScreenshots = screenshots.Length > 0; if (PackageHasScreenshots) { PackageHasScreenshots = true; diff --git a/src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs b/src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs index 9a5a52961..5bafaa581 100644 --- a/src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs +++ b/src/UniGetUI/Interface/SoftwarePages/AbstractPackagesPage.xaml.cs @@ -103,7 +103,7 @@ protected string NoPackages_SubtitleText } protected string NoMatches_SubtitleText { - get => FoundPackages_SubtitleText_Base(Loader.Packages.Count(), FilteredPackages.Count()) + + get => FoundPackages_SubtitleText_Base(Loader.Packages.Count, FilteredPackages.Count) + (SHOW_LAST_CHECKED_TIME ? " " + CoreTools.Translate("(Last checked: {0})", LastPackageLoadTime.ToString()) : ""); } protected string FoundPackages_SubtitleText { get => NoMatches_SubtitleText; } @@ -582,11 +582,11 @@ public void FilterPackages() /// public void UpdatePackageCount() { - if (FilteredPackages.Count() == 0) + if (FilteredPackages.Count == 0) { if (LoadingProgressBar.Visibility == Visibility.Collapsed) { - if (Loader.Packages.Count() == 0) + if (Loader.Packages.Count == 0) { BackgroundText.Text = NoPackages_BackgroundText; SourcesPlaceholderText.Text = NoPackages_SourcesText; diff --git a/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs b/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs index 09ed7065b..a8fbe22ba 100644 --- a/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs +++ b/src/UniGetUI/Interface/SoftwarePages/PackageBundle.xaml.cs @@ -393,11 +393,11 @@ public void FilterPackages(string query, bool StillLoading = false) FilteredPackages.BlockSorting = false; FilteredPackages.Sort(); - if (MatchingList.Count() == 0) + if (MatchingList.Length == 0) { if (!StillLoading) { - if (Packages.Count() == 0) + if (Packages.Count == 0) { BackgroundText.Text = SourcesPlaceholderText.Text = CoreTools.AutoTranslated("We couldn't find any package"); SourcesPlaceholderText.Text = CoreTools.AutoTranslated("No packages found"); diff --git a/src/UniGetUI/Interface/SoftwarePages/SoftwareUpdatesPage.cs b/src/UniGetUI/Interface/SoftwarePages/SoftwareUpdatesPage.cs index ec75fdd8e..351cdf27c 100644 --- a/src/UniGetUI/Interface/SoftwarePages/SoftwareUpdatesPage.cs +++ b/src/UniGetUI/Interface/SoftwarePages/SoftwareUpdatesPage.cs @@ -298,7 +298,7 @@ protected override void WhenPackageCountUpdated() { try { - MainApp.Instance.TooltipStatus.AvailableUpdates = Loader.Packages.Count(); + MainApp.Instance.TooltipStatus.AvailableUpdates = Loader.Packages.Count; } catch (Exception) { }