From 1cecbd4f1a79b9ecce0376b50de4552f16cb7266 Mon Sep 17 00:00:00 2001 From: Nemesh Date: Thu, 20 Oct 2022 23:14:09 +0300 Subject: [PATCH 01/11] Copy button rewrite - moved copy method from being created for every skin to being in viewmodel - clicking copy button highlights corresponding field --- FloatTool/Common/Skin.cs | 11 ------- FloatTool/ViewModels/MainViewModel.cs | 15 ++++++++++ FloatTool/Views/MainWindow.xaml | 42 +++++++++++++-------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/FloatTool/Common/Skin.cs b/FloatTool/Common/Skin.cs index 9af34d9..c07266b 100644 --- a/FloatTool/Common/Skin.cs +++ b/FloatTool/Common/Skin.cs @@ -16,8 +16,6 @@ */ using System.Collections.Generic; -using System.Globalization; -using System.Windows; namespace FloatTool { @@ -144,15 +142,6 @@ public sealed class InputSkin public float Price; public Currency SkinCurrency; - private RelayCommand copyCommand; - public RelayCommand CopyCommand - { - get - { - return copyCommand ??= new RelayCommand(obj => Clipboard.SetText(WearValue.ToString("0.00000000000000", CultureInfo.InvariantCulture))); - } - } - public double GetWearValue => WearValue; public InputSkin(double wear, float price, Currency currency) diff --git a/FloatTool/ViewModels/MainViewModel.cs b/FloatTool/ViewModels/MainViewModel.cs index 66f1e27..a472588 100644 --- a/FloatTool/ViewModels/MainViewModel.cs +++ b/FloatTool/ViewModels/MainViewModel.cs @@ -315,6 +315,21 @@ public float ProgressPercentage public long ParsedCombinations { get; internal set; } public long TotalCombinations { get; internal set; } + private RelayCommand copyCommand; + public RelayCommand CopyCommand + { + get + { + return copyCommand ??= new RelayCommand(field => + { + var textbox = field as TextBox; + Clipboard.SetText(textbox.Text); + textbox?.Focus(); + textbox?.SelectAll(); + }); + } + } + #endregion private void UpdateFullSkinName() diff --git a/FloatTool/Views/MainWindow.xaml b/FloatTool/Views/MainWindow.xaml index 3007ff3..faa37e5 100644 --- a/FloatTool/Views/MainWindow.xaml +++ b/FloatTool/Views/MainWindow.xaml @@ -24,7 +24,7 @@ xmlns:theme="clr-namespace:FloatTool.Theme" mc:Ignorable="d" KeyUp="Window_KeyUp" MinWidth="875" MinHeight="420" - Width="875" Height="420" + Width="875" Height="420" x:Name="mainWindow" WindowStartupLocation="CenterScreen" WindowStyle="None" AllowsTransparency="True" Background="Transparent" Title="FloatTool"> @@ -337,8 +337,8 @@ - - @@ -347,8 +347,8 @@ - - @@ -357,8 +357,8 @@ - - @@ -367,8 +367,8 @@ - - @@ -377,8 +377,8 @@ - - @@ -387,8 +387,8 @@ - - @@ -397,8 +397,8 @@ - - @@ -407,8 +407,8 @@ - - @@ -417,8 +417,8 @@ - - @@ -427,8 +427,8 @@ - - From 9009b998b41085add91e8b90d4c279ee7b6eec1f Mon Sep 17 00:00:00 2001 From: Nemesh Date: Thu, 20 Oct 2022 23:36:02 +0300 Subject: [PATCH 02/11] Fixed benchmark upload exploit - fixed a way to set different amount of threads before uploading result to server --- FloatTool/ViewModels/BenchmarkViewModel.cs | 3 ++- FloatTool/Views/BenchmarkWindow.xaml.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/FloatTool/ViewModels/BenchmarkViewModel.cs b/FloatTool/ViewModels/BenchmarkViewModel.cs index c3b546b..62fa1de 100644 --- a/FloatTool/ViewModels/BenchmarkViewModel.cs +++ b/FloatTool/ViewModels/BenchmarkViewModel.cs @@ -51,6 +51,7 @@ public sealed class BenchmarkResult private bool showOnlyCurrent = false; private int multithreadedSpeed = 0; private int threadCount = Environment.ProcessorCount; + public int ThreadCountTested = 0; private int singlethreadedSpeed = 0; private bool isUpdatingEnabled; @@ -225,7 +226,7 @@ public async void PushBenchmarkResults() using var client = new HttpClient(); var version = Assembly.GetExecutingAssembly().GetName().Version; client.DefaultRequestHeaders.Add("User-Agent", $"FloatTool/{AppHelpers.VersionCode}"); - string paramedURL = $"/submit?cpu={CurrentCpuName}&threads={ThreadCount}&multicore={MultithreadedSpeed}&singlecore={SinglethreadedSpeed}"; + string paramedURL = $"/submit?cpu={CurrentCpuName}&threads={ThreadCountTested}&multicore={MultithreadedSpeed}&singlecore={SinglethreadedSpeed}"; HttpResponseMessage response = await client.GetAsync(Utils.API_URL + paramedURL); response.EnsureSuccessStatusCode(); string responseBody = await response.Content.ReadAsStringAsync(); diff --git a/FloatTool/Views/BenchmarkWindow.xaml.cs b/FloatTool/Views/BenchmarkWindow.xaml.cs index 47d4f81..87cf9a8 100644 --- a/FloatTool/Views/BenchmarkWindow.xaml.cs +++ b/FloatTool/Views/BenchmarkWindow.xaml.cs @@ -171,6 +171,7 @@ private void StartBenchmark_Click(object sender, RoutedEventArgs e) Context.MultithreadedSpeed = 0; Context.SinglethreadedSpeed = 0; Context.ProgressPercentage = 0; + Context.ThreadCountTested = Context.ThreadCount; string searchFilter = "0.250000000"; From f4dd9bb99ccccb4d2ddfdc57f853380047e70903 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:56:36 +0000 Subject: [PATCH 03/11] Bump DiscordRichPresence from 1.0.175 to 1.1.3.18 Bumps [DiscordRichPresence](https://github.com/Lachee/discord-rpc-csharp) from 1.0.175 to 1.1.3.18. - [Release notes](https://github.com/Lachee/discord-rpc-csharp/releases) - [Commits](https://github.com/Lachee/discord-rpc-csharp/commits) --- updated-dependencies: - dependency-name: DiscordRichPresence dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- FloatTool/FloatTool.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FloatTool/FloatTool.csproj b/FloatTool/FloatTool.csproj index 7c7dea0..9914847 100644 --- a/FloatTool/FloatTool.csproj +++ b/FloatTool/FloatTool.csproj @@ -39,7 +39,7 @@ - + From 1607d4b108ba59a4ac290bc1bde821ee793ea6fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Dec 2022 12:53:49 +0000 Subject: [PATCH 04/11] Bump Newtonsoft.Json from 13.0.1 to 13.0.2 Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- FloatTool/FloatTool.csproj | 2 +- ItemsParser/ItemsParser.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FloatTool/FloatTool.csproj b/FloatTool/FloatTool.csproj index 9914847..d01a957 100644 --- a/FloatTool/FloatTool.csproj +++ b/FloatTool/FloatTool.csproj @@ -42,7 +42,7 @@ - + diff --git a/ItemsParser/ItemsParser.csproj b/ItemsParser/ItemsParser.csproj index bc4b6b3..b4353ab 100644 --- a/ItemsParser/ItemsParser.csproj +++ b/ItemsParser/ItemsParser.csproj @@ -9,7 +9,7 @@ - + From 05ac95466777fa239b16e6fd0df94b17230bdf2e Mon Sep 17 00:00:00 2001 From: Nemesh Date: Tue, 13 Dec 2022 12:36:02 +0200 Subject: [PATCH 05/11] Better Stopwatch usage Now Stopwatch doesn't use heap allocations which should give a tiny speed boost --- FloatTool/Common/Utils.cs | 21 +++++++++++++++++++++ FloatTool/Views/BenchmarkWindow.xaml.cs | 12 ++++++------ FloatTool/Views/MainWindow.xaml.cs | 7 ++++--- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/FloatTool/Common/Utils.cs b/FloatTool/Common/Utils.cs index 9a0d41c..4386565 100644 --- a/FloatTool/Common/Utils.cs +++ b/FloatTool/Common/Utils.cs @@ -19,9 +19,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Http; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -179,6 +181,25 @@ public static void Sort(this ObservableCollection collection, Comparison threadPool = new(); int threads = Context.ThreadCount; - Stopwatch timer = Stopwatch.StartNew(); + long startTime = Stopwatch.GetTimestamp(); try { for (int i = 0; i < threads; i++) { - var startIndex = i; - var newThread = Task.Factory.StartNew(() => FloatCraftWorkerThread( + int startIndex = i; + Task newThread = Task.Factory.StartNew(() => FloatCraftWorkerThread( new CraftSearchSetup { SkinPool = inputSkins, @@ -230,9 +230,9 @@ private void StartBenchmark_Click(object sender, RoutedEventArgs e) Thread.Sleep(5); } - timer.Stop(); - - float speed = PassedCombinations * 1000 / timer.ElapsedMilliseconds; + long endTime = Stopwatch.GetTimestamp(); + double millis = Utils.GetTimePassed(startTime, endTime).TotalMilliseconds; + double speed = PassedCombinations * 1000 / millis; Context.MultithreadedSpeed = (int)speed; Context.SinglethreadedSpeed = (int)(speed / threads); diff --git a/FloatTool/Views/MainWindow.xaml.cs b/FloatTool/Views/MainWindow.xaml.cs index 5809eba..42ca7d1 100644 --- a/FloatTool/Views/MainWindow.xaml.cs +++ b/FloatTool/Views/MainWindow.xaml.cs @@ -465,13 +465,14 @@ private void StartSearchButton_Click(object sender, RoutedEventArgs e) } SetStatus("m_Searching"); - Stopwatch timer = Stopwatch.StartNew(); + var startTime = Stopwatch.GetTimestamp(); long LastCombinationCount = 0; while (true) { - long timeSinceLast = timer.ElapsedMilliseconds; - timer.Restart(); + long newTime = Stopwatch.GetTimestamp(); + double timeSinceLast = Utils.GetTimePassed(startTime, newTime).TotalMilliseconds; + startTime = newTime; bool isAnyRunning = false; foreach (Task t in CollectionsMarshal.AsSpan(ThreadPool)) From 5836ddbd45b172d030e73bcee34fd81d5a2e4b9f Mon Sep 17 00:00:00 2001 From: Nemesh Date: Tue, 13 Dec 2022 12:43:20 +0200 Subject: [PATCH 06/11] Simplify getting performance frequency --- FloatTool/Common/Utils.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/FloatTool/Common/Utils.cs b/FloatTool/Common/Utils.cs index 4386565..c7a654c 100644 --- a/FloatTool/Common/Utils.cs +++ b/FloatTool/Common/Utils.cs @@ -184,12 +184,8 @@ public static void Sort(this ObservableCollection collection, Comparison Date: Thu, 19 Jan 2023 23:52:59 +0200 Subject: [PATCH 07/11] Settings now use JSON file instead of registry + Also added advanced settings: * API selector to choose from two different methods of getting floats * Format selector to correctly format floats for selected extension --- FloatTool/App.xaml.cs | 61 ++++++----- FloatTool/AppHelpers.cs | 2 + FloatTool/Common/Logger.cs | 6 + FloatTool/Common/Settings.cs | 121 ++++++++++++++++----- FloatTool/Common/Utils.cs | 16 ++- FloatTool/Languages/Lang.xaml | 3 + FloatTool/ViewModels/BenchmarkViewModel.cs | 14 +-- FloatTool/ViewModels/MainViewModel.cs | 10 +- FloatTool/ViewModels/SettingsViewModel.cs | 87 ++++++++++++--- FloatTool/Views/BenchmarkWindow.xaml.cs | 7 +- FloatTool/Views/MainWindow.xaml | 21 ++-- FloatTool/Views/MainWindow.xaml.cs | 31 +++--- FloatTool/Views/SettingsWindow.xaml | 75 +++++++++---- FloatTool/Views/SettingsWindow.xaml.cs | 16 +-- FloatTool/Views/UpdateWindow.xaml.cs | 8 +- 15 files changed, 313 insertions(+), 165 deletions(-) diff --git a/FloatTool/App.xaml.cs b/FloatTool/App.xaml.cs index 0a8530d..bd1d346 100644 --- a/FloatTool/App.xaml.cs +++ b/FloatTool/App.xaml.cs @@ -18,7 +18,6 @@ using DiscordRPC; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -76,8 +75,7 @@ public static void SelectTheme(string themeURI) return; // Preload - if (ThemeDictionary is null) - ThemeDictionary = (ResourceDictionary)LoadComponent(new Uri("/Theme/Schemes/Dark.xaml", UriKind.Relative)); + ThemeDictionary ??= (ResourceDictionary)LoadComponent(new Uri("/Theme/Schemes/Dark.xaml", UriKind.Relative)); if (themeURI.StartsWith("/Theme/Schemes")) ThemeDictionary.Source = new Uri(themeURI, UriKind.Relative); @@ -101,7 +99,6 @@ public App() AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Log.Error("Unhandled exception", (Exception)e.ExceptionObject); - DispatcherUnhandledException += (s, e) => { Logger.Log.Error("Dispatcher Unhandled Exception", e.Exception); @@ -119,6 +116,8 @@ public App() var subfolder = "floattool"; var combined = Path.Combine(appdata, subfolder); + AppHelpers.AppDirectory = combined; + //Check if folder exists if (!Directory.Exists(combined)) Directory.CreateDirectory(combined); @@ -127,8 +126,7 @@ public App() var themesFolder = Path.Combine(combined, "themes"); if (!Directory.Exists(themesFolder)) Directory.CreateDirectory(themesFolder); - AppHelpers. - ThemesFound = new List + AppHelpers.ThemesFound = new List { "/Theme/Schemes/Dark.xaml", "/Theme/Schemes/Light.xaml" }; @@ -138,25 +136,21 @@ public App() foreach (FileInfo file in Files) AppHelpers.ThemesFound.Add(file.FullName); - AppHelpers. - Watcher = new FileSystemWatcher - { - Path = themesFolder, - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName - }; - AppHelpers. - - // Add event handlers. - Watcher.Changed += new FileSystemEventHandler(OnChanged); + AppHelpers.Watcher = new FileSystemWatcher + { + Path = themesFolder, + NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName + }; + AppHelpers.Watcher.Changed += new FileSystemEventHandler(OnChanged); AppHelpers.Watcher.Created += new FileSystemEventHandler(OnChanged); AppHelpers.Watcher.Deleted += new FileSystemEventHandler(OnChanged); AppHelpers.Watcher.Renamed += new RenamedEventHandler(OnRenamed); - AppHelpers. - Watcher.EnableRaisingEvents = true; - Trace.WriteLine("Started FileWatcher"); - AppHelpers. - DiscordClient = new DiscordRpcClient("734042978246721537"); + AppHelpers.Watcher.EnableRaisingEvents = true; + AppHelpers.DiscordClient = new DiscordRpcClient("734042978246721537"); AppHelpers.DiscordClient.Initialize(); + + AppHelpers.Settings = new Settings(); + AppHelpers.Settings.Load(); } public static void CleanOldFiles() @@ -195,8 +189,7 @@ public static bool IsFileLocked(string file) } finally { - if (stream != null) - stream.Close(); + stream?.Close(); } } return false; @@ -205,7 +198,6 @@ public static bool IsFileLocked(string file) // Define the event handlers. private void OnChanged(object source, FileSystemEventArgs e) { - Trace.WriteLine($"File: {e.FullPath} {e.ChangeType}"); switch (e.ChangeType) { case WatcherChangeTypes.Deleted: @@ -233,7 +225,6 @@ private void OnChanged(object source, FileSystemEventArgs e) private void OnRenamed(object source, RenamedEventArgs e) { - Trace.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}"); AppHelpers.ThemesFound[AppHelpers.ThemesFound.IndexOf(e.OldFullPath)] = e.FullPath; } } @@ -250,4 +241,24 @@ public object ConvertBack(object value, Type targetType, object param, CultureIn return (bool)value ? param : Binding.DoNothing; } } + + public sealed class DoublePrecisionConverter : IValueConverter + { + public object Convert(object value, Type targetType, object param, CultureInfo culture) + { + //Logger.Debug(AppHelpers.Settings.ToString()); + return AppHelpers.Settings.ExtensionType switch + { + ExtensionType.SteamInventoryHelper => string.Format(CultureInfo.InvariantCulture, "{0:R}", value), + _ => string.Format(CultureInfo.InvariantCulture, "{0:0.00000000000000}", value), + }; + } + + public object ConvertBack(object value, Type targetType, object param, CultureInfo culture) + { + return Binding.DoNothing; + } + } + + } diff --git a/FloatTool/AppHelpers.cs b/FloatTool/AppHelpers.cs index 91662d1..60a927a 100644 --- a/FloatTool/AppHelpers.cs +++ b/FloatTool/AppHelpers.cs @@ -26,6 +26,8 @@ internal static class AppHelpers public static FileSystemWatcher Watcher; public static DiscordRpcClient DiscordClient; public static string VersionCode; + public static string AppDirectory; + public static Settings Settings; public static List ThemesFound { get; set; } } } \ No newline at end of file diff --git a/FloatTool/Common/Logger.cs b/FloatTool/Common/Logger.cs index 6d78325..358bb45 100644 --- a/FloatTool/Common/Logger.cs +++ b/FloatTool/Common/Logger.cs @@ -58,5 +58,11 @@ public static void Initialize() hierarchy.Root.Level = Level.Info; hierarchy.Configured = true; } + + public static void Debug(object message) => Log.Debug(message); + public static void Info(object message) => Log.Info(message); + public static void Warn(object message) => Log.Warn(message); + public static void Error(object message) => Log.Error(message); + public static void Fatal(object message) => Log.Fatal(message); } } diff --git a/FloatTool/Common/Settings.cs b/FloatTool/Common/Settings.cs index 501b1e7..99a0968 100644 --- a/FloatTool/Common/Settings.cs +++ b/FloatTool/Common/Settings.cs @@ -16,6 +16,7 @@ */ using Microsoft.Win32; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; @@ -47,6 +48,19 @@ public enum Currency CRC = 40, UYU = 41, RMB = 9000, NXP = 9001 } + + // These are currently the same, but that can change later. + public enum FloatAPI + { + CSGOFloat, + SteamInventoryHelper + } + + public enum ExtensionType + { + CSGOFloat, + SteamInventoryHelper + } public static class CurrencyHelper { @@ -65,58 +79,110 @@ public static int GetIndexFromCurrency(Currency currency) public sealed class Settings { - public string LanguageCode { get; set; } + public string LanguageCode { get; set; } = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; public Currency Currency { get; set; } = Currency.USD; public string ThemeURI { get; set; } = "/Theme/Schemes/Dark.xaml"; public bool Sound { get; set; } = true; public bool CheckForUpdates { get; set; } = true; public bool DiscordRPC { get; set; } = true; public int ThreadCount { get; set; } = Environment.ProcessorCount; - public bool Migrated { get; set; } = false; + public FloatAPI FloatAPI { get; set; } = FloatAPI.CSGOFloat; + public ExtensionType ExtensionType { get; set; } = ExtensionType.CSGOFloat; - public void TryLoad() + public void Load() + { + try + { + string settingsPath = Path.Join(AppHelpers.AppDirectory, "settings.json"); + if (File.Exists(settingsPath)) + { + var settings = File.ReadAllText(settingsPath); + var tmpSettings = JsonConvert.DeserializeObject(settings); + LanguageCode = tmpSettings.LanguageCode; + Currency = tmpSettings.Currency; + ThemeURI = tmpSettings.ThemeURI; + Sound = tmpSettings.Sound; + CheckForUpdates = tmpSettings.CheckForUpdates; + DiscordRPC = tmpSettings.DiscordRPC; + ThreadCount = tmpSettings.ThreadCount; + FloatAPI = tmpSettings.FloatAPI; + ExtensionType = tmpSettings.ExtensionType; + } + else + { + LoadOld(); + Save(); + } + } + catch (Exception ex) + { + Logger.Log.Error("Error loading settings", ex); + } + } + + public void LoadOld() { // Load settings from registry const string userRoot = "HKEY_CURRENT_USER"; const string subkey = "Software\\FloatTool"; const string keyName = userRoot + "\\" + subkey; + try { - LanguageCode = (string)Registry.GetValue(keyName, "languageCode", Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName); - Currency = (Currency)Registry.GetValue(keyName, "currency", Currency.USD); - ThemeURI = (string)Registry.GetValue(keyName, "themeURI", "/Theme/Schemes/Dark.xaml"); - ThreadCount = (int)Registry.GetValue(keyName, "lastThreads", Environment.ProcessorCount); - Sound = (string)Registry.GetValue(keyName, "sound", "True") == "True"; - CheckForUpdates = (string)Registry.GetValue(keyName, "updateCheck", "True") == "True"; - DiscordRPC = (string)Registry.GetValue(keyName, "discordRPC", "True") == "True"; - Migrated = (string)Registry.GetValue(keyName, "migrated", "False") == "True"; + using var hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64); + var key = hkcu.OpenSubKey(@"SOFTWARE\FloatTool"); + + if (key == null) return; + + LanguageCode = (string)Registry.GetValue(keyName, "languageCode", LanguageCode); + Currency = (Currency)Registry.GetValue(keyName, "currency", Currency); + ThemeURI = (string)Registry.GetValue(keyName, "themeURI", ThemeURI); + ThreadCount = (int)Registry.GetValue(keyName, "lastThreads", ThreadCount); + Sound = (string)Registry.GetValue(keyName, "sound", Sound ? "True" : "False") == "True"; + CheckForUpdates = (string)Registry.GetValue(keyName, "updateCheck", CheckForUpdates ? "True" : "False") == "True"; + DiscordRPC = (string)Registry.GetValue(keyName, "discordRPC", DiscordRPC ? "True" : "False") == "True"; + + key.Close(); + Logger.Log.Info("Loaded settings from registry"); + + MigrateFromOldVersion(); } catch (Exception ex) { - Logger.Log.Error("Error loading settings", ex); + Logger.Log.Error("Error loading settings from registry", ex); } } public void Save() { - // Save settings to registry - const string userRoot = "HKEY_CURRENT_USER"; - const string subkey = "Software\\FloatTool"; - const string keyName = userRoot + "\\" + subkey; + try + { + if (!Directory.Exists(AppHelpers.AppDirectory)) + Directory.CreateDirectory(AppHelpers.AppDirectory); - Registry.SetValue(keyName, "languageCode", LanguageCode); - Registry.SetValue(keyName, "currency", (int)Currency); - Registry.SetValue(keyName, "themeURI", ThemeURI); - Registry.SetValue(keyName, "lastThreads", ThreadCount); - Registry.SetValue(keyName, "sound", Sound); - Registry.SetValue(keyName, "updateCheck", CheckForUpdates); - Registry.SetValue(keyName, "discordRPC", DiscordRPC); - Registry.SetValue(keyName, "migrated", Migrated); + var settings = JsonConvert.SerializeObject(this, Formatting.Indented); + File.WriteAllText(Path.Join(AppHelpers.AppDirectory, "settings.json"), settings); + } + catch (Exception ex) + { + Logger.Log.Error("Error saving settings", ex); + } } public void MigrateFromOldVersion() { - // This method cleans up old settings and data + // This method cleans up old settings and data + try + { + RegistryKey regkeySoftware = Registry.CurrentUser.OpenSubKey("SOFTWARE", true); + regkeySoftware.DeleteSubKeyTree("FloatTool"); + regkeySoftware.Close(); + } + catch (Exception ex) + { + Logger.Log.Error("Error saving settings", ex); + } + List oldFiles = new() { "debug.log", @@ -135,15 +201,12 @@ public void MigrateFromOldVersion() } App.CleanOldFiles(); - - // Finally save that we migrated to not do this every time - Migrated = true; Save(); } public override string ToString() { - return $"{{LanguageCode: {LanguageCode}, Currency: {Currency}, ThemeURI: {ThemeURI}, Sound: {Sound}, CheckForUpdates: {CheckForUpdates}, DiscordRPC: {DiscordRPC}, ThreadCount: {ThreadCount}, HaveUpdated: {Migrated}}}"; + return JsonConvert.SerializeObject(this, Formatting.Indented); } } } diff --git a/FloatTool/Common/Utils.cs b/FloatTool/Common/Utils.cs index c7a654c..2957fd8 100644 --- a/FloatTool/Common/Utils.cs +++ b/FloatTool/Common/Utils.cs @@ -23,7 +23,6 @@ using System.IO; using System.Linq; using System.Net.Http; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -99,12 +98,18 @@ public static string FirstCharToUpper(this string input) => public static class Utils { - public const string API_URL = "https://git.prevter.ml/api/floattool"; + public const string API_URL = "https://prevter.ml/api/floattool"; private static readonly HttpClient Client = new(); public static async Task GetWearFromInspectURL(string inspect_url) { - var result = await Client.GetAsync($"https://api.csgofloat.com/?url={inspect_url}"); + string url = AppHelpers.Settings.FloatAPI switch + { + FloatAPI.SteamInventoryHelper => "https://floats.steaminventoryhelper.com/?url=", + _ => "https://api.csgofloat.com/?url=", + }; + + var result = await Client.GetAsync(url + inspect_url); result.EnsureSuccessStatusCode(); string response = await result.Content.ReadAsStringAsync(); dynamic json = JsonConvert.DeserializeObject(response); @@ -181,11 +186,11 @@ public static void Sort(this ObservableCollection collection, ComparisonOpen themes folder Enable sound Check for updates + Show advanced + Float fetcher API: + Format for: Benchmark diff --git a/FloatTool/ViewModels/BenchmarkViewModel.cs b/FloatTool/ViewModels/BenchmarkViewModel.cs index 62fa1de..1d57235 100644 --- a/FloatTool/ViewModels/BenchmarkViewModel.cs +++ b/FloatTool/ViewModels/BenchmarkViewModel.cs @@ -40,9 +40,6 @@ public sealed class BenchmarkResult public GridLength FillSize { get; set; } public GridLength EmptySize { get; set; } } - - public Settings Settings; - public long TotalCombinations { get; set; } private int progressPercentage; @@ -182,14 +179,10 @@ public async void PollBenchmarkResults() else if (cpuName.StartsWith("Intel")) currentFill = IntelBrush; - string threadsString = Application.Current.Resources["m_Threads"] as string; - if ((int)benchmark.threads == 1) - threadsString = Application.Current.Resources["m_Thread"] as string; - BenchmarkResults.Add(new BenchmarkResult { CpuName = cpuName, - ThreadCount = $"{benchmark.threads} {threadsString} [{benchmark.version}]", + ThreadCount = Utils.EscapeLocalization($"{benchmark.threads} {((int)benchmark.threads == 1 ? "%m_Thread%" : "%m_Threads%")} [{benchmark.version}]"), MultithreadedScore = $"{(int)benchmark.multithread:n0}", SinglethreadedScore = $"{(int)benchmark.singlethread:n0}", FillSize = new GridLength(percentage, GridUnitType.Star), @@ -241,10 +234,9 @@ public async void PushBenchmarkResults() PollBenchmarkResults(); } - public BenchmarkViewModel(Settings settings) + public BenchmarkViewModel() { - Settings = settings; - ThreadCount = settings.ThreadCount; + ThreadCount = AppHelpers.Settings.ThreadCount; string path = @"HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0"; string cpu = (string)Registry.GetValue(path, "ProcessorNameString", "Unknown"); CurrentCpuName = Utils.ShortCpuName(cpu); diff --git a/FloatTool/ViewModels/MainViewModel.cs b/FloatTool/ViewModels/MainViewModel.cs index a472588..4e154d2 100644 --- a/FloatTool/ViewModels/MainViewModel.cs +++ b/FloatTool/ViewModels/MainViewModel.cs @@ -123,8 +123,7 @@ public sealed class MainViewModel : INotifyPropertyChanged public Dictionary, List> Outcomes = new(); public List SkinsDatabase; - public Settings Settings { get; set; } - + #region Properties public ObservableCollection FoundCombinations { get; set; } @@ -136,8 +135,8 @@ public static string CurrentVersionSubtitle public int ThreadCount { - get { return Settings.ThreadCount; } - set { Settings.ThreadCount = value; OnPropertyChanged(); } + get { return AppHelpers.Settings.ThreadCount; } + set { AppHelpers.Settings.ThreadCount = value; OnPropertyChanged(); } } public string CombinationsLabel @@ -535,11 +534,10 @@ public void UpdateSkinList() SkinList = list; } - public MainViewModel(string weapon, string skin, string quality, string filter, int count, int skip, Settings settings, Viewbox errorTooltip, Viewbox errorTooltipFloat) + public MainViewModel(string weapon, string skin, string quality, string filter, int count, int skip, Viewbox errorTooltip, Viewbox errorTooltipFloat) { errorMessage = errorTooltip; errorMessageFloat = errorTooltipFloat; - Settings = settings; WeaponName = weapon; SkinName = skin; SkinQuality = quality; diff --git a/FloatTool/ViewModels/SettingsViewModel.cs b/FloatTool/ViewModels/SettingsViewModel.cs index 76f2863..1eefa90 100644 --- a/FloatTool/ViewModels/SettingsViewModel.cs +++ b/FloatTool/ViewModels/SettingsViewModel.cs @@ -24,8 +24,6 @@ namespace FloatTool { public sealed class SettingsViewModel : INotifyPropertyChanged { - public Settings Settings { get; set; } - public static List ThemesList { get @@ -39,33 +37,33 @@ public static List ThemesList public int ThemeIndex { - get { return AppHelpers.ThemesFound.IndexOf(Settings.ThemeURI); } + get { return AppHelpers.ThemesFound.IndexOf(AppHelpers.Settings.ThemeURI); } set { - Settings.ThemeURI = AppHelpers.ThemesFound[value]; - App.SelectTheme(Settings.ThemeURI); + AppHelpers.Settings.ThemeURI = AppHelpers.ThemesFound[value]; + App.SelectTheme(AppHelpers.Settings.ThemeURI); OnPropertyChanged(); } } public bool EnableSound { - get { return Settings.Sound; } - set { Settings.Sound = value; OnPropertyChanged(); } + get { return AppHelpers.Settings.Sound; } + set { AppHelpers.Settings.Sound = value; OnPropertyChanged(); } } public bool CheckUpdates { - get { return Settings.CheckForUpdates; } - set { Settings.CheckForUpdates = value; OnPropertyChanged(); } + get { return AppHelpers.Settings.CheckForUpdates; } + set { AppHelpers.Settings.CheckForUpdates = value; OnPropertyChanged(); } } public bool DiscordRPC { - get { return Settings.DiscordRPC; } + get { return AppHelpers.Settings.DiscordRPC; } set { - Settings.DiscordRPC = value; + AppHelpers.Settings.DiscordRPC = value; OnPropertyChanged(); // Re-enabling does not work. Probably bug in the library @@ -80,11 +78,11 @@ public int CurrentCurrencyIndex { get { - return CurrencyHelper.GetIndexFromCurrency(Settings.Currency); + return CurrencyHelper.GetIndexFromCurrency(AppHelpers.Settings.Currency); } set { - Settings.Currency = CurrencyHelper.GetCurrencyByIndex(value); + AppHelpers.Settings.Currency = CurrencyHelper.GetCurrencyByIndex(value); OnPropertyChanged(); } } @@ -139,12 +137,12 @@ public int CurrentLanguage { get { - return LanguageCodes.IndexOf(Settings.LanguageCode); + return LanguageCodes.IndexOf(AppHelpers.Settings.LanguageCode); } set { - Settings.LanguageCode = LanguageCodes[value]; - App.SelectCulture(Settings.LanguageCode); + AppHelpers.Settings.LanguageCode = LanguageCodes[value]; + App.SelectCulture(AppHelpers.Settings.LanguageCode); OnPropertyChanged(); } } @@ -175,10 +173,63 @@ public int CurrentLanguage "zh", }; - public SettingsViewModel(Settings settings) + public List FloatAPIList { get; private set; } = new() + { + "CSGOFloat (api.csgofloat.com)", + "SIH (floats.steaminventoryhelper.com)" + }; + + public List ExtensionNames { get; private set; } = new() + { + "CSGOFloat Market Checker", + "Steam Inventory Helper" + }; + + public int SelectedFloatAPI + { + get { return (int)AppHelpers.Settings.FloatAPI; } + set + { + AppHelpers.Settings.FloatAPI = (FloatAPI)value; + OnPropertyChanged(); + } + } + + public int SelectedExtension + { + get { return (int)AppHelpers.Settings.ExtensionType; } + set + { + AppHelpers.Settings.ExtensionType = (ExtensionType)value; + OnPropertyChanged(); + } + } + + private bool isShowingAdvanced = false; + private RelayCommand showAdvanced; + public RelayCommand ShowAdvancedCommand + { + get + { + return showAdvanced ??= new RelayCommand(obj => + { + isShowingAdvanced = !isShowingAdvanced; + + if (isShowingAdvanced) + window.Height = 370; + else + window.Height = 310; + + }); + } + } + + private readonly SettingsWindow window; + + public SettingsViewModel(SettingsWindow window) { - Settings = settings; Languages = new List(); + this.window = window; foreach (var lang in LanguageCodes) { diff --git a/FloatTool/Views/BenchmarkWindow.xaml.cs b/FloatTool/Views/BenchmarkWindow.xaml.cs index 4656efb..7afdbaa 100644 --- a/FloatTool/Views/BenchmarkWindow.xaml.cs +++ b/FloatTool/Views/BenchmarkWindow.xaml.cs @@ -30,16 +30,15 @@ namespace FloatTool public sealed partial class BenchmarkWindow : Window { public BenchmarkViewModel Context; - public Settings Settings; private static long PassedCombinations; - public BenchmarkWindow(Settings settings) + public BenchmarkWindow() { Logger.Log.Info("Opened benchmark window"); - Context = new BenchmarkViewModel(settings); + Context = new BenchmarkViewModel(); DataContext = Context; - if (settings.DiscordRPC) + if (AppHelpers.Settings.DiscordRPC) { AppHelpers.DiscordClient.SetPresence(new DiscordRPC.RichPresence() { diff --git a/FloatTool/Views/MainWindow.xaml b/FloatTool/Views/MainWindow.xaml index faa37e5..d76e80f 100644 --- a/FloatTool/Views/MainWindow.xaml +++ b/FloatTool/Views/MainWindow.xaml @@ -38,6 +38,7 @@ + @@ -337,7 +338,7 @@ - + @@ -347,7 +348,7 @@ - + @@ -357,7 +358,7 @@ - + @@ -367,7 +368,7 @@ - + @@ -377,7 +378,7 @@ - + @@ -387,7 +388,7 @@ - + @@ -397,7 +398,7 @@ - + @@ -407,7 +408,7 @@ - + @@ -417,7 +418,7 @@ - + @@ -427,7 +428,7 @@ - + diff --git a/FloatTool/Views/MainWindow.xaml.cs b/FloatTool/Views/MainWindow.xaml.cs index 42ca7d1..ab9b4f7 100644 --- a/FloatTool/Views/MainWindow.xaml.cs +++ b/FloatTool/Views/MainWindow.xaml.cs @@ -40,7 +40,6 @@ namespace FloatTool public sealed partial class MainWindow : Window { public MainViewModel ViewModel; - public Settings Settings; private readonly RPCSettingsPersist RPCSettings = new(); private static long PassedCombinations; @@ -58,7 +57,7 @@ public void UpdateRichPresence(bool clear = false) RPCSettings.ShowTime = false; } - if (Settings.DiscordRPC) + if (AppHelpers.Settings.DiscordRPC) { AppHelpers.DiscordClient.SetPresence(RPCSettings.GetPresense()); } @@ -73,16 +72,12 @@ public MainWindow() CombinationFoundSound.Load(); } - Settings = new Settings(); - Settings.TryLoad(); + App.SelectCulture(AppHelpers.Settings.LanguageCode); + App.SelectTheme(AppHelpers.Settings.ThemeURI); if (!Settings.Migrated) Settings.MigrateFromOldVersion(); - - App.SelectCulture(Settings.LanguageCode); - App.SelectTheme(Settings.ThemeURI); - - ViewModel = new MainViewModel("Nova", "Predator", "Field-Tested", "0.250000000", 100, 20, Settings, ErrorTooltip, ErrorTooltipFloat); + ViewModel = new MainViewModel("Nova", "Predator", "Field-Tested", "0.250000000", 100, 20, ErrorTooltip, ErrorTooltipFloat); MaxHeight = SystemParameters.WorkArea.Height + 12; MaxWidth = SystemParameters.WorkArea.Width + 12; @@ -92,7 +87,7 @@ public MainWindow() Logger.Log.Info("Main window started"); - if (Settings.CheckForUpdates) + if (AppHelpers.Settings.CheckForUpdates) { Task.Factory.StartNew(() => { @@ -102,7 +97,7 @@ public MainWindow() Dispatcher.Invoke(new Action(() => { Logger.Log.Info("New version available"); - var updateWindow = new UpdateWindow(update, Settings) + var updateWindow = new UpdateWindow(update) { Owner = this }; @@ -120,6 +115,7 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) } private void Window_KeyUp(object sender, KeyEventArgs e) + private async void Window_KeyUp(object sender, KeyEventArgs e) { switch (e.Key) { @@ -143,6 +139,9 @@ private void Window_KeyUp(object sender, KeyEventArgs e) break; case Key.F12: // TODO: Create a dev tools window + var client = new SteamClient(); + var qrcode = await client.LoginWithQR(); + MessageBox.Show(qrcode); break; } } @@ -165,10 +164,10 @@ private void WindowButton_Click(object sender, RoutedEventArgs e) Process.Start(new ProcessStartInfo { FileName = "https://discord.gg/RM9VrzMfhP", UseShellExecute = true }); break; case "BenchmarkButton": - new BenchmarkWindow(Settings).ShowDialog(); + new BenchmarkWindow().ShowDialog(); break; case "SettingsButton": - new SettingsWindow(Settings).ShowDialog(); + new SettingsWindow().ShowDialog(); break; } @@ -251,7 +250,7 @@ private void FloatCraftWorkerThread(CraftSearchSetup options) Price = price, Wear32Bit = ((double)ieee).ToString("0.000000000000000", CultureInfo.InvariantCulture), }); - if (Settings.Sound) + if (AppHelpers.Settings.Sound) CombinationFoundSound.Play(); })); } @@ -283,7 +282,7 @@ private void StartSearchButton_Click(object sender, RoutedEventArgs e) TokenSource = new CancellationTokenSource(); CancellationToken = TokenSource.Token; - if (Settings.DiscordRPC) + if (AppHelpers.Settings.DiscordRPC) { RPCSettings.Details = $"%m_Searching% {ViewModel.FullSkinName}"; RPCSettings.State = $"%m_DesiredFloat% {ViewModel.SearchFilter}"; @@ -324,7 +323,7 @@ private void StartSearchButton_Click(object sender, RoutedEventArgs e) ConcurrentBag inputSkinBag = new(); - string url = $"https://steamcommunity.com/market/listings/730/{ViewModel.FullSkinName}/render/?count={ViewModel.SkinCount}&start={ViewModel.SkinSkipCount}¤cy={(int)Settings.Currency}"; + string url = $"https://steamcommunity.com/market/listings/730/{ViewModel.FullSkinName}/render/?count={ViewModel.SkinCount}&start={ViewModel.SkinSkipCount}¤cy={(int)AppHelpers.Settings.Currency}"; try { using var client = new HttpClient(); diff --git a/FloatTool/Views/SettingsWindow.xaml b/FloatTool/Views/SettingsWindow.xaml index 9e328e5..36f64aa 100644 --- a/FloatTool/Views/SettingsWindow.xaml +++ b/FloatTool/Views/SettingsWindow.xaml @@ -20,12 +20,12 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:FloatTool" - mc:Ignorable="d" - Height="300" Width="350" + mc:Ignorable="d" x:Name="settingsWindow" + Height="310" Width="350" WindowStartupLocation="CenterScreen" - WindowStyle="None" + WindowStyle="None" AllowsTransparency="True" ResizeMode="NoResize" - Background="Transparent"> + Background="Transparent" d:DesignHeight="370"> @@ -66,6 +66,7 @@ + - + ItemsSource="{Binding Languages}" SelectedIndex="{Binding CurrentLanguage}"/> + - - - - - + Grid.Column="0" Grid.Row="2"/> + - +