Skip to content

Commit

Permalink
[CodeFactor] Apply fixes (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: codefactor-io <support@codefactor.io>
  • Loading branch information
codefactor-io[bot] and code-factor authored Sep 1, 2024
1 parent 2f8a808 commit a41cb82
Show file tree
Hide file tree
Showing 23 changed files with 24 additions and 73 deletions.
12 changes: 4 additions & 8 deletions Emerald.App/Emerald.App/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.ApplicationModel.Resources;
using System;
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions Emerald.App/Emerald.App/Helpers/Settings/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public class Account : JSON

public partial class Downloader : JSON
{

[ObservableProperty]
private bool _HashCheck;

Expand Down Expand Up @@ -154,7 +153,6 @@ public JVM()

[JsonIgnore]
public bool SetSize => !(ScreenSizeStatus == "FullScreen".Localize() || ScreenSizeStatus == "Default".Localize());

}

public class App : JSON
Expand All @@ -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; }
Expand Down Expand Up @@ -297,7 +293,6 @@ public class Store : JSON

public partial class StoreSortOptions : JSON
{

[ObservableProperty]
private bool _Relevance = true;

Expand Down
3 changes: 1 addition & 2 deletions Emerald.App/Emerald.App/Helpers/Settings/SettingsSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,7 +19,6 @@ public static T GetSerializedFromSettings<T>(string key, T def)
string json;
try
{

json = ApplicationData.Current.RoamingSettings.Values[key] as string;
return JsonSerializer.Deserialize<T>(json);
}
Expand Down
3 changes: 0 additions & 3 deletions Emerald.App/Emerald.App/Helpers/Updater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
4 changes: 1 addition & 3 deletions Emerald.App/Emerald.App/Helpers/WindowManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommunityToolkit.WinUI.Helpers;
using CommunityToolkit.WinUI.Helpers;
using Microsoft.UI;
using Microsoft.UI.Composition;
using Microsoft.UI.Composition.SystemBackdrops;
Expand Down Expand Up @@ -48,7 +48,6 @@ public static MicaBackground IntializeWindow(Window window)
/// <exception cref="NullReferenceException"/>
public static void SetTitleBar(Window window, UIElement AppTitleBar)
{

FrameworkElement RootUI = (FrameworkElement)window.Content;
if (AppWindowTitleBar.IsCustomizationSupported())
{
Expand Down Expand Up @@ -168,7 +167,6 @@ private void MicaBackground_ActualThemeChanged(FrameworkElement sender, object a
{
SetConfigurationSourceTheme();
}

}

private void SetConfigurationSourceTheme()
Expand Down
4 changes: 1 addition & 3 deletions Emerald.App/Emerald.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Emerald.Core;
using Emerald.Core;
using Emerald.Core.Tasks;
using Emerald.WinUI.Helpers;
using Emerald.WinUI.Helpers.Settings.JSON;
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
};
}

Expand Down
3 changes: 1 addition & 2 deletions Emerald.App/Emerald.App/Models/Account.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.ComponentModel;
using Emerald.Core;
using Emerald.WinUI.Enums;
using Emerald.WinUI.Helpers;
Expand All @@ -7,7 +7,6 @@ namespace Emerald.WinUI.Models
{
public partial class Account : Model
{

[ObservableProperty]
private string _UserName;

Expand Down
3 changes: 1 addition & 2 deletions Emerald.App/Emerald.App/Models/NavViewHeader.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 0 additions & 2 deletions Emerald.App/Emerald.App/UserControls/AdaptiveItemPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Emerald.WinUI.UserControls
{

/// <summary>
/// A nice control from the RiseMP
/// </summary>
public sealed partial class AdaptiveItemPane : UserControl
{

public static DependencyProperty LeftPaneProperty =
DependencyProperty.Register("LeftPane", typeof(object),
typeof(AdaptiveItemPane), new PropertyMetadata(null));
Expand Down
2 changes: 0 additions & 2 deletions Emerald.App/Emerald.App/UserControls/ExpanderItem.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));


}
}
5 changes: 1 addition & 4 deletions Emerald.App/Emerald.App/Views/Home/AccountsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CmlLib.Core.Auth;
using CmlLib.Core.Auth;
using Emerald.Core;
using Emerald.WinUI.Helpers;
using Emerald.WinUI.Models;
Expand Down Expand Up @@ -122,7 +122,6 @@ private void btnSelectAll_Click(object sender, RoutedEventArgs e)
item.IsChecked = val;
}
UpdateAll();

}
private void RemoveSelected() =>
Accounts.Remove(x => x.IsChecked);
Expand Down Expand Up @@ -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 =>
Expand Down Expand Up @@ -244,7 +242,6 @@ private async void mitMicrosoftAdd_Click(object sender, RoutedEventArgs e)
}
catch (Exception ex)
{

Core.Tasks.TasksHelper.CompleteTask(taskID, false, ex.Message);
}
}
Expand Down
7 changes: 1 addition & 6 deletions Emerald.App/Emerald.App/Views/Home/HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CmlLib.Core;
using CmlLib.Core;
using CmlLib.Core.Auth;
using CmlLib.Core.Downloader;
using CommunityToolkit.WinUI.Helpers;
Expand Down Expand Up @@ -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
Expand All @@ -106,7 +105,6 @@ public async void Initialize()
SS.Settings.Minecraft.Path = f.Path;
}
}

}
App.Current.Launcher.InitializeLauncher(new MinecraftPath(SS.Settings.Minecraft.Path));

Expand Down Expand Up @@ -152,7 +150,6 @@ public async void Initialize()

if (SystemInformation.Instance.IsFirstRun)
ShowTips();

}

public void ShowTips()
Expand Down Expand Up @@ -262,7 +259,6 @@ void FindSubVers(MinecraftVersion ver)
var found = splitText.All((key) => v.Version.ToLower().Contains(key));
if (found)
suitableItems.Add(v);

}
}

Expand Down Expand Up @@ -463,7 +459,6 @@ private void AdaptiveItemPane_OnStretched(object sender, EventArgs e)
s.Children.OfType<TextBlock>().ToList().ForEach(x => x.HorizontalAlignment = HorizontalAlignment.Left);

NewsButton.HorizontalContentAlignment = ChangelogsButton.HorizontalContentAlignment = HorizontalAlignment.Left;

}
}
}
1 change: 0 additions & 1 deletion Emerald.App/Emerald.App/Views/Home/NewsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions Emerald.App/Emerald.App/Views/Settings/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Emerald.Core;
using Emerald.Core;
using Emerald.WinUI.Helpers;
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 1 addition & 5 deletions Emerald.App/Emerald.App/Views/Settings/GeneralPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CmlLib.Core;
using CmlLib.Core;
using Emerald.WinUI.Enums;
using Emerald.WinUI.Helpers;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -54,10 +54,8 @@ async void Try()
Try();
else
Start();

}
}

}
Start();
}
Expand All @@ -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;


}
}
6 changes: 3 additions & 3 deletions Emerald.Core/Launcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CmlLib.Core;
using CmlLib.Core;
using CmlLib.Core.Downloader;
using CmlLib.Core.Files;
using CmlLib.Core.Installer.FabricMC;
Expand Down Expand Up @@ -140,15 +140,15 @@ void ProgChange(object sender, System.ComponentModel.ProgressChangedEventArgs e)
prog = e.ProgressPercentage;
if (createTask)
TasksHelper.EditProgressTask(id, prog, message: message);
};
}

void FileChange(DownloadFileChangedEventArgs e)
{
message = $"{e.FileKind} : {e.FileName} ({e.ProgressedFileCount}/{e.TotalFileCount})";

if (createTask)
TasksHelper.EditProgressTask(id, prog, message: message);
};
}

try
{
Expand Down
1 change: 0 additions & 1 deletion Emerald.Core/News/JSON/Dimensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Emerald.Core.News.JSON
{

public class Dimensions
{
public int width { get; set; }
Expand Down
1 change: 0 additions & 1 deletion Emerald.Core/News/JSON/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Emerald.Core.News.JSON
{

public class Entry
{
[JsonPropertyName("title")]
Expand Down
3 changes: 1 addition & 2 deletions Emerald.Core/News/NewsHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text.Json;
using System.Text.Json;
using System.Collections.ObjectModel;
using System.ComponentModel;

Expand Down Expand Up @@ -84,7 +84,6 @@ public ObservableCollection<JSON.Entry> Entries

foreach (var item in AllEntries.Where(x => filter == null || filter.Contains(x.Category)))
Entries.Add(item);

}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions Emerald.Core/Optifine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CmlLib.Core;
using CmlLib.Core;
using System.Text.Json;
using ProjBobcat.Class.Helper;
using ProjBobcat.Class.Model.Optifine;
Expand Down Expand Up @@ -49,7 +49,7 @@ public async Task<List<OptifineDownloadVersionModel>> GetOptifineVersions()
javaResult.Add(java);
}

if (!javaResult.Any())
if (javaResult.Count == 0)
return (false, "NoJRE");

ProgressChanged(this, 0);
Expand Down
Loading

0 comments on commit a41cb82

Please sign in to comment.