Skip to content

Commit

Permalink
autoupdate, even more languages, old files cleaning, fixed minor bugs
Browse files Browse the repository at this point in the history
This is probably last commit before release, as there are only minor things to be done
  • Loading branch information
Prevter committed Apr 22, 2022
1 parent 2285751 commit c0514a6
Show file tree
Hide file tree
Showing 35 changed files with 1,594 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.vs/
FloatTool/bin/
bin/
FloatTool/obj/
22 changes: 18 additions & 4 deletions FloatTool/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:FloatTool"
StartupUri="Views/MainWindow.xaml">
StartupUri="Views/MainWindow.xaml" Startup="AppLoaded">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand All @@ -41,12 +41,26 @@
<ResourceDictionary Source="Assets/BenchmarkIcon.xaml"/>
<ResourceDictionary Source="Assets/ButtonIcons.xaml"/>
<!-- Translations -->
<ResourceDictionary Source="Languages/Lang.cs.xaml"/>
<ResourceDictionary Source="Languages/Lang.da.xaml"/>
<ResourceDictionary Source="Languages/Lang.de.xaml"/>
<ResourceDictionary Source="Languages/Lang.es.xaml"/>
<ResourceDictionary Source="Languages/Lang.fi.xaml"/>
<ResourceDictionary Source="Languages/Lang.fr.xaml"/>
<ResourceDictionary Source="Languages/Lang.ga.xaml"/>
<ResourceDictionary Source="Languages/Lang.he.xaml"/>
<ResourceDictionary Source="Languages/Lang.hr.xaml"/>
<ResourceDictionary Source="Languages/Lang.it.xaml"/>
<ResourceDictionary Source="Languages/Lang.ja.xaml"/>
<ResourceDictionary Source="Languages/Lang.zh.xaml"/>
<ResourceDictionary Source="Languages/Lang.ka.xaml"/>
<ResourceDictionary Source="Languages/Lang.lt.xaml"/>
<ResourceDictionary Source="Languages/Lang.lv.xaml"/>
<ResourceDictionary Source="Languages/Lang.pl.xaml"/>
<ResourceDictionary Source="Languages/Lang.fr.xaml"/>
<ResourceDictionary Source="Languages/Lang.ru.xaml"/>
<ResourceDictionary Source="Languages/Lang.pt.xaml"/>
<ResourceDictionary Source="Languages/Lang.uk.xaml"/>
<ResourceDictionary Source="Languages/Lang.tr.xaml"/>
<ResourceDictionary Source="Languages/Lang.ru.xaml"/>
<ResourceDictionary Source="Languages/Lang.zh.xaml"/>
<ResourceDictionary Source="Languages/Lang.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down
19 changes: 17 additions & 2 deletions FloatTool/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static void SelectTheme(string themeURI)
public App()
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
VersionCode = $"v.{version.Major}.{version.MajorRevision}.{version.Minor}";
VersionCode = $"v.{version.Major}.{version.Minor}.{version.Build}";

Logger.Initialize();
Logger.Log.Info($"FloatTool {VersionCode}");
Expand Down Expand Up @@ -162,9 +162,24 @@ public App()
DiscordClient.Initialize();
}

public static void CleanOldFiles()
{
string folderPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
foreach (var oldFile in Directory.GetFiles(folderPath, "*.old", SearchOption.TopDirectoryOnly))
File.Delete(oldFile);
}

void AppLoaded(object sender, StartupEventArgs e)
{
if (e.Args.Length > 0 && e.Args.Contains("--clean-update"))
{
CleanOldFiles();
}
}

const int ERROR_SHARING_VIOLATION = 32;
const int ERROR_LOCK_VIOLATION = 33;
private static bool IsFileLocked(string file)
public static bool IsFileLocked(string file)
{
if (File.Exists(file) == true)
{
Expand Down
2 changes: 1 addition & 1 deletion FloatTool/Common/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void Initialize()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

PatternLayout patternLayout = new PatternLayout{
PatternLayout patternLayout = new() {
ConversionPattern = "%date [%thread] %-5level - %message%newline"
};
patternLayout.ActivateOptions();
Expand Down
43 changes: 35 additions & 8 deletions FloatTool/Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

namespace FloatTool
Expand Down Expand Up @@ -70,6 +72,7 @@ public class Settings
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 void TryLoad()
{
Expand All @@ -83,11 +86,10 @@ public void TryLoad()
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);

// Using ToString to be compatible with older versions
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";
}
catch (Exception ex)
{
Expand All @@ -106,16 +108,41 @@ public void Save()
Registry.SetValue(keyName, "currency", (int)Currency);
Registry.SetValue(keyName, "themeURI", ThemeURI);
Registry.SetValue(keyName, "lastThreads", ThreadCount);

// Using ToString to be compatible with older versions
Registry.SetValue(keyName, "sound", Sound.ToString());
Registry.SetValue(keyName, "updateCheck", CheckForUpdates.ToString());
Registry.SetValue(keyName, "discordRPC", DiscordRPC.ToString());
Registry.SetValue(keyName, "sound", Sound);
Registry.SetValue(keyName, "updateCheck", CheckForUpdates);
Registry.SetValue(keyName, "discordRPC", DiscordRPC);
Registry.SetValue(keyName, "migrated", Migrated);
}

public void MigrateFromOldVersion()
{
// This method cleans up old settings and data
List<string> oldFiles = new() {
"debug.log",
"FloatCore.dll",
"FloatTool.exe.config",
"FloatTool.pdb",
"itemData.json",
"theme.json",
"Updater.exe"
};

foreach(var file in oldFiles)
{
if (File.Exists(file))
File.Delete(file);
}

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}}}";
return $"{{LanguageCode: {LanguageCode}, Currency: {Currency}, ThemeURI: {ThemeURI}, Sound: {Sound}, CheckForUpdates: {CheckForUpdates}, DiscordRPC: {DiscordRPC}, ThreadCount: {ThreadCount}, HaveUpdated: {Migrated}}}";
}
}
}
35 changes: 34 additions & 1 deletion FloatTool/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string FirstCharToUpper(this string input) =>
public static class Utils
{
public static string API_URL = "https://prevterapi.000webhostapp.com";
private static HttpClient Client = new();
private static readonly HttpClient Client = new();

public static async Task<decimal> GetWearFromInspectURL(string inspect_url)
{
Expand All @@ -49,6 +49,24 @@ public static async Task<decimal> GetWearFromInspectURL(string inspect_url)
return Convert.ToDecimal(json["iteminfo"]["floatvalue"]);
}

public static async Task<UpdateResult> CheckForUpdates()
{
try
{
HttpClient client = new();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36");
var result = await client.GetAsync("https://api.github.com/repos/prevter/floattool/releases/latest");
result.EnsureSuccessStatusCode();
string response = await result.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<UpdateResult>(response);
}
catch(Exception ex)
{
Logger.Log.Error("Failed to get latest version", ex);
return null;
}
}

public static string ShortCpuName(string cpu)
{
cpu = cpu.Replace("(R)", "");
Expand Down Expand Up @@ -77,6 +95,21 @@ 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; }
}

public string tag_name { get; set; }
public string name { get; set; }
public List<Asset> assets { get; set; }
public string body { get; set; }
}
#pragma warning restore IDE1006 // Naming Styles

public class CraftSearchSetup
{
public decimal SearchTarget { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions FloatTool/FloatTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<AssemblyVersion>1.0.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<ApplicationIcon>Assets\Icon.ico</ApplicationIcon>
<DebugType>embedded</DebugType>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<BaseOutputPath>$(SolutionDir)bin</BaseOutputPath>
</PropertyGroup>

<ItemGroup>
Expand All @@ -29,6 +32,7 @@
<ItemGroup>
<PackageReference Include="DiscordRichPresence" Version="1.0.175" />
<PackageReference Include="log4net" Version="2.0.14" />
<PackageReference Include="MdXaml_migfree" Version="1.13.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

Expand Down
6 changes: 6 additions & 0 deletions FloatTool/FloatTool.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<Compile Update="Views\SettingsWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Update="Views\UpdateWindow.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Update="Languages\Lang.ru.xaml">
Expand Down Expand Up @@ -46,5 +49,8 @@
<Page Update="Views\SettingsWindow.xaml">
<SubType>Designer</SubType>
</Page>
<Page Update="Views\UpdateWindow.xaml">
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
84 changes: 84 additions & 0 deletions FloatTool/Languages/Lang.cs.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--
- 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/>.
-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:v="clr-namespace:System;assembly=mscorlib">
<!-- Main window -->
<v:String x:Key="m_WeaponType">Typ zbraně:</v:String>
<v:String x:Key="m_Skin">Kůže:</v:String>
<v:String x:Key="m_Quality">Kvalitní:</v:String>
<v:String x:Key="m_Outcomes">výsledky:</v:String>
<v:String x:Key="m_SearchMode">Režim vyhledávání:</v:String>
<v:String x:Key="m_DesiredFloat">Požadovaný plovák:</v:String>
<v:String x:Key="m_Count">Počet:</v:String>
<v:String x:Key="m_Skip">Přeskočit:</v:String>
<v:String x:Key="m_Start">Start</v:String>
<v:String x:Key="m_Stop">Stop</v:String>
<v:String x:Key="m_FindOne">Najdi jednu</v:String>
<v:String x:Key="m_Sort">Seřadit</v:String>
<v:String x:Key="m_Descending">Klesající</v:String>
<v:String x:Key="m_ThreadCount">Počet vláken:</v:String>
<v:String x:Key="m_CraftRange">Rozsah řemesel:</v:String>
<v:String x:Key="m_CurrentSpeed">Aktuální rychlost:</v:String>
<v:String x:Key="m_CombinationsPerSecond">kombinace/sekundu</v:String>
<v:String x:Key="m_CheckedCombinations">Kontrolované kombinace:</v:String>
<v:String x:Key="m_SkinNotFound">Chyba! Tato kůže nemůže mít tuto kvalitu.</v:String>

<!-- Settings window -->
<v:String x:Key="m_Settings">Nastavení</v:String>
<v:String x:Key="m_Language">Jazyk:</v:String>
<v:String x:Key="m_Currency">Měna:</v:String>
<v:String x:Key="m_Theme">Téma:</v:String>
<v:String x:Key="m_GetThemes">Získejte témata</v:String>
<v:String x:Key="m_OpenThemesFolder">Otevřete složku motivů</v:String>
<v:String x:Key="m_EnableSound">Povolit zvuk</v:String>
<v:String x:Key="m_CheckForUpdates">Kontrola aktualizací</v:String>

<!-- Benchmark window -->
<v:String x:Key="m_Benchmark">Benchmark</v:String>
<v:String x:Key="m_MultipleThreads">Více vláken</v:String>
<v:String x:Key="m_SingleThread">Jedno vlákno</v:String>
<v:String x:Key="m_StartBenchmark">Spustit benchmark</v:String>
<v:String x:Key="m_Update">Aktualizace</v:String>
<v:String x:Key="m_Threads">Vlákna</v:String>
<v:String x:Key="m_Thread">Vlákno</v:String>
<v:String x:Key="m_PublishResult">Zveřejnit výsledek</v:String>

<!-- Combination -->
<v:String x:Key="m_Copy">kopírovat</v:String>
<v:String x:Key="m_PossibleFloat">Možný plovák:</v:String>
<v:String x:Key="m_Ingredients">Ingredience:</v:String>
<v:String x:Key="m_Price">Cena:</v:String>

<!-- Discord RPC -->
<v:String x:Key="m_SettingUpSearch">Nastavení vyhledávání</v:String>
<v:String x:Key="m_Benchmarking">Benchmarking</v:String>
<v:String x:Key="m_Searching">Hledání</v:String>

<!-- Status bar -->
<v:String x:Key="m_SearchingSkin">Hledání skinu na trhu</v:String>
<v:String x:Key="m_GettingFloats">Získávání plavidel z tržiště</v:String>
<v:String x:Key="m_ErrorCouldntGetFloats">Chyba! Nepodařilo se získat plováky z tržiště</v:String>
<v:String x:Key="m_ErrorLessThan10">Chyba! Z tržiště se nepodařilo získat více než 10 plaváků</v:String>
<v:String x:Key="m_StartingUpSearch">Spouštění vyhledávání</v:String>
<v:String x:Key="m_FinishedSearching">Hledání dokončeno</v:String>

<!-- Update window -->
<v:String x:Key="m_UpdateAvailable">Aktualizace k dispozici</v:String>
<v:String x:Key="m_Later">Později</v:String>
<v:String x:Key="m_DoNotAsk">Neptej se</v:String>
</ResourceDictionary>
Loading

0 comments on commit c0514a6

Please sign in to comment.