From 2d4dfcb48d70fc4738c34a9ce2a94c824359dd08 Mon Sep 17 00:00:00 2001 From: Nemesh Date: Tue, 19 Jul 2022 23:16:39 +0300 Subject: [PATCH] v.1.1.0 * Minor bug fixes * Small optimizations * Added CZ75, P250, SSG 08, Tec-9 and USP-S to list (haven't realized until now) * Fixed all warnings and messages in VS * Added search filter check, it'l show a warning if you entered incorrect settings * If you press F4, it will open steam marketplace for current skin --- FloatTool/App.xaml.cs | 61 ++++++++++------------ FloatTool/AppHelpers.cs | 31 +++++++++++ FloatTool/Common/Calculations.cs | 26 +++++---- FloatTool/Common/Logger.cs | 18 ++++--- FloatTool/Common/Utils.cs | 27 ++++++---- FloatTool/FloatTool.csproj | 2 +- FloatTool/Languages/Lang.ru.xaml | 4 +- FloatTool/Languages/Lang.uk.xaml | 4 +- FloatTool/Languages/Lang.xaml | 4 +- FloatTool/Theme/NumericBox.xaml | 6 +-- FloatTool/Theme/NumericBox.xaml.cs | 6 +-- FloatTool/ViewModels/BenchmarkViewModel.cs | 8 +-- FloatTool/ViewModels/MainViewModel.cs | 47 +++++++++++++++-- FloatTool/ViewModels/SettingsViewModel.cs | 12 ++--- FloatTool/Views/BenchmarkWindow.xaml.cs | 16 +++--- FloatTool/Views/MainWindow.xaml | 35 +++++++++++++ FloatTool/Views/MainWindow.xaml.cs | 43 +++++++++------ FloatTool/Views/UpdateWindow.xaml | 4 +- FloatTool/Views/UpdateWindow.xaml.cs | 4 +- ItemsParser/Program.cs | 14 ++--- ItemsParser/Structs.cs | 36 ++++++------- 21 files changed, 267 insertions(+), 141 deletions(-) create mode 100644 FloatTool/AppHelpers.cs diff --git a/FloatTool/App.xaml.cs b/FloatTool/App.xaml.cs index 3c58117..82905f7 100644 --- a/FloatTool/App.xaml.cs +++ b/FloatTool/App.xaml.cs @@ -15,6 +15,7 @@ - along with this program. If not, see . */ +using DiscordRPC; using System; using System.Collections.Generic; using System.Diagnostics; @@ -28,17 +29,12 @@ using System.Windows; using System.Windows.Data; using System.Windows.Threading; -using DiscordRPC; namespace FloatTool { public partial class App : Application { public static ResourceDictionary ThemeDictionary { get; set; } - public static List ThemesFound { get; set; } - public static FileSystemWatcher Watcher; - public static DiscordRpcClient DiscordClient; - public static string VersionCode; public static void SelectCulture(string culture) { @@ -94,17 +90,17 @@ public static void SelectTheme(string themeURI) public App() { var version = Assembly.GetExecutingAssembly().GetName().Version; - VersionCode = $"v.{version.Major}.{version.Minor}.{version.Build}"; + AppHelpers.VersionCode = $"v.{version.Major}.{version.Minor}.{version.Build}"; Logger.Initialize(); - Logger.Log.Info($"FloatTool {VersionCode}"); + Logger.Log.Info($"FloatTool {AppHelpers.VersionCode}"); Logger.Log.Info($"OS: {Environment.OSVersion}"); Logger.Log.Info($"Memory: {Environment.WorkingSet / 1024 / 1024} MB"); Logger.Log.Info($"Culture: {Thread.CurrentThread.CurrentCulture}"); AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Log.Error("Unhandled exception", (Exception)e.ExceptionObject); - + DispatcherUnhandledException += (s, e) => { @@ -117,7 +113,7 @@ public App() Logger.Log.Error("Unobserved Unhandled Exception", e.Exception); e.SetObserved(); }; - + //Get path for %AppData% var appdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var subfolder = "floattool"; @@ -131,8 +127,8 @@ public App() var themesFolder = Path.Combine(combined, "themes"); if (!Directory.Exists(themesFolder)) Directory.CreateDirectory(themesFolder); - - ThemesFound = new List + AppHelpers. + ThemesFound = new List { "/Theme/Schemes/Dark.xaml", "/Theme/Schemes/Light.xaml" }; @@ -141,25 +137,26 @@ public App() FileInfo[] Files = d.GetFiles("*.xaml"); foreach (FileInfo file in Files) - ThemesFound.Add(file.FullName); - - Watcher = new FileSystemWatcher - { - Path = themesFolder, - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName - }; - - // Add event handlers. - Watcher.Changed += new FileSystemEventHandler(OnChanged); - Watcher.Created += new FileSystemEventHandler(OnChanged); - Watcher.Deleted += new FileSystemEventHandler(OnChanged); - Watcher.Renamed += new RenamedEventHandler(OnRenamed); - - Watcher.EnableRaisingEvents = true; + 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.Created += new FileSystemEventHandler(OnChanged); + AppHelpers.Watcher.Deleted += new FileSystemEventHandler(OnChanged); + AppHelpers.Watcher.Renamed += new RenamedEventHandler(OnRenamed); + AppHelpers. + Watcher.EnableRaisingEvents = true; Trace.WriteLine("Started FileWatcher"); - - DiscordClient = new DiscordRpcClient("734042978246721537"); - DiscordClient.Initialize(); + AppHelpers. + DiscordClient = new DiscordRpcClient("734042978246721537"); + AppHelpers.DiscordClient.Initialize(); } public static void CleanOldFiles() @@ -212,10 +209,10 @@ private void OnChanged(object source, FileSystemEventArgs e) switch (e.ChangeType) { case WatcherChangeTypes.Deleted: - ThemesFound.Remove(e.FullPath); + AppHelpers.ThemesFound.Remove(e.FullPath); break; case WatcherChangeTypes.Created: - ThemesFound.Add(e.FullPath); + AppHelpers.ThemesFound.Add(e.FullPath); break; case WatcherChangeTypes.Changed: if (ThemeDictionary.Source.IsAbsoluteUri && e.FullPath == ThemeDictionary.Source.LocalPath) @@ -237,7 +234,7 @@ private void OnChanged(object source, FileSystemEventArgs e) private void OnRenamed(object source, RenamedEventArgs e) { Trace.WriteLine($"File: {e.OldFullPath} renamed to {e.FullPath}"); - ThemesFound[ThemesFound.IndexOf(e.OldFullPath)] = e.FullPath; + AppHelpers.ThemesFound[AppHelpers.ThemesFound.IndexOf(e.OldFullPath)] = e.FullPath; } } diff --git a/FloatTool/AppHelpers.cs b/FloatTool/AppHelpers.cs new file mode 100644 index 0000000..91662d1 --- /dev/null +++ b/FloatTool/AppHelpers.cs @@ -0,0 +1,31 @@ +/* +- Copyright(C) 2022 Prevter +- +- This program is free software: you can redistribute it and/or modify +- it under the terms of the GNU General Public License as published by +- the Free Software Foundation, either version 3 of the License, or +- (at your option) any later version. +- +- This program is distributed in the hope that it will be useful, +- but WITHOUT ANY WARRANTY; without even the implied warranty of +- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +- GNU General Public License for more details. +- +- You should have received a copy of the GNU General Public License +- along with this program. If not, see . +*/ + +using DiscordRPC; +using System.Collections.Generic; +using System.IO; + +namespace FloatTool +{ + internal static class AppHelpers + { + public static FileSystemWatcher Watcher; + public static DiscordRpcClient DiscordClient; + public static string VersionCode; + public static List ThemesFound { get; set; } + } +} \ No newline at end of file diff --git a/FloatTool/Common/Calculations.cs b/FloatTool/Common/Calculations.cs index acbdbd5..03f3ebe 100644 --- a/FloatTool/Common/Calculations.cs +++ b/FloatTool/Common/Calculations.cs @@ -24,24 +24,22 @@ static public class Calculations { static public decimal Craft(InputSkin[] ingridients, decimal minFloat, decimal floatRange) { - decimal avgFloat = ingridients[0].WearValue; - avgFloat += ingridients[1].WearValue; - avgFloat += ingridients[2].WearValue; - avgFloat += ingridients[3].WearValue; - avgFloat += ingridients[4].WearValue; - avgFloat += ingridients[5].WearValue; - avgFloat += ingridients[6].WearValue; - avgFloat += ingridients[7].WearValue; - avgFloat += ingridients[8].WearValue; - avgFloat += ingridients[9].WearValue; - return floatRange * avgFloat + minFloat; + return floatRange * (ingridients[0].WearValue + + ingridients[1].WearValue + + ingridients[2].WearValue + + ingridients[3].WearValue + + ingridients[4].WearValue + + ingridients[5].WearValue + + ingridients[6].WearValue + + ingridients[7].WearValue + + ingridients[8].WearValue + + ingridients[9].WearValue) + minFloat; } static public bool NextCombination(int[] num, int n) { bool finished = false; - bool changed = false; - for (int i = 9; !finished && !changed; --i) + for (int i = 9; !finished; --i) { if (num[i] < n + i) { @@ -53,7 +51,7 @@ static public bool NextCombination(int[] num, int n) } finished = i == 0; } - return changed; + return false; } static public IEnumerable Combinations(InputSkin[] elem, int start, int skip) diff --git a/FloatTool/Common/Logger.cs b/FloatTool/Common/Logger.cs index 158106c..17df694 100644 --- a/FloatTool/Common/Logger.cs +++ b/FloatTool/Common/Logger.cs @@ -38,14 +38,16 @@ public static void Initialize() }; patternLayout.ActivateOptions(); - RollingFileAppender roller = new(); - roller.AppendToFile = false; - roller.File = @"logs/log.txt"; - roller.Layout = patternLayout; - roller.MaxSizeRollBackups = 5; - roller.MaximumFileSize = "250KB"; - roller.RollingStyle = RollingFileAppender.RollingMode.Size; - roller.StaticLogFileName = true; + RollingFileAppender roller = new() + { + AppendToFile = false, + File = @"logs/log.txt", + Layout = patternLayout, + MaxSizeRollBackups = 5, + MaximumFileSize = "250KB", + RollingStyle = RollingFileAppender.RollingMode.Size, + StaticLogFileName = true + }; roller.ActivateOptions(); hierarchy.Root.AddAppender(roller); diff --git a/FloatTool/Common/Utils.cs b/FloatTool/Common/Utils.cs index 23fa2f7..0a4149d 100644 --- a/FloatTool/Common/Utils.cs +++ b/FloatTool/Common/Utils.cs @@ -18,6 +18,7 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Text.RegularExpressions; using System.Threading.Tasks; @@ -37,7 +38,7 @@ public static string FirstCharToUpper(this string input) => public static class Utils { - public static string API_URL = "https://prevterapi.000webhostapp.com"; + public const string API_URL = "https://prevterapi.000webhostapp.com"; private static readonly HttpClient Client = new(); public static async Task GetWearFromInspectURL(string inspect_url) @@ -80,7 +81,7 @@ public static string ShortCpuName(string cpu) Regex regex = new(@"( \S{1,}-Core)"); MatchCollection matches = regex.Matches(cpu); if (matches.Count > 0) - foreach (Match match in matches) + foreach (Match match in matches.Cast()) cpu = cpu.Replace(match.Value, ""); var index = cpu.IndexOf('@'); @@ -95,20 +96,28 @@ public static string ShortCpuName(string cpu) } } -#pragma warning disable IDE1006 // Naming Styles public class UpdateResult { public class Asset { - public string browser_download_url { get; set; } + [JsonRequired] + [JsonProperty("browser_download_url")] + public string BrowserDownloadUrl { get; set; } } - public string tag_name { get; set; } - public string name { get; set; } - public List assets { get; set; } - public string body { get; set; } + [JsonRequired] + [JsonProperty("tag_name")] + public string TagName { get; set; } + [JsonRequired] + [JsonProperty("name")] + public string Name { get; set; } + [JsonRequired] + [JsonProperty("assets")] + public List Assets { get; set; } + [JsonRequired] + [JsonProperty("body")] + public string Body { get; set; } } -#pragma warning restore IDE1006 // Naming Styles public class CraftSearchSetup { diff --git a/FloatTool/FloatTool.csproj b/FloatTool/FloatTool.csproj index d05060a..c1f96cd 100644 --- a/FloatTool/FloatTool.csproj +++ b/FloatTool/FloatTool.csproj @@ -9,7 +9,7 @@ https://prevter.github.io/FloatTool https://github.com/Prevter/FloatTool en - 1.0.2 + 1.1.0 $(AssemblyVersion) Assets\Icon.ico embedded diff --git a/FloatTool/Languages/Lang.ru.xaml b/FloatTool/Languages/Lang.ru.xaml index 7922919..d578672 100644 --- a/FloatTool/Languages/Lang.ru.xaml +++ b/FloatTool/Languages/Lang.ru.xaml @@ -38,7 +38,9 @@ Проверено комбинаций: Ошибка! Этот скин не может иметь это качество. Ошибка! Этот скин не может быть StatTrak. - + Внимание! Вы ввели значение которое виходит за рамки для текущих настроек. + Ошибка! Не удалось перевести в число. + Настройки Язык: diff --git a/FloatTool/Languages/Lang.uk.xaml b/FloatTool/Languages/Lang.uk.xaml index 04fe364..97afd5a 100644 --- a/FloatTool/Languages/Lang.uk.xaml +++ b/FloatTool/Languages/Lang.uk.xaml @@ -38,7 +38,9 @@ Перевірено комбінацій: Помилка! Цей скін не можете мати цю якість. Помилка! Цей скін не може бути StatTrak. - + Увага! Ви ввели значення яке виходить за рамки для поточних налаштувань. + Помилка! Не вдалося перевести в число. + Налаштування Мова: diff --git a/FloatTool/Languages/Lang.xaml b/FloatTool/Languages/Lang.xaml index 92bc540..22833ae 100644 --- a/FloatTool/Languages/Lang.xaml +++ b/FloatTool/Languages/Lang.xaml @@ -38,7 +38,9 @@ Checked combinations: Error! This skin can not have this quality. Error! This skin can not be StatTrak. - + Warning! You've entered value that is out of bounds for current settings. + Error! Can't convert this to number. + Settings Language: diff --git a/FloatTool/Theme/NumericBox.xaml b/FloatTool/Theme/NumericBox.xaml index 27189de..3eb3857 100644 --- a/FloatTool/Theme/NumericBox.xaml +++ b/FloatTool/Theme/NumericBox.xaml @@ -40,12 +40,12 @@ BorderThickness="0" PreviewTextInput="PreviewTextInputHandler" DataObject.Pasting="TextBox_Pasting" - TextChanged="inputBox_TextChanged"/> + TextChanged="InputBox_TextChanged"/>