diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs index 5a04a19..79bdca4 100644 --- a/WeeXnes/App.xaml.cs +++ b/WeeXnes/App.xaml.cs @@ -58,12 +58,38 @@ namespace WeeXnes SaveSettingsHandler.Data.KeyManager.Section, SaveSettingsHandler.Data.KeyManager.CensorKeys)); + //Load paths + + string customRpcPath = SettingsView.Data.settingsFile.GetValue( + SaveSettingsHandler.Data.General.Section, + SaveSettingsHandler.Data.General.RpcFilesPath + ); + if (!String.IsNullOrEmpty(customRpcPath)) + { + Global.AppDataPathRPC.Value = customRpcPath; + } + else + { + Global.AppDataPathRPC.Value = Global.Defaults.DefaultPathRPC; + } + string customKeyPath = SettingsView.Data.settingsFile.GetValue( + SaveSettingsHandler.Data.General.Section, + SaveSettingsHandler.Data.General.KeyFilesPath + ); + if (!String.IsNullOrEmpty(customKeyPath)) + { + Global.AppDataPathKEY.Value = customKeyPath; + } + else + { + Global.AppDataPathKEY.Value = Global.Defaults.DefaultPathKEY; + } } private void LoadFiles() { - Functions.CheckFolderAndCreate(Global.AppDataPathRPC); - DirectoryInfo rpcDirectoryInfo = new DirectoryInfo(Global.AppDataPathRPC); + Functions.CheckFolderAndCreate(Global.AppDataPathRPC.Value); + DirectoryInfo rpcDirectoryInfo = new DirectoryInfo(Global.AppDataPathRPC.Value); foreach (var file in rpcDirectoryInfo.GetFiles("*.rpc")) { try @@ -78,8 +104,8 @@ namespace WeeXnes MessageBox.Show(file.Name + ": " + ex.Message); } } - Functions.CheckFolderAndCreate(Global.AppDataPathKEY); - DirectoryInfo keyDirectoryInfo = new DirectoryInfo(Global.AppDataPathKEY); + Functions.CheckFolderAndCreate(Global.AppDataPathKEY.Value); + DirectoryInfo keyDirectoryInfo = new DirectoryInfo(Global.AppDataPathKEY.Value); foreach (var file in keyDirectoryInfo.GetFiles("*.wx")) { try diff --git a/WeeXnes/Core/Global.cs b/WeeXnes/Core/Global.cs index 92a4d3c..00695a5 100644 --- a/WeeXnes/Core/Global.cs +++ b/WeeXnes/Core/Global.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; +using System.Windows.Forms; namespace WeeXnes.Core { public class Information { - public const string Version = "4.2.0"; + public const string Version = "4.2.1"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; } @@ -14,8 +16,18 @@ namespace WeeXnes.Core public class Global { public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes"); - public static string AppDataPathRPC = Path.Combine(AppDataPath, "RPC"); - public static string AppDataPathKEY = Path.Combine(AppDataPath, "Keys"); + public static UpdateVar AppDataPathRPC = new UpdateVar(); + public static UpdateVar AppDataPathKEY = new UpdateVar(); public static string SettingsFile = "settings.ini"; + public class Defaults + { + public static string DefaultPathRPC = Path.Combine(AppDataPath, "RPC"); + public static string DefaultPathKEY = Path.Combine(AppDataPath, "Keys"); + } + public static void ForceClose() + { + System.Windows.Forms.Application.Restart(); + Environment.Exit(0); + } } } \ No newline at end of file diff --git a/WeeXnes/Core/SaveSettingsHandler.cs b/WeeXnes/Core/SaveSettingsHandler.cs index fa9e5b8..c91c780 100644 --- a/WeeXnes/Core/SaveSettingsHandler.cs +++ b/WeeXnes/Core/SaveSettingsHandler.cs @@ -1,4 +1,8 @@ -using System.Collections.Specialized; +using System; +using System.Collections.Specialized; +using System.Net.Mime; +using System.Runtime.CompilerServices; +using System.Windows; using WeeXnes.Views.KeyManager; using WeeXnes.Views.Settings; @@ -12,6 +16,8 @@ namespace WeeXnes.Core public static class General { public const string Section = "GENERAL"; + public const string RpcFilesPath = "RpcFilesPath"; + public const string KeyFilesPath = "KeyFilesPath"; } public static class KeyManager { @@ -42,6 +48,22 @@ namespace WeeXnes.Core KeyManagerView.Data.censorKeys.Value.ToString() ); }; + Global.AppDataPathRPC.ValueChanged += () => + { + SettingsView.Data.settingsFile.SetValue( + Data.General.Section, + Data.General.RpcFilesPath, + Global.AppDataPathRPC.Value + ); + }; + Global.AppDataPathKEY.ValueChanged += () => + { + SettingsView.Data.settingsFile.SetValue( + Data.General.Section, + Data.General.KeyFilesPath, + Global.AppDataPathKEY.Value + ); + }; } } } \ No newline at end of file diff --git a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs index 8ade9f7..a654403 100644 --- a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs +++ b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs @@ -55,7 +55,7 @@ namespace WeeXnes.Views.DiscordRPC if(selectedCache == null) return; Data.Games.Remove(selectedCache); - File.Delete(Global.AppDataPathRPC + "\\" + selectedCache.UUID + ".rpc"); + File.Delete(Global.AppDataPathRPC.Value + "\\" + selectedCache.UUID + ".rpc"); } diff --git a/WeeXnes/Views/DiscordRPC/Game.cs b/WeeXnes/Views/DiscordRPC/Game.cs index d996664..6ec293b 100644 --- a/WeeXnes/Views/DiscordRPC/Game.cs +++ b/WeeXnes/Views/DiscordRPC/Game.cs @@ -158,7 +158,7 @@ namespace WeeXnes.Views.DiscordRPC public void Save() { - INIFile rpcFile = new INIFile(Global.AppDataPathRPC + "\\" + this.UUID + ".rpc", true); + INIFile rpcFile = new INIFile(Global.AppDataPathRPC.Value + "\\" + this.UUID + ".rpc", true); rpcFile.SetValue( SaveSettingsHandler.Data.DiscordRpcFiles.Section, SaveSettingsHandler.Data.DiscordRpcFiles.ProcessName, diff --git a/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs b/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs index 01b6f75..e144d39 100644 --- a/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs +++ b/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs @@ -40,7 +40,7 @@ namespace WeeXnes.Views.KeyManager tb_keyvalue.Text ); WXFile wxFile = new WXFile( - Global.AppDataPathKEY + "\\" + newKey.Filename); + Global.AppDataPathKEY.Value + "\\" + newKey.Filename); WXFile.Methods.WriteFile(newKey, wxFile); Data.KeyItemsList.Add(newKey); } @@ -65,7 +65,7 @@ namespace WeeXnes.Views.KeyManager Data.KeyItemsList.Remove(removeItem); try { - File.Delete(Global.AppDataPathKEY + "\\" + removeItem.Filename); + File.Delete(Global.AppDataPathKEY.Value + "\\" + removeItem.Filename); } catch (Exception ex) { diff --git a/WeeXnes/Views/Settings/ChangePathsView.xaml b/WeeXnes/Views/Settings/ChangePathsView.xaml new file mode 100644 index 0000000..82de67e --- /dev/null +++ b/WeeXnes/Views/Settings/ChangePathsView.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WeeXnes/Views/Settings/ChangePathsView.xaml.cs b/WeeXnes/Views/Settings/ChangePathsView.xaml.cs new file mode 100644 index 0000000..15ced7c --- /dev/null +++ b/WeeXnes/Views/Settings/ChangePathsView.xaml.cs @@ -0,0 +1,33 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using WeeXnes.Core; + +namespace WeeXnes.Views.Settings +{ + public partial class ChangePathsView : Page + { + public ChangePathsView() + { + InitializeComponent(); + } + + private void ChangePathsView_OnLoaded(object sender, RoutedEventArgs e) + { + TextboxKeyPath.Text = Global.AppDataPathKEY.Value; + TextboxRPCPath.Text = Global.AppDataPathRPC.Value; + } + + private void ButtonCancelDialog_OnClick(object sender, RoutedEventArgs e) + { + NavigationService.Navigate(new Uri("/Views/Settings/SettingsView.xaml",UriKind.Relative)); + } + + private void ButtonSaveDialog_OnClick(object sender, RoutedEventArgs e) + { + Global.AppDataPathRPC.Value = TextboxRPCPath.Text; + Global.AppDataPathKEY.Value = TextboxKeyPath.Text; + Global.ForceClose(); + } + } +} \ No newline at end of file diff --git a/WeeXnes/Views/Settings/SettingsView.xaml b/WeeXnes/Views/Settings/SettingsView.xaml index 358d05b..489feab 100644 --- a/WeeXnes/Views/Settings/SettingsView.xaml +++ b/WeeXnes/Views/Settings/SettingsView.xaml @@ -29,7 +29,7 @@ + Margin="0,10,0,0"> + + + + + diff --git a/WeeXnes/Views/Settings/SettingsView.xaml.cs b/WeeXnes/Views/Settings/SettingsView.xaml.cs index 7fcbd62..806a7e2 100644 --- a/WeeXnes/Views/Settings/SettingsView.xaml.cs +++ b/WeeXnes/Views/Settings/SettingsView.xaml.cs @@ -105,5 +105,9 @@ namespace WeeXnes.Views.Settings } } + private void ChangePathsButton_OnClick(object sender, RoutedEventArgs e) + { + NavigationService.Navigate(new Uri("/Views/Settings/ChangePathsView.xaml",UriKind.Relative)); + } } } \ No newline at end of file diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index a404d1e..6eb1648 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - 4.2.0 + 4.2.1 {4B33CEE7-C74D-43B9-B99A-8B273D5195BC} WinExe WeeXnes @@ -91,6 +91,9 @@ KeyManagerView.xaml + + ChangePathsView.xaml + SettingsView.xaml @@ -119,6 +122,7 @@ +