fixes + improved crash handler

This commit is contained in:
WeeXnes 2023-06-08 17:58:44 +02:00
parent f623fd79f2
commit e1351cc756
10 changed files with 129 additions and 19 deletions

View file

@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Windows;
using System.IO;
using System.Windows.Media;
using Newtonsoft.Json.Linq;
using Nocksoft.IO.ConfigFiles;
using WeeXnes.Core;
@ -17,6 +18,7 @@ namespace WeeXnes
/// </summary>
public partial class App
{
public static bool DebugMode = false;
private void SetExceptionHandler()
{
AppDomain currentDomain = default(AppDomain);
@ -30,6 +32,7 @@ namespace WeeXnes
{
writer.WriteLine(ex.ToString());
}
new FluentMessageBox(ex.Message).ShowDialog();
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
@ -142,7 +145,7 @@ namespace WeeXnes
);
newItem.Filename = file.Name;
KeyManagerView.Data.KeyItemsList.Add(newItem);
WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded");
WeeXnes.Core.CustomConsole.WriteLineVerbose(file.Name + " loaded");
}
catch (Exception ex)
@ -173,9 +176,10 @@ namespace WeeXnes
private void CheckForDebugMode()
{
#if DEBUG
#if DEBUG
DebugMode = true;
HandleLaunchArguments.arg_enableConsole();
#endif
#endif
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using VanillaConsole = System.Console;
@ -33,14 +34,11 @@ namespace WeeXnes.Core
ConsoleColor color,
ConsoleColor foregroundColor = ConsoleColor.White)
{
try
{
VanillaConsole.OutputEncoding = Encoding.UTF8;
}
catch (Exception ex)
{
VanillaConsole.WriteLine("error setting OutputEncoding to UTF8");
}
if(!App.DebugMode)
return;
VanillaConsole.OutputEncoding = Encoding.UTF8;
ConsoleColor prevColor = VanillaConsole.BackgroundColor;
ConsoleColor prevForeColor = VanillaConsole.ForegroundColor;
if (Data.Colors.colored_output)
@ -64,6 +62,13 @@ namespace WeeXnes.Core
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,VanillaConsole.BackgroundColor, ConsoleColor.White);
}
public static void WriteLineVerbose(string text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null,
[CallerFilePath] string filePath = null)
{
ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + Path.GetFileName(filePath) + "|" + caller + "|" + lineNumber + ") " + text,VanillaConsole.BackgroundColor, ConsoleColor.White);
}
public static void WriteLine(float text,
[CallerLineNumber] int lineNumber = 0,
[CallerMemberName] string caller = null)

View file

@ -39,5 +39,10 @@ namespace WeeXnes.Core
}
File.WriteAllLines(filepath, stringArray, Encoding.UTF8);
}
public static void ThrowTestException()
{
throw new NotImplementedException();
}
}
}

View file

@ -8,7 +8,7 @@ namespace WeeXnes.Core
{
public class Information
{
public const string Version = "4.3.3";
public const string Version = "4.3.4";
public const string EncryptionHash = "8zf5#RdyQ]$4x4_";
public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest";
}

View file

@ -19,16 +19,16 @@
SelectionChanged="ListviewKeys_OnSelectionChanged">
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove"
Name="btn_context_remove"
Click="ContextMenu_Remove"/>
<Separator />
<MenuItem Header="Export"
Name="btn_context_export"
Click="ContextMenu_Export"/>
<MenuItem Header="Import"
Name="btn_context_import"
Click="ContextMenu_Import"/>
<Separator />
<MenuItem Header="Remove"
Name="btn_context_remove"
Click="ContextMenu_Remove"/>
</ContextMenu>
</ListView.ContextMenu>

View file

@ -20,8 +20,25 @@
<TextBlock Text="(will auto close after saving)" FontSize="10" Foreground="White"
HorizontalAlignment="Center"/>
<ui:TextBox Name="TextboxKeyPath" PlaceholderText="Key Files Path" Margin="0,4"/>
<ui:TextBox Name="TextboxRPCPath" PlaceholderText="Client ID" Margin="0,4"/>
<ui:TextBox Name="TextboxKeyPath" PlaceholderText="Key Files Path" Margin="0,4">
<ui:TextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Select Folder for Key Files"
Name="btn_context_selFolderKF"
Click="ContextMenu_SelectKfFolder"/>
</ContextMenu>
</ui:TextBox.ContextMenu>
</ui:TextBox>
<ui:TextBox Name="TextboxRPCPath" PlaceholderText="Client ID" Margin="0,4">
<ui:TextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Select Folder for RPC Files"
Name="btn_context_selFolderRPC"
Click="ContextMenu_SelectRpcFolder"
/>
</ContextMenu>
</ui:TextBox.ContextMenu>
</ui:TextBox>
</StackPanel>
</ScrollViewer>

View file

@ -1,7 +1,11 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using WeeXnes.Core;
using MessageBox = System.Windows.MessageBox;
using OpenFileDialog = Microsoft.Win32.OpenFileDialog;
using TextBox = System.Windows.Controls.TextBox;
namespace WeeXnes.Views.Settings
{
@ -29,5 +33,29 @@ namespace WeeXnes.Views.Settings
Global.AppDataPathKEY.Value = TextboxKeyPath.Text;
Global.ForceClose();
}
private void ContextMenu_SelectKfFolder(object sender, RoutedEventArgs e)
{
CallOpenFolderDialog(TextboxKeyPath);
}
private void ContextMenu_SelectRpcFolder(object sender, RoutedEventArgs e)
{
CallOpenFolderDialog(TextboxRPCPath);
}
private void CallOpenFolderDialog(TextBox textBoxToChange)
{
using(var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
textBoxToChange.Text = fbd.SelectedPath;
}
}
}
}
}

View file

@ -0,0 +1,33 @@
<ui:UiWindow x:Class="WeeXnes.Views.Settings.FluentMessageBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WeeXnes.Views.Settings"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
mc:Ignorable="d"
Title="" Height="200" Width="600"
Background="{DynamicResource ApplicationBackgroundBrush}"
ExtendsContentIntoTitleBar="True"
WindowBackdropType="Mica"
WindowStartupLocation="CenterScreen">
<Grid>
<ui:TitleBar
Grid.Row="0"
Title="Error"
ShowHelp="False"
ShowClose="True"
ShowMinimize="False"
ShowMaximize="False"
UseSnapLayout="True">
</ui:TitleBar>
<Border Margin="0,0,0,0">
<StackPanel Orientation="Vertical" VerticalAlignment="Center">
<Label Content="Oh no! an error has occurred" Foreground="White" HorizontalAlignment="Center" FontSize="25"/>
<Label Content="full exception log has been dumped into error__log.txt" Foreground="White" HorizontalAlignment="Center" FontSize="12"/>
<Label Content="" Name="ErrorDump" Foreground="Gray" HorizontalAlignment="Center" FontSize="12" Padding="0,15,0,0"/>
</StackPanel>
</Border>
</Grid>
</ui:UiWindow>

View file

@ -0,0 +1,14 @@
using System.Windows;
using Wpf.Ui.Controls;
namespace WeeXnes.Views.Settings
{
public partial class FluentMessageBox : UiWindow
{
public FluentMessageBox(string messageContent)
{
InitializeComponent();
ErrorDump.Content = "Exception: " + messageContent;
}
}
}

View file

@ -4,7 +4,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Version>4.3.3</Version>
<Version>4.3.4</Version>
<ProjectGuid>{4B33CEE7-C74D-43B9-B99A-8B273D5195BC}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>WeeXnes</RootNamespace>
@ -98,6 +98,9 @@
<Compile Include="Views\Settings\ChangePathsView.xaml.cs">
<DependentUpon>ChangePathsView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\FluentMessageBox.xaml.cs">
<DependentUpon>FluentMessageBox.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Settings\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
@ -127,6 +130,7 @@
<Page Include="Views\Home\HomeView.xaml" />
<Page Include="Views\KeyManager\KeyManagerView.xaml" />
<Page Include="Views\Settings\ChangePathsView.xaml" />
<Page Include="Views\Settings\FluentMessageBox.xaml" />
<Page Include="Views\Settings\SettingsView.xaml" />
<Page Include="Views\Settings\UpdateFoundView.xaml" />
</ItemGroup>