From a41cb824d38df353e1c048552b90a28f2a702e07 Mon Sep 17 00:00:00 2001 From: "codefactor-io[bot]" <47775046+codefactor-io[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 17:44:50 +0530 Subject: [PATCH] [CodeFactor] Apply fixes (#49) Co-authored-by: codefactor-io --- Emerald.App/Emerald.App/Helpers/Extensions.cs | 12 ++++-------- Emerald.App/Emerald.App/Helpers/Settings/JSON.cs | 5 ----- .../Emerald.App/Helpers/Settings/SettingsSystem.cs | 3 +-- Emerald.App/Emerald.App/Helpers/Updater/Updater.cs | 3 --- Emerald.App/Emerald.App/Helpers/WindowManager.cs | 4 +--- Emerald.App/Emerald.App/MainWindow.xaml.cs | 4 +--- Emerald.App/Emerald.App/Models/Account.cs | 3 +-- Emerald.App/Emerald.App/Models/NavViewHeader.cs | 3 +-- .../UserControls/AdaptiveItemPane.xaml.cs | 2 -- .../Emerald.App/UserControls/ExpanderItem.xaml.cs | 2 -- .../Emerald.App/Views/Home/AccountsPage.xaml.cs | 5 +---- Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs | 7 +------ Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs | 1 - .../Emerald.App/Views/Settings/AboutPage.xaml.cs | 3 +-- .../Views/Settings/AppearancePage.xaml.cs | 3 +-- .../Emerald.App/Views/Settings/GeneralPage.xaml.cs | 6 +----- Emerald.Core/Launcher.cs | 6 +++--- Emerald.Core/News/JSON/Dimensions.cs | 1 - Emerald.Core/News/JSON/Entry.cs | 1 - Emerald.Core/News/NewsHelper.cs | 3 +-- Emerald.Core/Optifine.cs | 4 ++-- Emerald.Core/Store/Labrinth.cs | 12 ++---------- Emerald.Core/Util.cs | 4 ++-- 23 files changed, 24 insertions(+), 73 deletions(-) diff --git a/Emerald.App/Emerald.App/Helpers/Extensions.cs b/Emerald.App/Emerald.App/Helpers/Extensions.cs index 2d61c177..5f0a94d0 100644 --- a/Emerald.App/Emerald.App/Helpers/Extensions.cs +++ b/Emerald.App/Emerald.App/Helpers/Extensions.cs @@ -1,4 +1,4 @@ -using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.Windows.ApplicationModel.Resources; using System; @@ -112,15 +112,11 @@ public static string ToBinaryString(this string str) public static string ToMD5(this string s) { StringBuilder sb = new(); + byte[] hashValue = MD5.HashData(Encoding.UTF8.GetBytes(s)); - using (MD5 md5 = MD5.Create()) + foreach (byte b in hashValue) { - byte[] hashValue = md5.ComputeHash(Encoding.UTF8.GetBytes(s)); - - foreach (byte b in hashValue) - { - sb.Append($"{b:X2}"); - } + sb.Append($"{b:X2}"); } return sb.ToString(); diff --git a/Emerald.App/Emerald.App/Helpers/Settings/JSON.cs b/Emerald.App/Emerald.App/Helpers/Settings/JSON.cs index 8122d468..b639a0c1 100644 --- a/Emerald.App/Emerald.App/Helpers/Settings/JSON.cs +++ b/Emerald.App/Emerald.App/Helpers/Settings/JSON.cs @@ -114,7 +114,6 @@ public class Account : JSON public partial class Downloader : JSON { - [ObservableProperty] private bool _HashCheck; @@ -154,7 +153,6 @@ public JVM() [JsonIgnore] public bool SetSize => !(ScreenSizeStatus == "FullScreen".Localize() || ScreenSizeStatus == "Default".Localize()); - } public class App : JSON @@ -168,11 +166,9 @@ public class App : JSON public bool AutoClose { get; set; } public bool HideOnLaunch { get; set; } public bool WindowsHello { get; set; } - } public class Updates : JSON { - public bool CheckAtStartup { get; set; } = true; public bool AutoDownload { get; set; } public bool IncludePreReleases { get; set; } @@ -297,7 +293,6 @@ public class Store : JSON public partial class StoreSortOptions : JSON { - [ObservableProperty] private bool _Relevance = true; diff --git a/Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs b/Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs index 4e62fd6e..d47d9054 100644 --- a/Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs +++ b/Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs @@ -1,4 +1,4 @@ -using Emerald.WinUI.Helpers.Settings.JSON; +using Emerald.WinUI.Helpers.Settings.JSON; using System.Text.Json; using System; using System.Collections.Generic; @@ -19,7 +19,6 @@ public static T GetSerializedFromSettings(string key, T def) string json; try { - json = ApplicationData.Current.RoamingSettings.Values[key] as string; return JsonSerializer.Deserialize(json); } diff --git a/Emerald.App/Emerald.App/Helpers/Updater/Updater.cs b/Emerald.App/Emerald.App/Helpers/Updater/Updater.cs index 02181bfe..fc74e220 100644 --- a/Emerald.App/Emerald.App/Helpers/Updater/Updater.cs +++ b/Emerald.App/Emerald.App/Helpers/Updater/Updater.cs @@ -93,7 +93,6 @@ public async void CheckForUpdates(bool OnlyInformifHigherAvailable = false) var msg = await MessageBox.Show("UpdateAvailable".Localize(), "## Version: " + ver.ToString() + "\n\n###ReleaseNotes".Localize() + "\n\n " + rel.Body,Enums.MessageBoxButtons.CustomWithCancel, "UpdateNow".Localize()); if(msg == Enums.MessageBoxResults.Cancel) goto Return; - } else if(ver < currentver) { @@ -104,8 +103,6 @@ public async void CheckForUpdates(bool OnlyInformifHigherAvailable = false) var msg = await MessageBox.Show("DowngradeAvailable".Localize(), "DowngradeDescription".Localize(),Enums.MessageBoxButtons.Ok); goto Return; - - } else if(ver == currentver) { diff --git a/Emerald.App/Emerald.App/Helpers/WindowManager.cs b/Emerald.App/Emerald.App/Helpers/WindowManager.cs index 52cbc0ef..0519e1e3 100644 --- a/Emerald.App/Emerald.App/Helpers/WindowManager.cs +++ b/Emerald.App/Emerald.App/Helpers/WindowManager.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.WinUI.Helpers; +using CommunityToolkit.WinUI.Helpers; using Microsoft.UI; using Microsoft.UI.Composition; using Microsoft.UI.Composition.SystemBackdrops; @@ -48,7 +48,6 @@ public static MicaBackground IntializeWindow(Window window) /// public static void SetTitleBar(Window window, UIElement AppTitleBar) { - FrameworkElement RootUI = (FrameworkElement)window.Content; if (AppWindowTitleBar.IsCustomizationSupported()) { @@ -168,7 +167,6 @@ private void MicaBackground_ActualThemeChanged(FrameworkElement sender, object a { SetConfigurationSourceTheme(); } - } private void SetConfigurationSourceTheme() diff --git a/Emerald.App/Emerald.App/MainWindow.xaml.cs b/Emerald.App/Emerald.App/MainWindow.xaml.cs index 7147aef9..080ee662 100644 --- a/Emerald.App/Emerald.App/MainWindow.xaml.cs +++ b/Emerald.App/Emerald.App/MainWindow.xaml.cs @@ -1,4 +1,4 @@ -using Emerald.Core; +using Emerald.Core; using Emerald.Core.Tasks; using Emerald.WinUI.Helpers; using Emerald.WinUI.Helpers.Settings.JSON; @@ -87,7 +87,6 @@ public async void Initialize(object s, RoutedEventArgs e) if (BackupState.WantBackup) { - var r = await MessageBox.Show( Localized.Error.Localize(), Localized.LoadSettingsFailed.Localize(), @@ -156,7 +155,6 @@ void Tasks() TaskView.ChangeDescription(e.ID, string.Join(" ", (e.Message ?? "").Split(" ").Select(s => s.Localize()))); TaskView.ChangeSeverty(e.ID, e.Success ? InfoBarSeverity.Success : InfoBarSeverity.Error); ShowMiniTask(c, string.Join(" ", (e.Message ?? "").Split(" ").Select(s => s.Localize())), e.Success ? InfoBarSeverity.Success : InfoBarSeverity.Error); - }; } diff --git a/Emerald.App/Emerald.App/Models/Account.cs b/Emerald.App/Emerald.App/Models/Account.cs index 9c09afdb..5efae4e5 100644 --- a/Emerald.App/Emerald.App/Models/Account.cs +++ b/Emerald.App/Emerald.App/Models/Account.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; using Emerald.Core; using Emerald.WinUI.Enums; using Emerald.WinUI.Helpers; @@ -7,7 +7,6 @@ namespace Emerald.WinUI.Models { public partial class Account : Model { - [ObservableProperty] private string _UserName; diff --git a/Emerald.App/Emerald.App/Models/NavViewHeader.cs b/Emerald.App/Emerald.App/Models/NavViewHeader.cs index e725700e..a2fdde70 100644 --- a/Emerald.App/Emerald.App/Models/NavViewHeader.cs +++ b/Emerald.App/Emerald.App/Models/NavViewHeader.cs @@ -1,11 +1,10 @@ -using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.UI.Xaml; namespace Emerald.WinUI.Models { public partial class NavViewHeader : Model { - [ObservableProperty] private string _HeaderText; diff --git a/Emerald.App/Emerald.App/UserControls/AdaptiveItemPane.xaml.cs b/Emerald.App/Emerald.App/UserControls/AdaptiveItemPane.xaml.cs index 84ef0769..8aa58e65 100644 --- a/Emerald.App/Emerald.App/UserControls/AdaptiveItemPane.xaml.cs +++ b/Emerald.App/Emerald.App/UserControls/AdaptiveItemPane.xaml.cs @@ -4,13 +4,11 @@ namespace Emerald.WinUI.UserControls { - /// /// A nice control from the RiseMP /// public sealed partial class AdaptiveItemPane : UserControl { - public static DependencyProperty LeftPaneProperty = DependencyProperty.Register("LeftPane", typeof(object), typeof(AdaptiveItemPane), new PropertyMetadata(null)); diff --git a/Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs b/Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs index 8933a8c1..2d219a94 100644 --- a/Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs +++ b/Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs @@ -64,7 +64,5 @@ public Visibility BorderVisibility // Using a DependencyProperty as the backing store for BorderVisibility. This enables animation, styling, binding, etc... public static readonly DependencyProperty BorderVisibilityProperty = DependencyProperty.Register("BorderVisibility", typeof(Visibility), typeof(ExpanderItem), new PropertyMetadata(null)); - - } } diff --git a/Emerald.App/Emerald.App/Views/Home/AccountsPage.xaml.cs b/Emerald.App/Emerald.App/Views/Home/AccountsPage.xaml.cs index e21a2308..84f7669c 100644 --- a/Emerald.App/Emerald.App/Views/Home/AccountsPage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Home/AccountsPage.xaml.cs @@ -1,4 +1,4 @@ -using CmlLib.Core.Auth; +using CmlLib.Core.Auth; using Emerald.Core; using Emerald.WinUI.Helpers; using Emerald.WinUI.Models; @@ -122,7 +122,6 @@ private void btnSelectAll_Click(object sender, RoutedEventArgs e) item.IsChecked = val; } UpdateAll(); - } private void RemoveSelected() => Accounts.Remove(x => x.IsChecked); @@ -161,7 +160,6 @@ private void CancelLogin_Click(object sender, RoutedEventArgs e) var a = (sender as Button).DataContext as Account; SetEditor(null); Accounts.Add(a); - } public void UpdateMainSource() => SS.Accounts = Accounts.Select(x => @@ -244,7 +242,6 @@ private async void mitMicrosoftAdd_Click(object sender, RoutedEventArgs e) } catch (Exception ex) { - Core.Tasks.TasksHelper.CompleteTask(taskID, false, ex.Message); } } diff --git a/Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs b/Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs index ab24c351..f2c077a4 100644 --- a/Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs @@ -1,4 +1,4 @@ -using CmlLib.Core; +using CmlLib.Core; using CmlLib.Core.Auth; using CmlLib.Core.Downloader; using CommunityToolkit.WinUI.Helpers; @@ -92,7 +92,6 @@ public async void Initialize() var r = await MessageBox.Show("Error".Localize(), "MCPathFailed".Localize().Replace("{Path}", SS.Settings.Minecraft.Path), MessageBoxButtons.CustomWithCancel, "Yes".Localize(), "SetDifMCPath".Localize()); if (r == MessageBoxResults.Cancel) Process.GetCurrentProcess().Kill(); // Application.Current.Exit() didn't kill the process - else if (r == MessageBoxResults.CustomResult2) { var fop = new FolderPicker @@ -106,7 +105,6 @@ public async void Initialize() SS.Settings.Minecraft.Path = f.Path; } } - } App.Current.Launcher.InitializeLauncher(new MinecraftPath(SS.Settings.Minecraft.Path)); @@ -152,7 +150,6 @@ public async void Initialize() if (SystemInformation.Instance.IsFirstRun) ShowTips(); - } public void ShowTips() @@ -262,7 +259,6 @@ void FindSubVers(MinecraftVersion ver) var found = splitText.All((key) => v.Version.ToLower().Contains(key)); if (found) suitableItems.Add(v); - } } @@ -463,7 +459,6 @@ private void AdaptiveItemPane_OnStretched(object sender, EventArgs e) s.Children.OfType().ToList().ForEach(x => x.HorizontalAlignment = HorizontalAlignment.Left); NewsButton.HorizontalContentAlignment = ChangelogsButton.HorizontalContentAlignment = HorizontalAlignment.Left; - } } } diff --git a/Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs b/Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs index 0bafae92..0298ea6f 100644 --- a/Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs @@ -27,7 +27,6 @@ public NewsPage() await Task.Delay(300); pnlEmpty.Visibility = App.Current.Launcher.News.Entries.Any() ? Visibility.Collapsed : Visibility.Visible; }; - } private void BackButton_Click(object sender, RoutedEventArgs e) => BackRequested?.Invoke(this, new EventArgs()); diff --git a/Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs b/Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs index 3632cc60..32cb10d4 100644 --- a/Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs @@ -1,4 +1,4 @@ -using CommunityToolkit.WinUI.UI.Controls; +using CommunityToolkit.WinUI.UI.Controls; using Emerald.Core; using Emerald.WinUI.Enums; using Emerald.WinUI.Helpers; @@ -102,7 +102,6 @@ private async void ToggleSwitch_Toggled(object sender, RoutedEventArgs e) { SS.Settings.App.WindowsHello = true; } - } private async void DeleteBackup_Click(object sender, RoutedEventArgs e) diff --git a/Emerald.App/Emerald.App/Views/Settings/AppearancePage.xaml.cs b/Emerald.App/Emerald.App/Views/Settings/AppearancePage.xaml.cs index b2d95df1..189fda80 100644 --- a/Emerald.App/Emerald.App/Views/Settings/AppearancePage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Settings/AppearancePage.xaml.cs @@ -1,4 +1,4 @@ -using Emerald.Core; +using Emerald.Core; using Emerald.WinUI.Helpers; using Microsoft.UI.Xaml.Controls; using System.Collections.ObjectModel; @@ -93,7 +93,6 @@ private void GVColorList_SelectionChanged(object sender, SelectionChangedEventAr private void CustomTintColor_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { - var c = SS.Settings.App.Appearance.CustomMicaTintColor; var cp = new ColorPicker() { diff --git a/Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml.cs b/Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml.cs index 1fe2010a..be703784 100644 --- a/Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml.cs +++ b/Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml.cs @@ -1,4 +1,4 @@ -using CmlLib.Core; +using CmlLib.Core; using Emerald.WinUI.Enums; using Emerald.WinUI.Helpers; using Microsoft.UI.Xaml; @@ -54,10 +54,8 @@ async void Try() Try(); else Start(); - } } - } Start(); } @@ -72,7 +70,5 @@ private void btnRamMinus_Click(object sender, RoutedEventArgs e) => private void btnAutoRAM_Click(object sender, RoutedEventArgs e) => SS.Settings.Minecraft.RAM = DirectResoucres.MaxRAM / 2; - - } } diff --git a/Emerald.Core/Launcher.cs b/Emerald.Core/Launcher.cs index 17ffd0d2..901af079 100644 --- a/Emerald.Core/Launcher.cs +++ b/Emerald.Core/Launcher.cs @@ -1,4 +1,4 @@ -using CmlLib.Core; +using CmlLib.Core; using CmlLib.Core.Downloader; using CmlLib.Core.Files; using CmlLib.Core.Installer.FabricMC; @@ -140,7 +140,7 @@ void ProgChange(object sender, System.ComponentModel.ProgressChangedEventArgs e) prog = e.ProgressPercentage; if (createTask) TasksHelper.EditProgressTask(id, prog, message: message); - }; + } void FileChange(DownloadFileChangedEventArgs e) { @@ -148,7 +148,7 @@ void FileChange(DownloadFileChangedEventArgs e) if (createTask) TasksHelper.EditProgressTask(id, prog, message: message); - }; + } try { diff --git a/Emerald.Core/News/JSON/Dimensions.cs b/Emerald.Core/News/JSON/Dimensions.cs index 7016bea8..54f415af 100644 --- a/Emerald.Core/News/JSON/Dimensions.cs +++ b/Emerald.Core/News/JSON/Dimensions.cs @@ -1,6 +1,5 @@ namespace Emerald.Core.News.JSON { - public class Dimensions { public int width { get; set; } diff --git a/Emerald.Core/News/JSON/Entry.cs b/Emerald.Core/News/JSON/Entry.cs index 908cf4ea..4abbe8df 100644 --- a/Emerald.Core/News/JSON/Entry.cs +++ b/Emerald.Core/News/JSON/Entry.cs @@ -2,7 +2,6 @@ namespace Emerald.Core.News.JSON { - public class Entry { [JsonPropertyName("title")] diff --git a/Emerald.Core/News/NewsHelper.cs b/Emerald.Core/News/NewsHelper.cs index dc90f61c..4965e924 100644 --- a/Emerald.Core/News/NewsHelper.cs +++ b/Emerald.Core/News/NewsHelper.cs @@ -1,4 +1,4 @@ -using System.Text.Json; +using System.Text.Json; using System.Collections.ObjectModel; using System.ComponentModel; @@ -84,7 +84,6 @@ public ObservableCollection Entries foreach (var item in AllEntries.Where(x => filter == null || filter.Contains(x.Category))) Entries.Add(item); - } catch { diff --git a/Emerald.Core/Optifine.cs b/Emerald.Core/Optifine.cs index 0cf9d52a..bc6b1147 100644 --- a/Emerald.Core/Optifine.cs +++ b/Emerald.Core/Optifine.cs @@ -1,4 +1,4 @@ -using CmlLib.Core; +using CmlLib.Core; using System.Text.Json; using ProjBobcat.Class.Helper; using ProjBobcat.Class.Model.Optifine; @@ -49,7 +49,7 @@ public async Task> GetOptifineVersions() javaResult.Add(java); } - if (!javaResult.Any()) + if (javaResult.Count == 0) return (false, "NoJRE"); ProgressChanged(this, 0); diff --git a/Emerald.Core/Store/Labrinth.cs b/Emerald.Core/Store/Labrinth.cs index 41ceff86..2b5dadd9 100644 --- a/Emerald.Core/Store/Labrinth.cs +++ b/Emerald.Core/Store/Labrinth.cs @@ -1,4 +1,4 @@ -using CmlLib.Core; +using CmlLib.Core; using Emerald.Core.Tasks; using System.Text.Json; using System.Collections.Specialized; @@ -34,7 +34,6 @@ private async Task Get(string code) return await response.Content.ReadAsStringAsync(); throw new Exception("Failed to GET: \"" + code + "\", StatusCode: " + response.StatusCode.ToString()); - } private int DownloadTaskID; @@ -75,7 +74,7 @@ private async void ModrinthDownload(string link, string folderdir, string fileNa { int taskID = name == "" ? Tasks.TasksHelper.AddTask(Localized.GettingMods) : TasksHelper.AddTask(Localized.SearchStore, name); - string categouriesString = (categories != null && categories.Any() && categories.Length != 15) ? $"[\"categories:{string.Join("\"],[\"categories:", categories)}\"],".ToLower() : ""; + string categouriesString = (categories != null && categories.Length != 0 && categories.Length != 15) ? $"[\"categories:{string.Join("\"],[\"categories:", categories)}\"],".ToLower() : ""; Results.SearchResult s; @@ -163,15 +162,12 @@ public enum SearchCategories Technology, Utility, Worldgen - } } namespace Emerald.Core.Store.Results { - public class File { - [JsonPropertyName("hashes")] public Hashes Hashes { get; set; } @@ -244,7 +240,6 @@ public class Version : INotifyPropertyChanged public class Hashes { - [JsonPropertyName("sha512")] public string Sha512 { get; set; } @@ -254,7 +249,6 @@ public class Hashes public class SearchResult { - [JsonPropertyName("hits")] public Hit[] Hits { get; set; } @@ -270,7 +264,6 @@ public class SearchResult public class Hit { - [JsonPropertyName("slug")] public string Slug { get; set; } @@ -421,7 +414,6 @@ public class License public class Donation_Urls { - [JsonPropertyName("id")] public string ID { get; set; } diff --git a/Emerald.Core/Util.cs b/Emerald.Core/Util.cs index 6c459be6..56b7c2bc 100644 --- a/Emerald.Core/Util.cs +++ b/Emerald.Core/Util.cs @@ -1,4 +1,4 @@ -namespace Emerald.Core +namespace Emerald.Core { public static class Util { @@ -91,7 +91,7 @@ private async Task ProcessContentStream(long? totalDownloadSize, Stream contentS using var fileStream = new FileStream(_destinationFilePath, FileMode.Create, FileAccess.Write, FileShare.None, 8192, true); do { - var bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length); + var bytesRead = await contentStream.ReadAsync(buffer); if (bytesRead == 0) { isMoreToRead = false;