From db8125de84d4f72c13820028797a858b1d6ef992 Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Mon, 28 Nov 2022 17:14:52 +0100 Subject: [PATCH] re-added autostart --- WeeXnes/App.xaml.cs | 4 ++ WeeXnes/Core/Global.cs | 2 +- WeeXnes/Core/HandleLaunchArguments.cs | 6 +- WeeXnes/Core/SaveSettingsHandler.cs | 13 ++++ WeeXnes/MainWindow.xaml | 19 ++++-- WeeXnes/MainWindow.xaml.cs | 23 +++++++ WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml | 1 + WeeXnes/Views/Settings/SettingsView.xaml | 5 ++ WeeXnes/Views/Settings/SettingsView.xaml.cs | 70 ++++++++++++++++++++ WeeXnes/WeeXnes.csproj | 2 +- 10 files changed, 136 insertions(+), 9 deletions(-) diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs index 383dc18..c20cec4 100644 --- a/WeeXnes/App.xaml.cs +++ b/WeeXnes/App.xaml.cs @@ -36,6 +36,10 @@ namespace WeeXnes Convert.ToBoolean(SettingsView.Data.settingsFile.GetValue( SaveSettingsHandler.Data.KeyManager.Section, SaveSettingsHandler.Data.KeyManager.CensorKeys)); + SettingsView.Data.Autostart.Value = + Convert.ToBoolean(SettingsView.Data.settingsFile.GetValue( + SaveSettingsHandler.Data.General.Section, + SaveSettingsHandler.Data.General.Autostart)); } diff --git a/WeeXnes/Core/Global.cs b/WeeXnes/Core/Global.cs index 3884aea..31826ee 100644 --- a/WeeXnes/Core/Global.cs +++ b/WeeXnes/Core/Global.cs @@ -6,7 +6,7 @@ namespace WeeXnes.Core { public class Information { - public const string Version = "4.0.0"; + public const string Version = "4.0.1"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; } diff --git a/WeeXnes/Core/HandleLaunchArguments.cs b/WeeXnes/Core/HandleLaunchArguments.cs index e1dde45..ce7b854 100644 --- a/WeeXnes/Core/HandleLaunchArguments.cs +++ b/WeeXnes/Core/HandleLaunchArguments.cs @@ -6,12 +6,16 @@ namespace WeeXnes.Core { public class HandleLaunchArguments { + public static class Data + { + public static bool Autostart = false; + } private const int ATTACH_PARENT_PROCESS = -1; [DllImport("kernel32.dll")] private static extern bool AttachConsole(int dwProcessId); public static void arg_autostart() { - + Data.Autostart = true; } public static void arg_debugMode() { diff --git a/WeeXnes/Core/SaveSettingsHandler.cs b/WeeXnes/Core/SaveSettingsHandler.cs index cb632a3..7aa0a27 100644 --- a/WeeXnes/Core/SaveSettingsHandler.cs +++ b/WeeXnes/Core/SaveSettingsHandler.cs @@ -9,6 +9,11 @@ namespace WeeXnes.Core public static class Data { //Layout-Names for INIFiles + public static class General + { + public const string Section = "GENERAL"; + public const string Autostart = "Autostart"; + } public static class KeyManager { public const string Section = "KEY_MANAGER"; @@ -38,6 +43,14 @@ namespace WeeXnes.Core KeyManagerView.Data.censorKeys.Value.ToString() ); }; + SettingsView.Data.Autostart.ValueChanged += () => + { + SettingsView.Data.settingsFile.SetValue( + Data.General.Section, + Data.General.Autostart, + SettingsView.Data.Autostart.Value.ToString() + ); + }; } } } \ No newline at end of file diff --git a/WeeXnes/MainWindow.xaml b/WeeXnes/MainWindow.xaml index b74a760..f6750b8 100644 --- a/WeeXnes/MainWindow.xaml +++ b/WeeXnes/MainWindow.xaml @@ -26,7 +26,7 @@ Grid.Row="0" Title="WeeXnes Suite" ForceShutdown="False" - MinimizeToTray="False" + MinimizeToTray="True" ShowHelp="False" ShowClose="True" ShowMaximize="True" @@ -35,12 +35,16 @@ - @@ -60,6 +64,7 @@ Content="Home" Icon="Home24" PageTag="home" + Name="ButtonHome" PageType="{x:Type home:HomeView}"/> + PageType="{x:Type discordrpc:DiscordRPCView}" + Loaded="RPCBtn_OnLoaded"/> + Margin="8,0,0,0" + /> diff --git a/WeeXnes/MainWindow.xaml.cs b/WeeXnes/MainWindow.xaml.cs index 8130e06..37851ea 100644 --- a/WeeXnes/MainWindow.xaml.cs +++ b/WeeXnes/MainWindow.xaml.cs @@ -9,8 +9,10 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using WeeXnes.Core; +using WeeXnes.Views.DiscordRPC; using Wpf.Ui.Mvvm.Services; using Button = System.Windows.Controls.Button; +using ButtonBase = System.Windows.Controls.Primitives.ButtonBase; using MessageBox = System.Windows.MessageBox; namespace WeeXnes @@ -26,6 +28,27 @@ namespace WeeXnes } + + private void RPCBtn_OnLoaded(object sender, RoutedEventArgs e) + { + if (HandleLaunchArguments.Data.Autostart) + { + ButtonRpc.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); + MainFrame.Source = new Uri("/Views/DiscordRPC/RunRPCView.xaml",UriKind.Relative); + WindowState = WindowState.Minimized; + } + } + + private void ContextStartRpc_OnClick(object sender, RoutedEventArgs e) + { + ButtonRpc.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); + MainFrame.Source = new Uri("/Views/DiscordRPC/RunRPCView.xaml",UriKind.Relative); + } + + private void ContextStopRpc_OnClick(object sender, RoutedEventArgs e) + { + ButtonHome.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent)); + } } } diff --git a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml index 533e44a..69d5760 100644 --- a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml +++ b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml @@ -6,6 +6,7 @@ xmlns:local="clr-namespace:WeeXnes.Views.DiscordRPC" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" mc:Ignorable="d" + Tag="RPCView" Title="DiscordRPCView" Height="Auto" Width="Auto"> diff --git a/WeeXnes/Views/Settings/SettingsView.xaml b/WeeXnes/Views/Settings/SettingsView.xaml index fb70ab7..c63844f 100644 --- a/WeeXnes/Views/Settings/SettingsView.xaml +++ b/WeeXnes/Views/Settings/SettingsView.xaml @@ -36,6 +36,11 @@ Name="CheckboxCensorKeys" Checked="CheckboxCensorKeys_OnChecked" Unchecked="CheckboxCensorKeys_OnUnchecked"/> + + diff --git a/WeeXnes/Views/Settings/SettingsView.xaml.cs b/WeeXnes/Views/Settings/SettingsView.xaml.cs index 045857c..e2348bf 100644 --- a/WeeXnes/Views/Settings/SettingsView.xaml.cs +++ b/WeeXnes/Views/Settings/SettingsView.xaml.cs @@ -18,6 +18,7 @@ namespace WeeXnes.Views.Settings { public static INIFile settingsFile = new INIFile(Global.AppDataPath + "\\" + Global.SettingsFile, true); public static GithubApiResponse updateResponse = null; + public static UpdateVar Autostart = new UpdateVar(); } public SettingsView() { @@ -28,6 +29,9 @@ namespace WeeXnes.Views.Settings private void LoadSettingsToGui() { CheckboxCensorKeys.IsChecked = KeyManagerView.Data.censorKeys.Value; + CheckboxAutostartRpc.IsChecked = Data.Autostart.Value; + + SetCheckboxAutostartRpc(); } private void CheckboxCensorKeys_OnChecked(object sender, RoutedEventArgs e) { @@ -99,5 +103,71 @@ namespace WeeXnes.Views.Settings Console.WriteLine(ex); } } + + void SetCheckboxAutostartRpc() + { + CheckboxAutostartRpc.Checked += CheckboxAutostartRpc_OnChecked; + CheckboxAutostartRpc.Unchecked += CheckboxAutostartRpc_OnUnchecked; + } + void UnsetCheckboxAutostartRpc() + { + CheckboxAutostartRpc.Checked -= CheckboxAutostartRpc_OnChecked; + CheckboxAutostartRpc.Unchecked -= CheckboxAutostartRpc_OnUnchecked; + } + + void SwitchAutostartRpc(bool enable) + { + UnsetCheckboxAutostartRpc(); + + + if (enable) + { + bool proc_suc; + try + { + Process uacpromp = Process.Start("WeeXnes_UAC.exe", "-EnableAutostart"); + uacpromp.WaitForExit(); + proc_suc = true; + } + catch (Exception ex) + { + Console.WriteLine(ex); + proc_suc = false; + } + + Data.Autostart.Value = proc_suc; + CheckboxAutostartRpc.IsChecked = proc_suc; + } + else + { + bool proc_suc; + try + { + Process uacpromp = Process.Start("WeeXnes_UAC.exe", "-DisableAutostart"); + uacpromp.WaitForExit(); + proc_suc = true; + } + catch (Exception ex) + { + Console.WriteLine(ex); + proc_suc = false; + } + + Data.Autostart.Value = !proc_suc; + CheckboxAutostartRpc.IsChecked = !proc_suc; + } + + + SetCheckboxAutostartRpc(); + } + private void CheckboxAutostartRpc_OnChecked(object sender, RoutedEventArgs e) + { + SwitchAutostartRpc(true); + } + + private void CheckboxAutostartRpc_OnUnchecked(object sender, RoutedEventArgs e) + { + SwitchAutostartRpc(false); + } } } \ No newline at end of file diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index 02d4568..1398f0d 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - 4.0.0 + 4.0.1 {4B33CEE7-C74D-43B9-B99A-8B273D5195BC} WinExe WeeXnes