added ability to change save paths for RPC and Key files

This commit is contained in:
WeeXnes 2023-01-05 22:08:09 +01:00
parent b95fb58925
commit 287dffbb5d
11 changed files with 176 additions and 14 deletions

View file

@ -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

View file

@ -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<string> AppDataPathRPC = new UpdateVar<string>();
public static UpdateVar<string> AppDataPathKEY = new UpdateVar<string>();
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);
}
}
}

View file

@ -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
);
};
}
}
}

View file

@ -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");
}

View file

@ -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,

View file

@ -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)
{

View file

@ -0,0 +1,49 @@
<Page x:Class="WeeXnes.Views.Settings.ChangePathsView"
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="ChangePathsView" Height="Auto" Width="Auto"
Loaded="ChangePathsView_OnLoaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="45"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="0">
<StackPanel Orientation="Vertical">
<TextBlock Text="Requires Restart after changing!!!" Foreground="White"
HorizontalAlignment="Center"/>
<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"/>
</StackPanel>
</ScrollViewer>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ui:Button
Padding="24,6"
HorizontalAlignment="Center"
Content="Cancel"
Icon="CaretLeft24"
Name="ButtonCancelDialog"
Click="ButtonCancelDialog_OnClick"/>
<ui:Button Grid.Column="1"
Padding="24,6"
HorizontalAlignment="Center"
Content="Save"
Icon="SaveMultiple24"
Name="ButtonSaveDialog"
Click="ButtonSaveDialog_OnClick"/>
</Grid>
</Grid>
</Page>

View file

@ -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();
}
}
}

View file

@ -29,7 +29,7 @@
<ui:CardAction Icon="LinkSquare20"
Name="ButtonCreateStartMenuShortcut"
Click="ButtonCreateStartMenuShortcut_OnClick"
Margin="0,10">
Margin="0,10,0,0">
<StackPanel>
<TextBlock
Margin="0,0,0,4"
@ -38,6 +38,18 @@
/>
</StackPanel>
</ui:CardAction>
<ui:CardAction Icon="Folder32"
Name="ChangePathsButton"
Click="ChangePathsButton_OnClick"
Margin="0,10">
<StackPanel>
<TextBlock
Margin="0,0,0,4"
FontWeight="Medium"
Text="Change paths for Key and RPC files"
/>
</StackPanel>
</ui:CardAction>
<TextBlock Text="Key Manager"
HorizontalAlignment="Center"
Foreground="White"/>

View file

@ -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));
}
}
}

View file

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