From ffcc7405a71d00c6a71175ab70dc224ea365f957 Mon Sep 17 00:00:00 2001 From: achiez Date: Mon, 3 Nov 2025 22:44:46 +0200 Subject: [PATCH] Refactor and enhance proxy and mafile handling - Introduced `Filename` property in `Mafile` for better file management. - Refactored `Storage` methods to support `Filename` and simplify `.mafile` handling. - Enhanced `ProxyManagerView` with new controls for protocol and credentials display. - Implemented `HintBox` control for displaying errors and tips in UI. - Updated `MainWindow` with improved UI elements and event handling. - Improved command execution checks in `MainVM` for better UX. - Added localization strings for new features like proxy display options. - General code cleanups and formatting improvements. --- src/NebulaAuth.LegacyConverter/Program.cs | 4 +- src/NebulaAuth/App.xaml | 1 + src/NebulaAuth/App.xaml.cs | 11 +- .../CodeProgressBar.cs | 2 +- src/NebulaAuth/Components/HintBox.xaml | 57 ++++++ src/NebulaAuth/Components/HintBox.xaml.cs | 98 ++++++++++ src/NebulaAuth/Converters/Converters.xaml | 1 + .../Converters/ProxyTextConverter.cs | 42 ++++- src/NebulaAuth/MainWindow.xaml | 131 ++++++++------ src/NebulaAuth/MainWindow.xaml.cs | 13 ++ src/NebulaAuth/Model/Entities/Mafile.cs | 3 +- src/NebulaAuth/Model/MaClient.cs | 24 ++- src/NebulaAuth/Model/NebulaSerializer.cs | 6 +- src/NebulaAuth/Model/ProxyStorage.cs | 2 +- src/NebulaAuth/Model/Settings.cs | 7 +- src/NebulaAuth/Model/Storage.cs | 76 +++----- src/NebulaAuth/NebulaAuth.csproj | 5 + src/NebulaAuth/NebulaAuth.csproj.DotSettings | 9 +- src/NebulaAuth/View/LinkerStepTemplates.xaml | 1 + src/NebulaAuth/View/LinkerView.xaml | 46 ++--- .../View/MafileMoverStepTemplates.xaml | 1 + src/NebulaAuth/View/MafileMoverView.xaml | 44 +---- src/NebulaAuth/View/ProxyManagerView.xaml | 127 +++++++++---- src/NebulaAuth/View/ProxyManagerView.xaml.cs | 13 +- src/NebulaAuth/View/SettingsView.xaml | 46 +++-- .../ViewModel/Linker/LinkAccountVM.cs | 168 +++++++++--------- .../ViewModel/MafileMover/MafileMoverVM.cs | 52 +++--- src/NebulaAuth/ViewModel/MainVM.cs | 42 ++--- src/NebulaAuth/ViewModel/MainVM_File.cs | 4 +- .../ViewModel/Other/ProxyManagerVM.cs | 54 ++++-- src/NebulaAuth/ViewModel/Other/SettingsVM.cs | 1 + src/NebulaAuth/localization.loc.json | 49 +++-- .../Api/Mobile/SteamAuthenticatorLinkerApi.cs | 8 +- .../Api/Mobile/SteamMobileApi.cs | 4 +- .../Api/Mobile/SteamMobileConfirmationsApi.cs | 4 +- .../Api/Services/AuthenticationServiceApi.cs | 6 +- src/SteamLibForked/Api/SteamGlobalApi.cs | 6 +- .../Authentication/AdmissionHelper.cs | 8 +- .../Authentication/AuthHelper.cs | 4 +- .../Authentication/SteamTokenHelper.cs | 8 +- .../Core/StatusCodes/SteamStatusCode.cs | 2 +- src/SteamLibForked/Core/SteamDomains.cs | 4 +- .../Core/SteamLibErrorMonitor.cs | 6 +- .../Helpers/DeviceDetailsDefaultBuilder.cs | 4 +- .../Models/Core/Session/MobileSessionData.cs | 8 +- .../Models/Core/Session/SessionData.cs | 6 +- src/SteamLibForked/Models/Core/SteamId.cs | 2 +- .../Models/Core/SteamIds/SteamId3.cs | 2 +- .../Models/Core/SteamIds/SteamId64.cs | 12 +- src/SteamLibForked/ProtoCore/ProtoHelpers.cs | 6 +- src/SteamLibForked/ProtoCore/ProtoResponse.cs | 6 +- .../Services/AuthenticationService.cs | 10 +- .../SteamLibForked.csproj.DotSettings | 15 +- .../SteamAuthenticatorLinker.cs | 6 +- .../SteamMobile/SteamGuardCodeGenerator.cs | 12 +- src/SteamLibForked/SteamMobile/TimeAligner.cs | 8 +- .../Utility/EncryptionHelper.cs | 2 +- .../DeserializedMafileData.cs | 12 +- .../MafileSerialization/MafileSerializer.cs | 2 +- .../MafileSerializer_SessionData.cs | 10 +- .../MafileSerializer_Utility.cs | 10 +- .../MafileSerializer_Validate.cs | 4 +- src/SteamLibForked/Utility/SteamIdParser.cs | 4 +- src/SteamLibForked/Web/ClientBuilder.cs | 6 +- .../Web/Converters/SteamIdConverters.cs | 12 +- .../Scrappers/HTML/ScriptHeaderScrapper.cs | 10 +- .../JSON/MobileConfirmationScrapper.cs | 2 +- 67 files changed, 815 insertions(+), 556 deletions(-) rename src/NebulaAuth/{Theme/Controls => Components}/CodeProgressBar.cs (97%) create mode 100644 src/NebulaAuth/Components/HintBox.xaml create mode 100644 src/NebulaAuth/Components/HintBox.xaml.cs diff --git a/src/NebulaAuth.LegacyConverter/Program.cs b/src/NebulaAuth.LegacyConverter/Program.cs index 64f48a5..5bd88be 100644 --- a/src/NebulaAuth.LegacyConverter/Program.cs +++ b/src/NebulaAuth.LegacyConverter/Program.cs @@ -1,8 +1,8 @@ -using System.Reflection; -using AchiesUtilities.Extensions; +using AchiesUtilities.Extensions; using NebulaAuth.LegacyConverter; using Newtonsoft.Json; using SteamLib.Utility.MafileSerialization; +using System.Reflection; try { diff --git a/src/NebulaAuth/App.xaml b/src/NebulaAuth/App.xaml index f33b575..f8140d2 100644 --- a/src/NebulaAuth/App.xaml +++ b/src/NebulaAuth/App.xaml @@ -33,6 +33,7 @@ + diff --git a/src/NebulaAuth/App.xaml.cs b/src/NebulaAuth/App.xaml.cs index 53c3e81..d91f119 100644 --- a/src/NebulaAuth/App.xaml.cs +++ b/src/NebulaAuth/App.xaml.cs @@ -1,8 +1,5 @@ using System; -using System.IO; -using System.Linq; using System.Windows; -using AchiesUtilities.Extensions; using NebulaAuth.Core; using NebulaAuth.Model; using NebulaAuth.Model.Exceptions; @@ -21,13 +18,7 @@ public partial class App LocManager.Init(); LocManager.SetApplicationLocalization(Settings.Instance.Language); Shell.Initialize(); - - var files = 0; - if (Directory.Exists(Storage.MAFILE_F)) - files = Directory.GetFiles(Storage.MafileFolder) - .Count(f => Path.GetExtension(f).EqualsIgnoreCase(".mafile")); - - var threads = files > 0 ? files / 100 + 1 : 1; + var threads = Environment.ProcessorCount > 0 ? Environment.ProcessorCount : 1; await Storage.Initialize(threads); var mainWindow = new MainWindow(); Current.MainWindow = mainWindow; diff --git a/src/NebulaAuth/Theme/Controls/CodeProgressBar.cs b/src/NebulaAuth/Components/CodeProgressBar.cs similarity index 97% rename from src/NebulaAuth/Theme/Controls/CodeProgressBar.cs rename to src/NebulaAuth/Components/CodeProgressBar.cs index 4f55936..8171e7b 100644 --- a/src/NebulaAuth/Theme/Controls/CodeProgressBar.cs +++ b/src/NebulaAuth/Components/CodeProgressBar.cs @@ -3,7 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; -namespace NebulaAuth.Theme.Controls; +namespace NebulaAuth; public class CodeProgressBar : ProgressBar { diff --git a/src/NebulaAuth/Components/HintBox.xaml b/src/NebulaAuth/Components/HintBox.xaml new file mode 100644 index 0000000..fdf57e9 --- /dev/null +++ b/src/NebulaAuth/Components/HintBox.xaml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/NebulaAuth/Components/HintBox.xaml.cs b/src/NebulaAuth/Components/HintBox.xaml.cs new file mode 100644 index 0000000..38d84d1 --- /dev/null +++ b/src/NebulaAuth/Components/HintBox.xaml.cs @@ -0,0 +1,98 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using CommunityToolkit.Mvvm.Input; +using MaterialDesignThemes.Wpf; + +namespace NebulaAuth; + +public partial class HintBox : UserControl +{ + public static readonly DependencyProperty TextProperty = + DependencyProperty.Register(nameof(Text), typeof(string), typeof(HintBox)); + + public static readonly DependencyProperty SeverityProperty = + DependencyProperty.Register(nameof(Severity), typeof(HintBoxSeverity), typeof(HintBox), + new PropertyMetadata(HintBoxSeverity.Info, OnSeverityChanged)); + + public static readonly DependencyProperty ShowCloseButtonProperty = + DependencyProperty.Register(nameof(ShowCloseButton), typeof(bool), typeof(HintBox), + new PropertyMetadata(false)); + + + public static readonly DependencyProperty CloseCommandProperty = + DependencyProperty.Register(nameof(CloseCommand), typeof(ICommand), typeof(HintBox), + new PropertyMetadata(null)); + + public string Text + { + get => (string) GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public HintBoxSeverity Severity + { + get => (HintBoxSeverity) GetValue(SeverityProperty); + set => SetValue(SeverityProperty, value); + } + + public ICommand CloseCommand + { + get => (ICommand) GetValue(CloseCommandProperty) ?? InternalCloseCommand; + set => SetValue(CloseCommandProperty, value); + } + + public bool ShowCloseButton + { + get => (bool) GetValue(ShowCloseButtonProperty); + set => SetValue(ShowCloseButtonProperty, value); + } + + private ICommand InternalCloseCommand { get; } + + public PackIconKind IconKind { get; private set; } + public Brush IconBrush { get; private set; } + + public HintBox() + { + InitializeComponent(); + ApplySeverityVisuals(); + + InternalCloseCommand = new RelayCommand(Close); + } + + public event RoutedEventHandler Closed; + + private static void OnSeverityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((HintBox) d).ApplySeverityVisuals(); + } + + private void ApplySeverityVisuals() + { + switch (Severity) + { + case HintBoxSeverity.Error: + IconKind = PackIconKind.ErrorOutline; + IconBrush = (Brush) Application.Current.FindResource("ErrorBrush")!; + break; + default: + IconKind = PackIconKind.InfoCircleOutline; + IconBrush = (Brush) Application.Current.FindResource("InfoBrush")!; + break; + } + } + + private void Close() + { + Visibility = Visibility.Collapsed; + Closed?.Invoke(this, new RoutedEventArgs()); + } +} + +public enum HintBoxSeverity +{ + Info, + Error +} \ No newline at end of file diff --git a/src/NebulaAuth/Converters/Converters.xaml b/src/NebulaAuth/Converters/Converters.xaml index 5b35f4c..eb20e3f 100644 --- a/src/NebulaAuth/Converters/Converters.xaml +++ b/src/NebulaAuth/Converters/Converters.xaml @@ -8,6 +8,7 @@ + diff --git a/src/NebulaAuth/Converters/ProxyTextConverter.cs b/src/NebulaAuth/Converters/ProxyTextConverter.cs index 2dab8f2..36aea4f 100644 --- a/src/NebulaAuth/Converters/ProxyTextConverter.cs +++ b/src/NebulaAuth/Converters/ProxyTextConverter.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Text; using System.Windows.Data; using AchiesUtilities.Web.Proxy; using NebulaAuth.Model.Entities; @@ -33,11 +34,50 @@ public class ProxyDataTextConverter : IValueConverter return string.Empty; } - return $"{p.Address}:{p.Port}"; + return $"{p.Protocol.ToString().ToLowerInvariant()}://{p.Address}:{p.Port}"; } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } +} + +public class ProxyDataTextMultiConverter : IMultiValueConverter +{ + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + var value = values[0] as ProxyData; + var displayProtocol = values.Length > 1 && values[1] is bool dp && dp; + var displayCredentials = values.Length > 2 && values[2] is bool dc && dc; + if (value == null) + { + return string.Empty; + } + + var sb = new StringBuilder(); + if (displayProtocol) + { + sb.Append(value.Protocol.ToString().ToLowerInvariant()); + sb.Append("://"); + } + + sb.Append(value.Address); + sb.Append(':'); + sb.Append(value.Port); + if (displayCredentials && value.AuthEnabled) + { + sb.Append(':'); + sb.Append(value.Username); + sb.Append(':'); + sb.Append(value.Password); + } + + return sb.ToString(); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/NebulaAuth/MainWindow.xaml b/src/NebulaAuth/MainWindow.xaml index 6540f4c..5bd6b88 100644 --- a/src/NebulaAuth/MainWindow.xaml +++ b/src/NebulaAuth/MainWindow.xaml @@ -8,7 +8,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:entities="clr-namespace:NebulaAuth.Model.Entities" xmlns:viewModel="clr-namespace:NebulaAuth.ViewModel" - xmlns:controls="clr-namespace:NebulaAuth.Theme.Controls" + xmlns:nebulaAuth="clr-namespace:NebulaAuth" WindowStartupLocation="CenterScreen" MinHeight="500" MinWidth="500" Title="NebulaAuth" Height="800" Width="730" @@ -73,8 +73,7 @@ - @@ -93,11 +92,9 @@ Command="{Binding RemoveAuthenticatorCommand}" /> - - @@ -254,8 +251,11 @@ Text="{Tr MainWindow.LeftPart.NoMafiles}" /> + SelectedValue="{Binding SelectedMafile}" + PreviewMouseDown="MafileListBox_OnPreviewMouseDown">