diff --git a/WeeXnes/App.xaml b/WeeXnes/App.xaml
index 825e2aa..b77f7c1 100644
--- a/WeeXnes/App.xaml
+++ b/WeeXnes/App.xaml
@@ -2,37 +2,15 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WeeXnes"
- xmlns:viewModel="clr-namespace:WeeXnes.MVVM.ViewModel"
- xmlns:view="clr-namespace:WeeXnes.MVVM.View"
+ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
StartupUri="MainWindow.xaml"
Startup="App_OnStartup">
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs
index 5e5e464..383dc18 100644
--- a/WeeXnes/App.xaml.cs
+++ b/WeeXnes/App.xaml.cs
@@ -1,7 +1,13 @@
using System;
+using System.ComponentModel;
using System.Windows;
-using WeeXnes.Core;
using System.IO;
+using Newtonsoft.Json.Linq;
+using Nocksoft.IO.ConfigFiles;
+using WeeXnes.Core;
+using WeeXnes.Views.DiscordRPC;
+using WeeXnes.Views.KeyManager;
+using WeeXnes.Views.Settings;
using Application = System.Windows.Forms.Application;
namespace WeeXnes
@@ -14,20 +20,94 @@ namespace WeeXnes
private void App_OnStartup(object sender, StartupEventArgs e)
{
Environment.CurrentDirectory = Application.StartupPath;
- if (e.Args.Length > 0)
- {
- for (int i = 0; i != e.Args.Length; ++i)
- {
- //MessageBox.Show(e.Args[i]);
- if (e.Args[i] == "-autostart")
- {
- //MessageBox.Show("Launched via autostart");
- Globals.info_RpcAutoStart = true;
- }
- }
+ CheckForDebugMode();
+ CheckForFolder();
+ LoadSettings();
+ SaveSettingsHandler.SetupSaveEvents();
+ LoadFiles();
+ CheckStartupArgs(e.Args);
+ }
+ private void LoadSettings()
+ {
+ if(!File.Exists(Path.Combine(Global.AppDataPath, Global.SettingsFile)))
+ return;
+ KeyManagerView.Data.censorKeys.Value =
+ Convert.ToBoolean(SettingsView.Data.settingsFile.GetValue(
+ SaveSettingsHandler.Data.KeyManager.Section,
+ SaveSettingsHandler.Data.KeyManager.CensorKeys));
+
+ }
+
+ private void LoadFiles()
+ {
+ Functions.CheckFolderAndCreate(Global.AppDataPathRPC);
+ DirectoryInfo rpcDirectoryInfo = new DirectoryInfo(Global.AppDataPathRPC);
+ foreach (var file in rpcDirectoryInfo.GetFiles("*.rpc"))
+ {
+ try
+ {
+ Game newGame = Game.Methods.GameFromIni(new INIFile(file.FullName));
+ DiscordRPCView.Data.Games.Add(newGame);
+ Console.WriteLine(file.Name + " loaded");
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(file.Name + ": " + ex.Message);
+ }
}
- //Globals.autoStartRpc = true;
+ Functions.CheckFolderAndCreate(Global.AppDataPathKEY);
+ DirectoryInfo keyDirectoryInfo = new DirectoryInfo(Global.AppDataPathKEY);
+ foreach (var file in keyDirectoryInfo.GetFiles("*.wx"))
+ {
+ try
+ {
+ //Load KeyFiles
+
+ WXFile wxFile = new WXFile(file.FullName);
+ KeyItem newItem = new KeyItem(
+ wxFile.GetName(),
+ EncryptionLib.EncryptorLibary.decrypt(
+ Information.EncryptionHash,
+ wxFile.GetValue()
+ )
+ );
+ newItem.Filename = file.Name;
+ KeyManagerView.Data.KeyItemsList.Add(newItem);
+ Console.WriteLine(file.Name + " loaded");
+
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(file.Name + ": " + ex.Message);
+ }
+ }
+ }
+ private void CheckForFolder()
+ {
+ Functions.CheckFolderAndCreate(Global.AppDataPath);
+ }
+ private void CheckStartupArgs(string[] arguments)
+ {
+ foreach (string argument in arguments)
+ {
+ switch (argument)
+ {
+ case "-autostart":
+ HandleLaunchArguments.arg_autostart();
+ break;
+ case "-debugMode":
+ HandleLaunchArguments.arg_debugMode();
+ break;
+ }
+ }
+ }
+
+ private void CheckForDebugMode()
+ {
+ #if DEBUG
+ HandleLaunchArguments.arg_enableConsole();
+ #endif
}
}
}
\ No newline at end of file
diff --git a/WeeXnes/Core/ApiResponse.cs b/WeeXnes/Core/ApiResponse.cs
deleted file mode 100644
index 934d262..0000000
--- a/WeeXnes/Core/ApiResponse.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-namespace WeeXnes.Core
-{
- public class ApiResponse
- {
- public string download_url { get; set; }
- public string file_name { get; set; }
- public string tag_name { get; set; }
- public string name { get; set; }
- public string description { get; set; }
- public ApiResponse(string _download_url, string _file_name, string _tag_name, string _name, string _description)
- {
- this.download_url = _download_url;
- this.file_name = _file_name;
- this.tag_name = _tag_name;
- this.name = _name;
- this.description = _description;
- }
-
- public override string ToString()
- {
- string returnval =
- "download_url: " + this.download_url + "\n" +
- "file_name: " + this.file_name + "\n" +
- "tag_name: " + this.tag_name + "\n" +
- "name: " + this.name + "\n" +
- "description: " + this.description;
- return returnval;
- }
- }
-}
\ No newline at end of file
diff --git a/WeeXnes/Core/DataTypes.cs b/WeeXnes/Core/DataTypes.cs
new file mode 100644
index 0000000..6a2e5d9
--- /dev/null
+++ b/WeeXnes/Core/DataTypes.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace WeeXnes.Core
+{
+ public class UpdateVar
+ {
+ private T _value;
+
+ public Action ValueChanged;
+
+ public T Value
+ {
+ get => _value;
+
+ set
+ {
+ _value = value;
+ OnValueChanged();
+ }
+ }
+
+ protected virtual void OnValueChanged() => ValueChanged?.Invoke();
+ }
+}
\ No newline at end of file
diff --git a/WeeXnes/Misc/EncryptorLibary.cs b/WeeXnes/Core/EncryptorLibrary.cs
similarity index 79%
rename from WeeXnes/Misc/EncryptorLibary.cs
rename to WeeXnes/Core/EncryptorLibrary.cs
index 5864c61..e8638ce 100644
--- a/WeeXnes/Misc/EncryptorLibary.cs
+++ b/WeeXnes/Core/EncryptorLibrary.cs
@@ -47,25 +47,7 @@ namespace EncryptionLib
}
return returnval;
}
- public static string[] readFile(string filepath)
- {
- string[] lines = System.IO.File.ReadAllLines(filepath);
- var listOfStrings = new List();
- foreach (string line in lines)
- {
- listOfStrings.Add(line);
- }
- string[] arrayOfStrings = listOfStrings.ToArray();
- return arrayOfStrings;
- }
- public static void writeFile(string[] stringArray, string filepath)
- {
- for (int i = 0; i < stringArray.Length; i++)
- {
- Console.WriteLine(stringArray[i]);
- }
- File.WriteAllLines(filepath, stringArray, Encoding.UTF8);
- }
+
public static string[] encryptArray(string hash, string[] arrayToEncrypt)
{
for (int i = 0; i < arrayToEncrypt.Length; i++)
diff --git a/WeeXnes/Core/Functions.cs b/WeeXnes/Core/Functions.cs
new file mode 100644
index 0000000..917aa54
--- /dev/null
+++ b/WeeXnes/Core/Functions.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Windows;
+
+namespace WeeXnes.Core
+{
+ public static class Functions
+ {
+ public static void CheckFolderAndCreate(string path)
+ {
+ try
+ {
+ if (!Directory.Exists(path))
+ Directory.CreateDirectory(path);
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show(e.Message);
+ }
+ }
+ public static string[] readFile(string filepath)
+ {
+ string[] lines = System.IO.File.ReadAllLines(filepath);
+ var listOfStrings = new List();
+ foreach (string line in lines)
+ {
+ listOfStrings.Add(line);
+ }
+ string[] arrayOfStrings = listOfStrings.ToArray();
+ return arrayOfStrings;
+ }
+ public static void writeFile(string[] stringArray, string filepath)
+ {
+ for (int i = 0; i < stringArray.Length; i++)
+ {
+ Console.WriteLine(stringArray[i]);
+ }
+ File.WriteAllLines(filepath, stringArray, Encoding.UTF8);
+ }
+ }
+}
\ No newline at end of file
diff --git a/WeeXnes/Core/Global.cs b/WeeXnes/Core/Global.cs
new file mode 100644
index 0000000..3884aea
--- /dev/null
+++ b/WeeXnes/Core/Global.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace WeeXnes.Core
+{
+ public class Information
+ {
+ public const string Version = "4.0.0";
+ public const string EncryptionHash = "8zf5#RdyQ]$4x4_";
+ public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest";
+ }
+
+ 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 string SettingsFile = "settings.ini";
+ }
+}
\ No newline at end of file
diff --git a/WeeXnes/Core/Globals.cs b/WeeXnes/Core/Globals.cs
deleted file mode 100644
index 572a4bc..0000000
--- a/WeeXnes/Core/Globals.cs
+++ /dev/null
@@ -1,212 +0,0 @@
-using WeeXnes.RPC;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-using Nocksoft.IO.ConfigFiles;
-using MessageBox = System.Windows.MessageBox;
-
-namespace WeeXnes.Core
-{
- internal class Globals
- {
- public static string encryptionKey = "8zf5#RdyQ]$4x4_";
- public static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "WeeXnes");
- public static string SettingsFileName = "settings.ini";
- public static string version = "3.6.4";
- public static bool info_isRpcRunning = false;
- public static bool info_RpcAutoStart;
- public static string apiUrl = "http://weexnes.com:5169/";
-
- public static UpdateVar settings_alwaysOnTop = new UpdateVar();
- public static UpdateVar settings_osxStyleControlls = new UpdateVar();
-
- public static UpdateVar settings_copySelectedToClipboard = new UpdateVar();
-
- public static string settings_KeyManagerItemsPath_Default = AppDataPath + "\\" + "Keys";
- public static UpdateVar settings_KeyManagerItemsPath = new UpdateVar();
- public static UpdateVar settings_KeyManagerItemsPath_Bool = new UpdateVar();
- public static UpdateVar settings_KeyManagerCensorKeys = new UpdateVar();
-
- public static string settings_RpcItemsPath_Default = AppDataPath + "\\" + "RPC";
- public static UpdateVar settings_RpcItemsPath = new UpdateVar();
- public static UpdateVar settings_RpcItemsPath_Bool = new UpdateVar();
-
- public static UpdateVar settings_RpcShowElapsedTime = new UpdateVar();
- public static UpdateVar settings_RpcDefaultClientID = new UpdateVar();
- public static UpdateVar settings_RpcAutoStart = new UpdateVar();
-
-
-
- public static UpdateVar searchbox_content = new UpdateVar();
- }
- public static class SettingsManager
- {
- public static INIFile SettingsFile = new INIFile(
- Globals.AppDataPath + "\\" + Globals.SettingsFileName,
- true
- );
- public static void start()
- {
- loadSettings();
- setEventListeners();
- }
-
- 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"));
- Globals.settings_KeyManagerCensorKeys.Value = Convert.ToBoolean(SettingsFile.GetValue("KeyManager", "CensorKeys"));
- 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_osxStyleControlls.Value = Convert.ToBoolean(SettingsFile.GetValue("general", "OSXStyle"));
-
- Globals.settings_RpcShowElapsedTime.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "RpcShowElapsedTime"));
- Globals.settings_RpcItemsPath_Bool.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "RpcItemsPath_Bool"));
- Globals.settings_RpcAutoStart.Value = Convert.ToBoolean(SettingsFile.GetValue("rpc", "RpcAutoStart"));
- 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_KeyManagerCensorKeys.ValueChanged += () =>
- {
- if (Globals.settings_KeyManagerCensorKeys.Value)
- {
- SettingsFile.SetValue("KeyManager", "CensorKeys", "true");
- }
- else
- {
- SettingsFile.SetValue("KeyManager", "CensorKeys", "false");
- }
- };
- Globals.settings_osxStyleControlls.ValueChanged += () =>
- {
- SettingsFile.SetValue("general", "OSXStyle", Globals.settings_osxStyleControlls.Value.ToString());
- };
-
- 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 bool IsDirectoryEmpty(string path)
- {
- return !Directory.EnumerateFileSystemEntries(path).Any();
- }
- }
- public class UpdateVar
- {
- private T _value;
-
- public Action ValueChanged;
-
- public T Value
- {
- get => _value;
-
- set
- {
- _value = value;
- OnValueChanged();
- }
- }
-
- protected virtual void OnValueChanged() => ValueChanged?.Invoke();
- }
-}
-
-
diff --git a/WeeXnes/Core/HandleLaunchArguments.cs b/WeeXnes/Core/HandleLaunchArguments.cs
new file mode 100644
index 0000000..e1dde45
--- /dev/null
+++ b/WeeXnes/Core/HandleLaunchArguments.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+namespace WeeXnes.Core
+{
+ public class HandleLaunchArguments
+ {
+ private const int ATTACH_PARENT_PROCESS = -1;
+ [DllImport("kernel32.dll")]
+ private static extern bool AttachConsole(int dwProcessId);
+ public static void arg_autostart()
+ {
+
+ }
+ public static void arg_debugMode()
+ {
+
+ }
+ public static void arg_enableConsole()
+ {
+ AttachConsole(ATTACH_PARENT_PROCESS);
+ }
+ }
+}
\ No newline at end of file
diff --git a/WeeXnes/Core/INIFile.cs b/WeeXnes/Core/INIFile.cs
new file mode 100644
index 0000000..629a985
--- /dev/null
+++ b/WeeXnes/Core/INIFile.cs
@@ -0,0 +1,296 @@
+/**
+ * Copyright by Nocksoft
+ * https://www.nocksoft.de
+ * https://nocksoft.de/tutorials/visual-c-sharp-arbeiten-mit-ini-dateien/
+ * https://github.com/Nocksoft/INIFile.cs
+ * -----------------------------------
+ * Author: Rafael Nockmann @ Nocksoft
+ * Updated: 2022-01-09
+ * Version: 1.0.3
+ *
+ * Language: Visual C#
+ *
+ * License: MIT license
+ * License URL: https://github.com/Nocksoft/INIFile.cs/blob/master/LICENSE
+ *
+ * Description:
+ * Provides basic functions for working with INI files.
+ *
+ * ##############################################################################################
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.IO;
+
+namespace Nocksoft.IO.ConfigFiles
+{
+ public class INIFile
+ {
+ private string _File;
+
+ ///
+ /// Call the constructor creates a new object of the INIFile class to work with INI files.
+ ///
+ /// Name of INI file, which you want to access.
+ /// Specifies whether the INI file should be created if it does not exist.
+ public INIFile(string file, bool createFile = false)
+ {
+ if (createFile == true && File.Exists(file) == false)
+ {
+ FileInfo fileInfo = new FileInfo(file);
+ FileStream fileStream = fileInfo.Create();
+ fileStream.Close();
+ }
+ _File = file;
+ }
+
+ #region Public Methods
+
+ ///
+ /// Removes all comments and empty lines from a complete section and returns the sections.
+ /// This method is not case-sensitive.
+ /// The return value does not contain any spaces at the beginning or at the end of a line.
+ ///
+ /// Name of the requested section.
+ /// Specifies whether comments should also be returned.
+ /// Returns the whole section.
+ public List GetSection(string section, bool includeComments = false)
+ {
+ section = CheckSection(section);
+
+ List completeSection = new List();
+ bool sectionStart = false;
+
+ string[] fileArray = File.ReadAllLines(_File);
+
+ foreach (var item in fileArray)
+ {
+ if (item.Length <= 0) continue;
+
+ // Beginning of section.
+ if (item.Replace(" ", "").ToLower() == section)
+ {
+ sectionStart = true;
+ }
+ // Beginning of next section.
+ if (sectionStart == true && item.Replace(" ", "").ToLower() != section && item.Replace(" ", "").Substring(0, 1) == "[" && item.Replace(" ", "").Substring(item.Length - 1, 1) == "]")
+ {
+ break;
+ }
+ if (sectionStart == true)
+ {
+ // Add the entry to the List completeSection, if it is not a comment or an empty entry.
+ if (includeComments == false
+ && item.Replace(" ", "").Substring(0, 1) != ";" && !string.IsNullOrWhiteSpace(item))
+ {
+ completeSection.Add(ReplaceSpacesAtStartAndEnd(item));
+ }
+ if (includeComments == true && !string.IsNullOrWhiteSpace(item))
+ {
+ completeSection.Add(ReplaceSpacesAtStartAndEnd(item));
+ }
+ }
+ }
+ return completeSection;
+ }
+
+ ///
+ /// The method returns a value for the associated key.
+ /// This method is not case-sensitive.
+ ///
+ /// Name of the requested section.
+ /// Name of the requested key.
+ /// If "true" is passed, the value will be returned in lowercase letters.
+ /// Returns the value for the specified key in the specified section, if available, otherwise null.
+ public string GetValue(string section, string key, bool convertValueToLower = false)
+ {
+ section = CheckSection(section);
+ key = key.ToLower();
+
+ List completeSection = GetSection(section);
+
+ foreach (var item in completeSection)
+ {
+ // Continue if entry is no key.
+ if (!item.Contains("=") && item.Contains("[") && item.Contains("]")) continue;
+
+ string[] keyAndValue = item.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
+ if (keyAndValue[0].ToLower() == key && keyAndValue.Count() > 1)
+ {
+ if (convertValueToLower == true)
+ {
+ keyAndValue[1] = keyAndValue[1].ToLower();
+ }
+ return keyAndValue[1];
+ }
+ }
+ return null;
+ }
+
+ ///
+ /// Set or add a value of the associated key in the specified section.
+ /// This method is not case-sensitive.
+ ///
+ /// Name of the section.
+ /// Name of the key.
+ /// Value to save.
+ /// If "true" is passed, the value will be saved in lowercase letters.
+ public void SetValue(string section, string key, string value, bool convertValueToLower = false)
+ {
+ section = CheckSection(section, false);
+ string sectionToLower = section.ToLower();
+
+ bool sectionFound = false;
+
+ List iniFileContent = new List();
+
+ string[] fileLines = File.ReadAllLines(_File);
+
+ // Creates a new INI file if none exists.
+ if (fileLines.Length <= 0)
+ {
+ iniFileContent = AddSection(iniFileContent, section, key, value, convertValueToLower);
+ WriteFile(iniFileContent);
+ return;
+ }
+
+ for (int i = 0; i < fileLines.Length; i++)
+ {
+ // Possibility 1: The desired section has not (yet) been found.
+ if (fileLines[i].Replace(" ", "").ToLower() != sectionToLower)
+ {
+ iniFileContent.Add(fileLines[i]);
+ // If a section does not exist, the section will be created.
+ if (i == fileLines.Length - 1 && fileLines[i].Replace(" ", "").ToLower() != sectionToLower && sectionFound == false)
+ {
+ iniFileContent.Add(null);
+ iniFileContent = AddSection(iniFileContent, section, key, value, convertValueToLower);
+ break;
+ }
+ continue;
+ }
+
+
+ // Possibility 2 -> Desired section was found.
+ sectionFound = true;
+
+ // Get the complete section in which the target key may be.
+ List targetSection = GetSection(sectionToLower, true);
+
+ for (int x = 0; x < targetSection.Count; x++)
+ {
+ string[] targetKey = targetSection[x].Split(new string[] { "=" }, StringSplitOptions.None);
+ // When the target key is found.
+ if (targetKey[0].ToLower() == key.ToLower())
+ {
+ if (convertValueToLower == true)
+ {
+ iniFileContent.Add(key + "=" + value.ToLower());
+ }
+ else
+ {
+ iniFileContent.Add(key + "=" + value);
+ }
+ i = i + x;
+ break;
+ }
+ else
+ {
+ iniFileContent.Add(targetSection[x]);
+ // If the target key is not found, it will be created.
+ if (x == targetSection.Count - 1 && targetKey[0].ToLower() != key.ToLower())
+ {
+ if (convertValueToLower == true)
+ {
+ iniFileContent.Add(key + "=" + value.ToLower());
+ }
+ else
+ {
+ iniFileContent.Add(key + "=" + value);
+ }
+ i = i + x;
+ break;
+ }
+ }
+ }
+ }
+
+ WriteFile(iniFileContent);
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ ///
+ /// Ensures that a section is always in the following format: [section].
+ ///
+ /// Section to be checked for correct format.
+ /// Specifies whether the section should be vonverted in lower case letters.
+ /// Returns section in this form: [section].
+ private string CheckSection(string section, bool convertToLower = true)
+ {
+ if (convertToLower == true)
+ {
+ section = section.ToLower();
+ }
+ if (!section.StartsWith("[") && !section.EndsWith("]"))
+ {
+ section = "[" + section + "]";
+ }
+ return section;
+ }
+
+ ///
+ /// Removes leading and trailing spaces from sections, keys and values.
+ ///
+ /// String to be trimmed.
+ /// Returns the trimmed string.
+ private string ReplaceSpacesAtStartAndEnd(string item)
+ {
+ // If the string has a key and a value.
+ if (item.Contains("=") && !item.Contains("[") && !item.Contains("]"))
+ {
+ string[] keyAndValue = item.Split(new string[] { "=" }, StringSplitOptions.None);
+ return keyAndValue[0].Trim() + "=" + keyAndValue[1].Trim();
+ }
+
+ return item.Trim();
+ }
+
+ ///
+ /// Adds a new section with key value pair.
+ ///
+ /// List iniFileContent from SetValue.
+ /// Section to be created.
+ /// Key to be added.
+ /// Value to be added.
+ /// Specifies whether the key and value should be saved in lower case letters.
+ /// Returns the new created section with key value pair.
+ private List AddSection(List iniFileContent, string section, string key, string value, bool convertValueToLower)
+ {
+ if (convertValueToLower == true)
+ {
+ value = value.ToLower();
+ }
+
+ iniFileContent.Add(section);
+ iniFileContent.Add($"{key}={value}");
+ return iniFileContent;
+ }
+
+ private void WriteFile(List content)
+ {
+ StreamWriter writer = new StreamWriter(_File);
+ foreach (var item in content)
+ {
+ writer.WriteLine(item);
+ }
+ writer.Close();
+ }
+
+ #endregion
+ }
+}
diff --git a/WeeXnes/Core/ObservableObject.cs b/WeeXnes/Core/ObservableObject.cs
deleted file mode 100644
index bac94be..0000000
--- a/WeeXnes/Core/ObservableObject.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
-
-namespace WeeXnes.Core
-{
- internal class ObservableObject : INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged([CallerMemberName] string name = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
- }
- }
-}
diff --git a/WeeXnes/Core/RelayCommand.cs b/WeeXnes/Core/RelayCommand.cs
deleted file mode 100644
index 91b2324..0000000
--- a/WeeXnes/Core/RelayCommand.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System;
-using System.Windows.Input;
-
-namespace WeeXnes.Core
-{
- internal class RelayCommand : ICommand
- {
- private Action