Skip to content

Commit

Permalink
v.1.1.0
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Prevter committed Jul 19, 2022
1 parent 9b968d6 commit 2d4dfcb
Show file tree
Hide file tree
Showing 21 changed files with 267 additions and 141 deletions.
61 changes: 29 additions & 32 deletions FloatTool/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using DiscordRPC;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -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<string> ThemesFound { get; set; }
public static FileSystemWatcher Watcher;
public static DiscordRpcClient DiscordClient;
public static string VersionCode;

public static void SelectCulture(string culture)
{
Expand Down Expand Up @@ -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) =>
{
Expand All @@ -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";
Expand All @@ -131,8 +127,8 @@ public App()
var themesFolder = Path.Combine(combined, "themes");
if (!Directory.Exists(themesFolder))
Directory.CreateDirectory(themesFolder);

ThemesFound = new List<string>
AppHelpers.
ThemesFound = new List<string>
{
"/Theme/Schemes/Dark.xaml", "/Theme/Schemes/Light.xaml"
};
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
}

Expand Down
31 changes: 31 additions & 0 deletions FloatTool/AppHelpers.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<string> ThemesFound { get; set; }
}
}
26 changes: 12 additions & 14 deletions FloatTool/Common/Calculations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -53,7 +51,7 @@ static public bool NextCombination(int[] num, int n)
}
finished = i == 0;
}
return changed;
return false;
}

static public IEnumerable<InputSkin[]> Combinations(InputSkin[] elem, int start, int skip)
Expand Down
18 changes: 10 additions & 8 deletions FloatTool/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
27 changes: 18 additions & 9 deletions FloatTool/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<decimal> GetWearFromInspectURL(string inspect_url)
Expand Down Expand Up @@ -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<Match>())
cpu = cpu.Replace(match.Value, "");

var index = cpu.IndexOf('@');
Expand All @@ -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<Asset> 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<Asset> Assets { get; set; }
[JsonRequired]
[JsonProperty("body")]
public string Body { get; set; }
}
#pragma warning restore IDE1006 // Naming Styles

public class CraftSearchSetup
{
Expand Down
2 changes: 1 addition & 1 deletion FloatTool/FloatTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageProjectUrl>https://prevter.github.io/FloatTool</PackageProjectUrl>
<RepositoryUrl>https://github.com/Prevter/FloatTool</RepositoryUrl>
<NeutralLanguage>en</NeutralLanguage>
<AssemblyVersion>1.0.2</AssemblyVersion>
<AssemblyVersion>1.1.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<ApplicationIcon>Assets\Icon.ico</ApplicationIcon>
<DebugType>embedded</DebugType>
Expand Down
4 changes: 3 additions & 1 deletion FloatTool/Languages/Lang.ru.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<v:String x:Key="m_CheckedCombinations">Проверено комбинаций:</v:String>
<v:String x:Key="m_SkinNotFound">Ошибка! Этот скин не может иметь это качество.</v:String>
<v:String x:Key="m_CantBeStattrak">Ошибка! Этот скин не может быть StatTrak.</v:String>

<v:String x:Key="m_OutOfBounds">Внимание! Вы ввели значение которое виходит за рамки для текущих настроек.</v:String>
<v:String x:Key="m_CantParse">Ошибка! Не удалось перевести в число.</v:String>

<!-- Settings window -->
<v:String x:Key="m_Settings">Настройки</v:String>
<v:String x:Key="m_Language">Язык:</v:String>
Expand Down
4 changes: 3 additions & 1 deletion FloatTool/Languages/Lang.uk.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<v:String x:Key="m_CheckedCombinations">Перевірено комбінацій:</v:String>
<v:String x:Key="m_SkinNotFound">Помилка! Цей скін не можете мати цю якість.</v:String>
<v:String x:Key="m_CantBeStattrak">Помилка! Цей скін не може бути StatTrak.</v:String>

<v:String x:Key="m_OutOfBounds">Увага! Ви ввели значення яке виходить за рамки для поточних налаштувань.</v:String>
<v:String x:Key="m_CantParse">Помилка! Не вдалося перевести в число.</v:String>

<!-- Settings window -->
<v:String x:Key="m_Settings">Налаштування</v:String>
<v:String x:Key="m_Language">Мова:</v:String>
Expand Down
4 changes: 3 additions & 1 deletion FloatTool/Languages/Lang.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<v:String x:Key="m_CheckedCombinations">Checked combinations:</v:String>
<v:String x:Key="m_SkinNotFound">Error! This skin can not have this quality.</v:String>
<v:String x:Key="m_CantBeStattrak">Error! This skin can not be StatTrak.</v:String>

<v:String x:Key="m_OutOfBounds">Warning! You've entered value that is out of bounds for current settings.</v:String>
<v:String x:Key="m_CantParse">Error! Can't convert this to number.</v:String>

<!-- Settings window -->
<v:String x:Key="m_Settings">Settings</v:String>
<v:String x:Key="m_Language">Language:</v:String>
Expand Down
6 changes: 3 additions & 3 deletions FloatTool/Theme/NumericBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
BorderThickness="0"
PreviewTextInput="PreviewTextInputHandler"
DataObject.Pasting="TextBox_Pasting"
TextChanged="inputBox_TextChanged"/>
TextChanged="InputBox_TextChanged"/>
<Button x:Name="cmdUp"
FontSize="8"
Padding="0,-2,0,0"
Width="20"
Click="cmdUp_Click"
Click="Up_Click"
Style="{DynamicResource MainButtonStyle}"
HorizontalAlignment="Right"
VerticalAlignment="Stretch">
Expand All @@ -69,7 +69,7 @@
FontSize="8"
Padding="0,-1,0,0"
Width="20"
Click="cmdDown_Click"
Click="Down_Click"
HorizontalAlignment="Right"
Style="{DynamicResource MainButtonStyle}"
VerticalAlignment="Stretch"
Expand Down
6 changes: 3 additions & 3 deletions FloatTool/Theme/NumericBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ private void TrySetValue(int value)
SetValue(ValueProperty, Maximum);
}

private void cmdUp_Click(object sender, RoutedEventArgs e)
private void Up_Click(object sender, RoutedEventArgs e)
{
Value++;
ValueChanged?.Invoke(this, Value);
}

private void cmdDown_Click(object sender, RoutedEventArgs e)
private void Down_Click(object sender, RoutedEventArgs e)
{
Value--;
ValueChanged?.Invoke(this, Value);
Expand Down Expand Up @@ -118,7 +118,7 @@ private void PreviewTextInputHandler(Object sender, TextCompositionEventArgs e)
e.Handled = !IsTextAllowed(e.Text);
}

private void inputBox_TextChanged(object sender, TextChangedEventArgs e)
private void InputBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!IsTextAllowed(inputBox.Text) || string.IsNullOrEmpty(inputBox.Text))
return;
Expand Down
Loading

0 comments on commit 2d4dfcb

Please sign in to comment.