Skip to content

Commit

Permalink
Release 1.2.20210613.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BuIlDaLiBlE committed Jun 16, 2021
1 parent 79b1360 commit 971194b
Show file tree
Hide file tree
Showing 21 changed files with 1,650 additions and 2,365 deletions.
173 changes: 159 additions & 14 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -9,9 +11,19 @@ namespace BetterHI3Launcher
{
public partial class App : Application
{
public static readonly LauncherVersion LocalLauncherVersion = new LauncherVersion("1.2.20210613.0");
public static readonly string LauncherRootPath = AppDomain.CurrentDomain.BaseDirectory;
public static readonly string LocalLowPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low";
public static readonly string LauncherDataPath = Path.Combine(LocalLowPath, @"Bp\Better HI3 Launcher");
public static readonly string LauncherBackgroundsPath = Path.Combine(LauncherDataPath, "Backgrounds");
public static readonly string LauncherLogFile = Path.Combine(LauncherDataPath, "BetterHI3Launcher-latest.log");
public static readonly string LauncherTranslationsFile = Path.Combine(LauncherDataPath, "BetterHI3Launcher-translations.json");
public static string UserAgent = $"BetterHI3Launcher v{LocalLauncherVersion}";
public static string LauncherLanguage;
public static readonly string OSVersion = BpUtility.GetWindowsVersion();
public static readonly string OSLanguage = CultureInfo.CurrentUICulture.ToString();
static Mutex mutex = null;
public static Dictionary<string, string> TextStrings = new Dictionary<string, string>();
public static Mutex Mutex = null;

public App() : base()
{
Expand All @@ -21,13 +33,10 @@ public App() : base()
protected override void OnStartup(StartupEventArgs e)
{
var culture = CultureInfo.InvariantCulture;
bool createdNew = false;

try
{
mutex = new Mutex(true, "BetterHI3Launcher", out createdNew);

if(!createdNew)
Mutex = new Mutex(true, "BetterHI3Launcher", out bool new_mutex);
if(!new_mutex)
{
Shutdown();
}
Expand All @@ -40,27 +49,89 @@ protected override void OnStartup(StartupEventArgs e)
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
#if DEBUG
WinConsole.Initialize();
UserAgent += " [DEBUG]";
#endif
TextStrings_English();
switch(OSLanguage)
{
case "de-AT":
case "de-CH":
case "de-DE":
case "de-LI":
case "de-LU":
LauncherLanguage = "de";
break;
case "es-AR":
case "es-BO":
case "es-CL":
case "es-CO":
case "es-CR":
case "es-DO":
case "es-EC":
case "es-ES":
case "es-GT":
case "es-HN":
case "es-MX":
case "es-NI":
case "es-PA":
case "es-PE":
case "es-PR":
case "es-PY":
case "es-SV":
case "es-US":
case "es-UY":
LauncherLanguage = "es";
break;
case "pt-BR":
case "pt-PT":
LauncherLanguage = "pt";
break;
case "ru-RU":
case "uk-UA":
case "be-BY":
LauncherLanguage = "ru";
break;
case "sr-Cyrl-BA":
case "sr-Cyrl-CS":
case "sr-Cyrl-ME":
case "sr-Cyrl-RS":
case "sr-Latn-BA":
case "sr-Latn-CS":
case "sr-Latn-ME":
case "sr-Latn-RS":
LauncherLanguage = "sr";
break;
case "th-TH":
LauncherLanguage = "th";
break;
case "vi-VN":
LauncherLanguage = "vi";
break;
default:
LauncherLanguage = "en";
break;
}
base.OnStartup(e);
}

protected override void OnExit(ExitEventArgs e)
{
if(mutex != null)
if(Mutex != null)
{
mutex.Dispose();
Mutex.Dispose();
}
base.OnExit(e);
}

private void SetupUnhandledExceptionHandling()
{
// Catch exceptions from all threads in the AppDomain.
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
ShowUnhandledException(args.ExceptionObject as Exception, "AppDomain.CurrentDomain.UnhandledException");
AppDomain.CurrentDomain.UnhandledException += (sender, args) => ShowUnhandledException(args.ExceptionObject as Exception, "AppDomain.CurrentDomain.UnhandledException");

// Catch exceptions from each AppDomain that uses a task scheduler for async operations.
TaskScheduler.UnobservedTaskException += (sender, args) =>
ShowUnhandledException(args.Exception, "TaskScheduler.UnobservedTaskException");
TaskScheduler.UnobservedTaskException += (sender, args) => ShowUnhandledException(args.Exception, "TaskScheduler.UnobservedTaskException");

// Catch exceptions from a single specific UI dispatcher thread.
Dispatcher.UnhandledException += (sender, args) =>
Expand All @@ -74,13 +145,87 @@ private void SetupUnhandledExceptionHandling()
};
}

void ShowUnhandledException(Exception e, string unhandledExceptionType)
private void ShowUnhandledException(Exception e, string unhandledExceptionType)
{
if(unhandledExceptionType == "TaskScheduler.UnobservedTaskException")
{
return;
}

MessageBox.Show($"Unhandled exception occurred. Please report this.\n\n{e}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
string msg = $"CRITICAL ERROR: Unhandled exception occurred. Stack trace:\n{e}";
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine('\n' + msg);
Directory.CreateDirectory(LauncherDataPath);
if(File.Exists(LauncherLogFile))
{
File.SetAttributes(LauncherLogFile, File.GetAttributes(LauncherLogFile) & ~FileAttributes.ReadOnly);
}
File.AppendAllText(LauncherLogFile, '\n' + msg);
if(MessageBox.Show(TextStrings["msgbox_unhandled_exception_msg"], TextStrings["msgbox_generic_error_title"], MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
{
BpUtility.StartProcess(LauncherLogFile, null, null, true);
}
Current.Shutdown();
}

public struct LauncherVersion
{
private int major, minor, date, hotfix;

internal LauncherVersion(int _major, int _minor, int _date, int _hotfix)
{
major = _major;
minor = _minor;
date = _date;
hotfix = _hotfix;
}

internal LauncherVersion(string _version)
{
string[] _version_strings = _version.Split('.');
if(_version_strings.Length != 4)
{
major = 0;
minor = 0;
date = 0;
hotfix = 0;
return;
}

major = int.Parse(_version_strings[0]);
minor = int.Parse(_version_strings[1]);
date = int.Parse(_version_strings[2]);
hotfix = int.Parse(_version_strings[3]);
}

internal bool IsNewerThan(LauncherVersion _other_version)
{
if(major >= _other_version.major && minor >= _other_version.minor && date >= _other_version.date)
{
if(major > _other_version.major)
{
return true;
}
else if(minor > _other_version.minor)
{
return true;
}
else if(date > _other_version.date)
{
return true;
}
else if(hotfix > _other_version.hotfix)
{
return true;
}
}
return false;
}

public override string ToString()
{
return $"{major}.{minor}.{date}.{hotfix}";
}
}
}
}
Binary file added Assets/Images/BackgroundShadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Images/Checkbox_Disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 7 additions & 12 deletions BetterHI3Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="SharpCompress, Version=0.28.2.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>packages\SharpCompress.0.28.2\lib\netstandard2.0\SharpCompress.dll</HintPath>
<Reference Include="SharpCompress, Version=0.28.3.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>packages\SharpCompress.0.28.3\lib\netstandard2.0\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
Expand Down Expand Up @@ -194,8 +194,8 @@
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="XamlAnimatedGif, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\XamlAnimatedGif.1.2.3\lib\net45\XamlAnimatedGif.dll</HintPath>
<Reference Include="XamlAnimatedGif, Version=2.0.0.0, Culture=neutral, PublicKeyToken=20a987d8023d9690, processorArchitecture=MSIL">
<HintPath>packages\XamlAnimatedGif.2.0.0\lib\net45\XamlAnimatedGif.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -222,14 +222,7 @@
<Compile Include="DialogWindow.xaml.cs">
<DependentUpon>DialogWindow.xaml</DependentUpon>
</Compile>
<Compile Include="TextStrings_de.cs" />
<Compile Include="TextStrings_en.cs" />
<Compile Include="TextStrings_es.cs" />
<Compile Include="TextStrings_pt.cs" />
<Compile Include="TextStrings_ru.cs" />
<Compile Include="TextStrings_sr.cs" />
<Compile Include="TextStrings_th.cs" />
<Compile Include="TextStrings_vi.cs" />
<Compile Include="Utility\PartialZip\Exceptions\PartialZipFileNotFoundException.cs" />
<Compile Include="Utility\PartialZip\Exceptions\PartialZipNotSupportedException.cs" />
<Compile Include="Utility\PartialZip\Exceptions\PartialZipParsingException.cs" />
Expand Down Expand Up @@ -297,11 +290,13 @@
<Resource Include="Assets\Images\Button_Minimize.png" />
<Resource Include="Assets\Images\Button_Minimize_Highlighted.png" />
<Resource Include="Assets\Images\Button_Minimize_Pressed.png" />
<Resource Include="Assets\Images\BackgroundShadow.png" />
<Resource Include="Assets\Images\BackgroundImage.png" />
<Resource Include="Assets\Images\HoV_Dance.gif" />
<Resource Include="Assets\Images\Window_Dialog.png" />
<Resource Include="Assets\Images\Checkbox_Off.png" />
<Resource Include="Assets\Images\Checkbox_On.png" />
<Resource Include="Assets\Images\Checkbox_Off.png" />
<Resource Include="Assets\Images\Checkbox_Disabled.png" />
<Resource Include="Assets\Images\Button_Preload.png" />
<Resource Include="Assets\Images\Button_Preload_Checkmark.png" />
<Resource Include="Assets\Images\Button_Preload_Circle.png" />
Expand Down
82 changes: 81 additions & 1 deletion DialogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,93 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Width" Value="24"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<StackPanel Orientation="Horizontal">
<Image x:Name="Image" Source="/Assets/Images/Checkbox_On.png"/>
<ContentPresenter/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_On.png"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_Off.png"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_Disabled.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="RadioButtonStyle" TargetType="{x:Type RadioButton}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Width" Value="21"/>
<Setter Property="Height" Value="16"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="UseLayoutRounding" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<StackPanel Orientation="Horizontal">
<Image x:Name="Image" Source="/Assets/Images/Checkbox_On.png"/>
<ContentPresenter/>
</StackPanel>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_On.png"/>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_Off.png"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Image" Property="Source" Value="/Assets/Images/Checkbox_Disabled.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid Width="576" Height="307">
<Image Source="Assets/Images/Window_Dialog.png"/>
<TextBlock Name="DialogTitle" VerticalAlignment="Top" Margin="85,29,85,0" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="18" TextAlignment="Center"/>
<ScrollViewer VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,25" Width="500" Height="135" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ScrollViewer Name="DialogMessageScrollViewer" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,0,0,25" Width="500" Height="135" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<TextBlock Name="DialogMessage" VerticalAlignment="Center" HorizontalAlignment="Center" MaxWidth="500" MaxHeight="147" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="16" TextAlignment="Center" TextWrapping="Wrap"/>
</ScrollViewer>
<StackPanel Name="UninstallStackPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,25,0,0" Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<CheckBox Name="UninstallGameFilesCheckBox" Style="{DynamicResource CheckBoxStyle}" IsChecked="True" Click="UninstallCheckBox_Click" x:FieldModifier="public"/>
<TextBlock Name="UninstallGameFilesLabel" VerticalAlignment="Center" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="16"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="UninstallGameCacheCheckBox" Style="{DynamicResource CheckBoxStyle}" IsChecked="True" Click="UninstallCheckBox_Click" x:FieldModifier="public"/>
<TextBlock Name="UninstallGameCacheLabel" VerticalAlignment="Center" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="16"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<CheckBox Name="UninstallGameSettingsCheckBox" Style="{DynamicResource CheckBoxStyle}" Width="24" Height="16" Margin="5" IsChecked="True" Click="UninstallCheckBox_Click" x:FieldModifier="public"/>
<TextBlock Name="UninstallGameSettingsLabel" VerticalAlignment="Center" Foreground="White" FontFamily="{DynamicResource Font}" FontSize="16"/>
</StackPanel>
</StackPanel>
<StackPanel Name="CustomBackgroundStackPanel" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,35,0,0" Visibility="Collapsed">
<StackPanel Orientation="Horizontal">
<RadioButton Name="CustomBackgroundEditRadioButton" GroupName="CustomBackgroundActionChoice" Style="{DynamicResource RadioButtonStyle}" IsChecked="True" Click="CustomBackgroundRadioButton_Click" x:FieldModifier="public"/>
<TextBlock Name="CustomBackgroundEditLabel" Foreground="White" VerticalAlignment="Center" FontFamily="{DynamicResource Font}" FontSize="16"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<RadioButton Name="CustomBackgroundDeleteRadioButton" GroupName="CustomBackgroundActionChoice" Style="{DynamicResource RadioButtonStyle}" Click="CustomBackgroundRadioButton_Click" x:FieldModifier="public"/>
<TextBlock Name="CustomBackgroundDeleteLabel" Foreground="White" VerticalAlignment="Center" FontFamily="{DynamicResource Font}" FontSize="16"/>
</StackPanel>
</StackPanel>
<Button Name="CloseButton" Style="{DynamicResource CloseButtonStyle}" Margin="0,23,33,0" Click="CloseButton_Click"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="36">
<Button Name="ConfirmButton" Style="{DynamicResource ButtonStyle}" Click="ConfirmButton_Click"/>
Expand Down
Loading

0 comments on commit 971194b

Please sign in to comment.