optimized settings

This commit is contained in:
WeeXnes 2022-04-29 00:59:16 +02:00
parent fddfd1ce6b
commit 4dde7eab20
6 changed files with 260 additions and 180 deletions

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using Nocksoft.IO.ConfigFiles; using Nocksoft.IO.ConfigFiles;
namespace WeeXnes.Core namespace WeeXnes.Core
@ -14,30 +15,152 @@ namespace WeeXnes.Core
public static string encryptionKey = "8zf5#RdyQ]$4x4_"; public static string encryptionKey = "8zf5#RdyQ]$4x4_";
public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes"); public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes");
public static string SettingsFileName = "settings.ini"; public static string SettingsFileName = "settings.ini";
public static string version = "2.4"; public static string version = "2.5";
public static bool isRpcRunning = false; public static bool info_isRpcRunning = false;
public static bool settings_alwaysOnTop;
public static bool settings_copySelectedToClipboard;
public static string settings_KeyManagerItemsPath_Default = AppDataPath + "\\" + "Keys";
public static bool settings_KeyManagerItemsPath_Bool = false;
public static string settings_KeyManagerItemsPath = settings_KeyManagerItemsPath_Default;
public static string settings_RpcItemsPath_Default = AppDataPath + "\\" + "RPC";
public static string settings_RpcItemsPath = settings_RpcItemsPath_Default;
public static bool settings_RpcItemsPath_Bool = false;
public static bool settings_RpcShowElapsedTime;
public static string settings_RpcDefaultClientID;
public static bool info_RpcAutoStart; public static bool info_RpcAutoStart;
public static UpdateVar<bool> settings_alwaysOnTop = new UpdateVar<bool>();
public static UpdateVar<bool> settings_copySelectedToClipboard = new UpdateVar<bool>();
public static string settings_KeyManagerItemsPath_Default = AppDataPath + "\\" + "Keys";
public static UpdateVar<string> settings_KeyManagerItemsPath = new UpdateVar<string>();
public static UpdateVar<bool> settings_KeyManagerItemsPath_Bool = new UpdateVar<bool>();
public static string settings_RpcItemsPath_Default = AppDataPath + "\\" + "RPC";
public static UpdateVar<string> settings_RpcItemsPath = new UpdateVar<string>();
public static UpdateVar<bool> settings_RpcItemsPath_Bool = new UpdateVar<bool>();
public static UpdateVar<bool> settings_RpcShowElapsedTime = new UpdateVar<bool>();
public static UpdateVar<string> settings_RpcDefaultClientID = new UpdateVar<string>();
public static UpdateVar<bool> settings_RpcAutoStart = new UpdateVar<bool>();
public static UpdateVar<string> searchbox_content = new UpdateVar<string>(); public static UpdateVar<string> searchbox_content = new UpdateVar<string>();
} }
public static class SettingsManager
{
private static INIFile SettingsFile = new INIFile(
Globals.AppDataPath + "\\" + Globals.SettingsFileName,
true
);
public static void start()
{
loadSettings();
setEventListeners();
}
public static void refresh()
{
}
private static void loadSettings()
{
Globals.settings_alwaysOnTop.Value = Convert.ToBoolean(SettingsFile.GetValue("general", "alwaysOnTop"));
Globals.settings_copySelectedToClipboard.Value = Convert.ToBoolean(SettingsFile.GetValue("KeyManager", "copySelectedToClipboard"));
Globals.settings_KeyManagerItemsPath_Bool.Value = Convert.ToBoolean(SettingsFile.GetValue("KeyManager", "KeyManagerItemsPath_Bool"));
if (Globals.settings_KeyManagerItemsPath_Bool.Value)
{
Globals.settings_KeyManagerItemsPath.Value = SettingsFile.GetValue("KeyManager", "KeyManagerItemsPath");
}
else
{
Globals.settings_KeyManagerItemsPath.Value = Globals.settings_KeyManagerItemsPath_Default;
}
Globals.settings_RpcShowElapsedTime.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "RpcShowElapsedTime"));
Globals.settings_RpcItemsPath_Bool.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "RpcItemsPath_Bool"));
if (Globals.settings_RpcItemsPath_Bool.Value)
{
Globals.settings_RpcItemsPath.Value = SettingsFile.GetValue("rpc", "RpcItemsPath");
}
else
{
Globals.settings_RpcItemsPath.Value = Globals.settings_RpcItemsPath_Default;
}
Globals.settings_RpcDefaultClientID.Value = SettingsFile.GetValue("rpc", "RpcDefaultClientID");
if (String.IsNullOrEmpty(Globals.settings_RpcDefaultClientID.Value))
{
Globals.settings_RpcDefaultClientID.Value = "605116707035676701";
}
}
private static void setEventListeners()
{
Globals.settings_KeyManagerItemsPath_Bool.ValueChanged += () =>
{
if (Globals.settings_KeyManagerItemsPath_Bool.Value)
{
SettingsFile.SetValue("KeyManager", "KeyManagerItemsPath_Bool", "true");
}
else
{
SettingsFile.SetValue("KeyManager", "KeyManagerItemsPath_Bool", "false");
}
};
Globals.settings_KeyManagerItemsPath.ValueChanged += () =>
{
if (Globals.settings_KeyManagerItemsPath_Bool.Value)
{
SettingsFile.SetValue("KeyManager", "KeyManagerItemsPath", Globals.settings_KeyManagerItemsPath.Value);
}
else
{
SettingsFile.SetValue("KeyManager", "KeyManagerItemsPath", "");
}
};
Globals.settings_RpcItemsPath_Bool.ValueChanged += () =>
{
if (Globals.settings_RpcItemsPath_Bool.Value)
{
SettingsFile.SetValue("rpc", "RpcItemsPath_Bool", "true");
}
else
{
SettingsFile.SetValue("rpc", "RpcItemsPath_Bool", "false");
}
};
Globals.settings_RpcItemsPath.ValueChanged += () =>
{
if (Globals.settings_RpcItemsPath_Bool.Value)
{
SettingsFile.SetValue("rpc", "RpcItemsPath", Globals.settings_RpcItemsPath.Value);
}
else
{
SettingsFile.SetValue("rpc", "RpcItemsPath", "");
}
};
Globals.settings_alwaysOnTop.ValueChanged += () =>
{
SettingsFile.SetValue("general","alwaysOnTop",Convert.ToString(Globals.settings_alwaysOnTop.Value));
};
Globals.settings_copySelectedToClipboard.ValueChanged += () =>
{
SettingsFile.SetValue("KeyManager","copySelectedToClipboard",Convert.ToString(Globals.settings_copySelectedToClipboard.Value));
};
Globals.settings_RpcDefaultClientID.ValueChanged += () =>
{
SettingsFile.SetValue("rpc", "RpcDefaultClientID", Globals.settings_RpcDefaultClientID.Value);
};
Globals.settings_RpcShowElapsedTime.ValueChanged += () =>
{
SettingsFile.SetValue("rpc", "RpcShowElapsedTime", Convert.ToString(Globals.settings_RpcShowElapsedTime.Value));
};
Globals.settings_RpcAutoStart.ValueChanged += () =>
{
SettingsFile.SetValue("rpc","RpcAutoStart", Convert.ToString(Globals.settings_RpcAutoStart.Value));
};
}
}
public static class funcs public static class funcs
{ {
public static bool IsDirectoryEmpty(string path) public static bool IsDirectoryEmpty(string path)

View file

@ -36,6 +36,7 @@ namespace WeeXnes.MVVM.View
public static UpdateVar<string> triggerLogupdate = new UpdateVar<string>(); public static UpdateVar<string> triggerLogupdate = new UpdateVar<string>();
public DiscordRpcView() public DiscordRpcView()
{ {
CheckFolders();
InitializeComponent(); InitializeComponent();
triggerLogupdate.ValueChanged += () => triggerLogupdate.ValueChanged += () =>
{ {
@ -48,6 +49,15 @@ namespace WeeXnes.MVVM.View
CheckForAutostart(); CheckForAutostart();
} }
public void CheckFolders()
{
if (!Directory.Exists(Globals.settings_RpcItemsPath.Value))
{
Directory.CreateDirectory(Globals.settings_RpcItemsPath.Value);
Console.WriteLine("Created settings_RpcItemsPath");
}
}
private void CheckForAutostart() private void CheckForAutostart()
{ {
if (Globals.info_RpcAutoStart) if (Globals.info_RpcAutoStart)
@ -83,7 +93,7 @@ namespace WeeXnes.MVVM.View
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{ {
Globals.isRpcRunning = true; Globals.info_isRpcRunning = true;
writeLog("Thread Started"); writeLog("Thread Started");
bool runWorker = true; bool runWorker = true;
int delay = 2000; int delay = 2000;
@ -110,7 +120,7 @@ namespace WeeXnes.MVVM.View
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ {
Globals.isRpcRunning = false; Globals.info_isRpcRunning = false;
foreach(Game game in Games) foreach(Game game in Games)
{ {
game.isRunning = false; game.isRunning = false;
@ -150,7 +160,7 @@ namespace WeeXnes.MVVM.View
public void generateNewGame() public void generateNewGame()
{ {
string filename = Guid.NewGuid().ToString() + ".rpc"; string filename = Guid.NewGuid().ToString() + ".rpc";
Game newGame = new Game(filename, generateIncrementalName(), null, Globals.settings_RpcDefaultClientID); Game newGame = new Game(filename, generateIncrementalName(), null, Globals.settings_RpcDefaultClientID.Value);
saveGameToFile(newGame); saveGameToFile(newGame);
} }
public string generateIncrementalName() public string generateIncrementalName()
@ -161,7 +171,7 @@ namespace WeeXnes.MVVM.View
} }
public void saveGameToFile(Game game) public void saveGameToFile(Game game)
{ {
INIFile rpcFile = new INIFile(Globals.settings_RpcItemsPath + "\\" + game.fileName, true); INIFile rpcFile = new INIFile(Globals.settings_RpcItemsPath.Value + "\\" + game.fileName, true);
rpcFile.SetValue("config", "name", game.Name); rpcFile.SetValue("config", "name", game.Name);
rpcFile.SetValue("config", "pname", game.ProcessName); rpcFile.SetValue("config", "pname", game.ProcessName);
rpcFile.SetValue("config", "id", game.id); rpcFile.SetValue("config", "id", game.id);
@ -177,7 +187,7 @@ namespace WeeXnes.MVVM.View
{ {
try try
{ {
File.Delete(Globals.settings_RpcItemsPath + "\\" + game.fileName); File.Delete(Globals.settings_RpcItemsPath.Value + "\\" + game.fileName);
} }
catch (Exception e) catch (Exception e)
{ {
@ -187,12 +197,12 @@ namespace WeeXnes.MVVM.View
} }
public void readRpcFileDirectory() public void readRpcFileDirectory()
{ {
bool Empty = funcs.IsDirectoryEmpty(Globals.settings_RpcItemsPath); bool Empty = funcs.IsDirectoryEmpty(Globals.settings_RpcItemsPath.Value);
List<Game> readGames = new List<Game>(); List<Game> readGames = new List<Game>();
if (!Empty) if (!Empty)
{ {
Console.WriteLine("RpcDir is not Empty, Reading content"); Console.WriteLine("RpcDir is not Empty, Reading content");
string[] files = Directory.GetFiles(Globals.settings_RpcItemsPath, "*.rpc", SearchOption.AllDirectories); string[] files = Directory.GetFiles(Globals.settings_RpcItemsPath.Value, "*.rpc", SearchOption.AllDirectories);
foreach (string file in files) foreach (string file in files)
{ {
INIFile rpcFile = new INIFile(file); INIFile rpcFile = new INIFile(file);

View file

@ -30,6 +30,7 @@ namespace WeeXnes.MVVM.View
public KeyManagerView() public KeyManagerView()
{ {
CheckForFolders();
InitializeComponent(); InitializeComponent();
Globals.searchbox_content.ValueChanged += () => { SearchboxChanged(); }; Globals.searchbox_content.ValueChanged += () => { SearchboxChanged(); };
} }
@ -118,10 +119,9 @@ namespace WeeXnes.MVVM.View
private void StackPanel_Loaded(object sender, RoutedEventArgs e) private void StackPanel_Loaded(object sender, RoutedEventArgs e)
{ {
KeyManagerLib.KeyList.Clear(); KeyManagerLib.KeyList.Clear();
CheckForFolders(); if (!SaveInterface.IsDirectoryEmpty(Globals.settings_KeyManagerItemsPath.Value))
if (!SaveInterface.IsDirectoryEmpty(Globals.settings_KeyManagerItemsPath))
{ {
string[] files = SaveInterface.GetFilesInDir(Globals.settings_KeyManagerItemsPath); string[] files = SaveInterface.GetFilesInDir(Globals.settings_KeyManagerItemsPath.Value);
foreach (string file in files) foreach (string file in files)
{ {
Console.WriteLine(file); Console.WriteLine(file);
@ -154,9 +154,9 @@ namespace WeeXnes.MVVM.View
Directory.CreateDirectory(Globals.AppDataPath); Directory.CreateDirectory(Globals.AppDataPath);
Console.WriteLine("Created AppDataPath"); Console.WriteLine("Created AppDataPath");
} }
if (!Directory.Exists(Globals.settings_KeyManagerItemsPath)) if (!Directory.Exists(Globals.settings_KeyManagerItemsPath.Value))
{ {
Directory.CreateDirectory(Globals.settings_KeyManagerItemsPath); Directory.CreateDirectory(Globals.settings_KeyManagerItemsPath.Value);
Console.WriteLine("Created settings_KeyManagerItemsPath"); Console.WriteLine("Created settings_KeyManagerItemsPath");
} }
} }
@ -186,7 +186,7 @@ namespace WeeXnes.MVVM.View
if(selectedItem != null) if(selectedItem != null)
{ {
Console.WriteLine(selectedItem.name + ": " + selectedItem.value); Console.WriteLine(selectedItem.name + ": " + selectedItem.value);
if (Globals.settings_copySelectedToClipboard) if (Globals.settings_copySelectedToClipboard.Value)
{ {
Clipboard.SetText(selectedItem.value); Clipboard.SetText(selectedItem.value);
} }
@ -199,7 +199,7 @@ namespace WeeXnes.MVVM.View
KeyItem selectedItem = (KeyItem)KeyListView.SelectedItem; KeyItem selectedItem = (KeyItem)KeyListView.SelectedItem;
Console.WriteLine("Doubleclicked " + selectedItem.name); Console.WriteLine("Doubleclicked " + selectedItem.name);
KeyManagerLib.KeyList.Remove(selectedItem); KeyManagerLib.KeyList.Remove(selectedItem);
string[] files = SaveInterface.GetFilesInDir(Globals.settings_KeyManagerItemsPath); string[] files = SaveInterface.GetFilesInDir(Globals.settings_KeyManagerItemsPath.Value);
foreach (string file in files) foreach (string file in files)
{ {
Console.WriteLine(file); Console.WriteLine(file);

View file

@ -29,11 +29,77 @@ namespace WeeXnes.MVVM.View
public SettingView() public SettingView()
{ {
InitializeComponent(); InitializeComponent();
LoadUiFromSettingsFile(); //LoadUiFromSettingsFile();
SetFunction(); SetFunction();
UpdatePathsOnUi(); SetUiUpdateListeners();
InitializeUi();
//UpdatePathsOnUi();
} }
public void InitializeUi()
{
if (!String.IsNullOrEmpty(Globals.settings_RpcItemsPath.Value))
{
RpcPathLabel.Content = Globals.settings_RpcItemsPath.Value;
}
else
{
RpcPathLabel.Content = "Default";
}
if (!String.IsNullOrEmpty(Globals.settings_KeyManagerItemsPath.Value))
{
KeyPathLabel.Content = Globals.settings_KeyManagerItemsPath.Value;
}
else
{
KeyPathLabel.Content = "Default";
}
if (Globals.settings_alwaysOnTop.Value)
{
AlwaysOnTopSwitch.IsChecked = true;
}
if (Globals.settings_RpcAutoStart.Value)
{
EnableAutoStart.IsChecked = true;
}
if (Globals.settings_RpcShowElapsedTime.Value)
{
ShowElapsedTimeOnRpc.IsChecked = true;
}
if (Globals.settings_copySelectedToClipboard.Value)
{
ItemToClipboardSwitch.IsChecked = true;
}
}
private void SetUiUpdateListeners()
{
Globals.settings_RpcItemsPath.ValueChanged += () =>
{
if (!String.IsNullOrEmpty(Globals.settings_RpcItemsPath.Value))
{
RpcPathLabel.Content = Globals.settings_RpcItemsPath.Value;
}
else
{
RpcPathLabel.Content = "Default";
}
};
Globals.settings_KeyManagerItemsPath.ValueChanged += () =>
{
if (!String.IsNullOrEmpty(Globals.settings_KeyManagerItemsPath.Value))
{
KeyPathLabel.Content = Globals.settings_KeyManagerItemsPath.Value;
}
else
{
KeyPathLabel.Content = "Default";
}
};
}
private void SetFunction() private void SetFunction()
{ {
EnableAutoStart.Checked += EnableAutoStart_Checked; EnableAutoStart.Checked += EnableAutoStart_Checked;
@ -45,135 +111,36 @@ namespace WeeXnes.MVVM.View
EnableAutoStart.Unchecked -= EnableAutoStart_Unchecked; EnableAutoStart.Unchecked -= EnableAutoStart_Unchecked;
} }
private void LoadUiFromSettingsFile()
{
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true);
if (Globals.settings_alwaysOnTop)
{
AlwaysOnTopSwitch.IsChecked = true;
}
if (Globals.settings_RpcShowElapsedTime)
{
ShowElapsedTimeOnRpc.IsChecked = true;
}
if (Globals.settings_copySelectedToClipboard)
{
ItemToClipboardSwitch.IsChecked = true;
}
bool autoStartRpc = Convert.ToBoolean(SettingsFile.GetValue("RPC", "autoStartRpc"));
if (autoStartRpc)
{
EnableAutoStart.IsChecked = true;
}
tb_DefaultClientID.Text = Globals.settings_RpcDefaultClientID;
}
public static void CheckSetting()
{
if(!File.Exists(Globals.AppDataPath + "\\" + Globals.SettingsFileName))
{
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true);
SettingsFile.SetValue("General", "AlwaysOnTop", "false");
SettingsFile.SetValue("RPC", "showElapsedTime", "true");
SettingsFile.SetValue("KeyManager", "copyToClipboard", "false");
SettingsFile.SetValue("RPC", "defaultID", "605116707035676701");
CheckSetting();
}
else
{
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName);
Globals.settings_alwaysOnTop = Convert.ToBoolean(SettingsFile.GetValue("General", "AlwaysOnTop"));
Console.WriteLine(Globals.settings_alwaysOnTop);
Globals.settings_RpcShowElapsedTime = Convert.ToBoolean(SettingsFile.GetValue("RPC", "showElapsedTime"));
Console.WriteLine(Globals.settings_RpcShowElapsedTime);
Globals.settings_copySelectedToClipboard = Convert.ToBoolean(SettingsFile.GetValue("KeyManager", "copyToClipboard"));
Console.WriteLine(Globals.settings_copySelectedToClipboard);
Globals.settings_RpcDefaultClientID = SettingsFile.GetValue("RPC", "defaultID");
Console.WriteLine(Globals.settings_RpcDefaultClientID);
Globals.settings_alwaysOnTop = Convert.ToBoolean(SettingsFile.GetValue("General", "AlwaysOnTop"));
Globals.settings_KeyManagerItemsPath_Bool = Convert.ToBoolean(SettingsFile.GetValue("KeyFiles", "CustomKeyLocation"));
if (Globals.settings_KeyManagerItemsPath_Bool)
{
Globals.settings_KeyManagerItemsPath = SettingsFile.GetValue("KeyFiles", "KeyPath");
}
else
{
Globals.settings_KeyManagerItemsPath = Globals.settings_KeyManagerItemsPath_Default;
}
Globals.settings_RpcItemsPath_Bool = Convert.ToBoolean(SettingsFile.GetValue("rpc", "CustomRpcLocation"));
if (Globals.settings_RpcItemsPath_Bool)
{
Globals.settings_RpcItemsPath = SettingsFile.GetValue("rpc", "RpcPath");
}
else
{
Globals.settings_RpcItemsPath = Globals.settings_RpcItemsPath_Default;
}
}
/*
SettingsFile.SetValue("settings", "alwaysOnTop", "false");
Globals.alwaysOnTop = false;
SettingsFile.SetValue("RPC", "elapsedTime", "true");
Globals.showElapsedTime = true;
*/
}
private void AlwaysOnTopSwitch_Checked(object sender, RoutedEventArgs e) private void AlwaysOnTopSwitch_Checked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_alwaysOnTop.Value = true;
SettingsFile.SetValue("General", "AlwaysOnTop", "true");
CheckSetting();
} }
private void AlwaysOnTopSwitch_Unchecked(object sender, RoutedEventArgs e) private void AlwaysOnTopSwitch_Unchecked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_alwaysOnTop.Value = false;
SettingsFile.SetValue("General", "AlwaysOnTop", "false");
CheckSetting();
} }
private void ShowElapsedTimeOnRpc_Checked(object sender, RoutedEventArgs e) private void ShowElapsedTimeOnRpc_Checked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_RpcShowElapsedTime.Value = true;
SettingsFile.SetValue("RPC", "showElapsedTime", "true");
CheckSetting();
} }
private void ShowElapsedTimeOnRpc_Unchecked(object sender, RoutedEventArgs e) private void ShowElapsedTimeOnRpc_Unchecked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_RpcShowElapsedTime.Value = false;
SettingsFile.SetValue("RPC", "showElapsedTime", "false");
CheckSetting();
} }
private void ItemToClipboardSwitch_Checked(object sender, RoutedEventArgs e) private void ItemToClipboardSwitch_Checked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_copySelectedToClipboard.Value = true;
SettingsFile.SetValue("KeyManager", "copyToClipboard", "true");
CheckSetting();
} }
private void ItemToClipboardSwitch_Unchecked(object sender, RoutedEventArgs e) private void ItemToClipboardSwitch_Unchecked(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_copySelectedToClipboard.Value = false;
SettingsFile.SetValue("KeyManager", "copyToClipboard", "false");
CheckSetting();
} }
private void OpenAppdataFolder_Click(object sender, RoutedEventArgs e) private void OpenAppdataFolder_Click(object sender, RoutedEventArgs e)
@ -183,11 +150,9 @@ namespace WeeXnes.MVVM.View
private void SaveDefaultID_Click(object sender, RoutedEventArgs e) private void SaveDefaultID_Click(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true);
if (!String.IsNullOrEmpty(tb_DefaultClientID.Text)) if (!String.IsNullOrEmpty(tb_DefaultClientID.Text))
{ {
SettingsFile.SetValue("RPC", "defaultID", tb_DefaultClientID.Text); Globals.settings_RpcDefaultClientID.Value = tb_DefaultClientID.Text;
CheckSetting();
} }
else else
{ {
@ -200,15 +165,14 @@ namespace WeeXnes.MVVM.View
{ {
UnsetFunction(); UnsetFunction();
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true);
if (on) if (on)
{ {
SettingsFile.SetValue("RPC", "autoStartRpc", "true"); Globals.settings_RpcAutoStart.Value = true;
EnableAutoStart.IsChecked = true; EnableAutoStart.IsChecked = true;
} }
else else
{ {
SettingsFile.SetValue("RPC", "autoStartRpc", "false"); Globals.settings_RpcAutoStart.Value = false;
EnableAutoStart.IsChecked = false; EnableAutoStart.IsChecked = false;
} }
SetFunction(); SetFunction();
@ -253,19 +217,11 @@ namespace WeeXnes.MVVM.View
switchAutoRpc(proc_suc); switchAutoRpc(proc_suc);
} }
private void UpdatePathsOnUi()
{
RpcPathLabel.Content = Globals.settings_RpcItemsPath;
KeyPathLabel.Content = Globals.settings_KeyManagerItemsPath;
}
private void SetKeyLocationDefault_OnClick(object sender, RoutedEventArgs e) private void SetKeyLocationDefault_OnClick(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_KeyManagerItemsPath_Bool.Value = false;
SettingsFile.SetValue("KeyFiles", "CustomKeyLocation", "false"); Globals.settings_KeyManagerItemsPath.Value = "";
SettingsFile.SetValue("KeyFiles", "KeyPath", "");
CheckSetting();
UpdatePathsOnUi();
} }
private void SetKeyLocation_OnClick(object sender, RoutedEventArgs e) private void SetKeyLocation_OnClick(object sender, RoutedEventArgs e)
@ -276,11 +232,9 @@ namespace WeeXnes.MVVM.View
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true);
SettingsFile.SetValue("KeyFiles", "CustomKeyLocation", "true"); Globals.settings_KeyManagerItemsPath_Bool.Value = true;
SettingsFile.SetValue("KeyFiles", "KeyPath", fbd.SelectedPath); Globals.settings_KeyManagerItemsPath.Value = fbd.SelectedPath;
CheckSetting();
UpdatePathsOnUi();
//MessageBox.Show("valid path: " + fbd.SelectedPath); //MessageBox.Show("valid path: " + fbd.SelectedPath);
} }
} }
@ -288,11 +242,8 @@ namespace WeeXnes.MVVM.View
private void SetRpcLocationDefault_OnClick(object sender, RoutedEventArgs e) private void SetRpcLocationDefault_OnClick(object sender, RoutedEventArgs e)
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_RpcItemsPath_Bool.Value = false;
SettingsFile.SetValue("rpc", "CustomRpcLocation", "false"); Globals.settings_RpcItemsPath.Value = "";
SettingsFile.SetValue("rpc", "RpcPath", "");
CheckSetting();
UpdatePathsOnUi();
} }
private void SetRpcLocation_OnClick(object sender, RoutedEventArgs e) private void SetRpcLocation_OnClick(object sender, RoutedEventArgs e)
@ -303,12 +254,8 @@ namespace WeeXnes.MVVM.View
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{ {
INIFile SettingsFile = new INIFile(Globals.AppDataPath + "\\" + Globals.SettingsFileName, true); Globals.settings_RpcItemsPath_Bool.Value = true;
SettingsFile.SetValue("rpc", "CustomRpcLocation", "true"); Globals.settings_RpcItemsPath.Value = fbd.SelectedPath;
SettingsFile.SetValue("rpc", "RpcPath", fbd.SelectedPath);
CheckSetting();
UpdatePathsOnUi();
//MessageBox.Show("valid path: " + fbd.SelectedPath);
} }
} }
} }

View file

@ -98,7 +98,9 @@ namespace WeeXnes
private void CheckForSettingsFile() private void CheckForSettingsFile()
{ {
SettingView.CheckSetting(); //SettingView.CheckSetting();
SettingsManager.start();
} }
private void Border_MouseDown(object sender, MouseButtonEventArgs e) private void Border_MouseDown(object sender, MouseButtonEventArgs e)
@ -139,17 +141,12 @@ namespace WeeXnes
Directory.CreateDirectory(Globals.AppDataPath); Directory.CreateDirectory(Globals.AppDataPath);
Console.WriteLine("Created AppDataPath"); Console.WriteLine("Created AppDataPath");
} }
if (!Directory.Exists(Globals.settings_RpcItemsPath))
{
Directory.CreateDirectory(Globals.settings_RpcItemsPath);
Console.WriteLine("Created settings_RpcItemsPath");
}
} }
private void Window_Deactivated(object sender, EventArgs e) private void Window_Deactivated(object sender, EventArgs e)
{ {
Window window = (Window)sender; Window window = (Window)sender;
if (Globals.settings_alwaysOnTop) if (Globals.settings_alwaysOnTop.Value)
{ {
window.Topmost = true; window.Topmost = true;
} }

View file

@ -75,7 +75,10 @@ namespace WeeXnes.RPC
SmallImageText = this.smallimgtext SmallImageText = this.smallimgtext
} }
}); });
client.UpdateStartTime(); if (Globals.settings_RpcShowElapsedTime.Value)
{
client.UpdateStartTime();
}
} }
public void stop() public void stop()
{ {