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 _execute; - private Func _canExecute; - - public event EventHandler CanExecuteChanged - { - add { CommandManager.RequerySuggested += value; } - remove { CommandManager.RequerySuggested -= value;} - } - public RelayCommand(Action execute, Func canExecute = null) - { - _execute = execute; - _canExecute = canExecute; - } - public bool CanExecute(object parameter) - { - return _canExecute == null || _canExecute(parameter); - } - public void Execute(object parameter) - { - _execute(parameter); - } - } -} diff --git a/WeeXnes/Core/SaveSettingsHandler.cs b/WeeXnes/Core/SaveSettingsHandler.cs new file mode 100644 index 0000000..cb632a3 --- /dev/null +++ b/WeeXnes/Core/SaveSettingsHandler.cs @@ -0,0 +1,43 @@ +using System.Collections.Specialized; +using WeeXnes.Views.KeyManager; +using WeeXnes.Views.Settings; + +namespace WeeXnes.Core +{ + public static class SaveSettingsHandler + { + public static class Data + { + //Layout-Names for INIFiles + public static class KeyManager + { + public const string Section = "KEY_MANAGER"; + public const string CensorKeys = "CensorKeys"; + } + public static class DiscordRpcFiles + { + public const string Section = "CONFIG"; + public const string ProcessName = "ProcessName"; + public const string ClientId = "ClientID"; + public const string State = "State"; + public const string Details = "Details"; + public const string BigImageKey = "BigImageKey"; + public const string BigImageText = "BigImageText"; + public const string SmallImageKey = "SmallImageKey"; + public const string SmallImageText = "SmallImageText"; + public const string UUID = "UUID"; + } + } + public static void SetupSaveEvents() + { + KeyManagerView.Data.censorKeys.ValueChanged += () => + { + SettingsView.Data.settingsFile.SetValue( + Data.KeyManager.Section, + Data.KeyManager.CensorKeys, + KeyManagerView.Data.censorKeys.Value.ToString() + ); + }; + } + } +} \ No newline at end of file diff --git a/WeeXnes/Core/WXFile.cs b/WeeXnes/Core/WXFile.cs new file mode 100644 index 0000000..5f22ad3 --- /dev/null +++ b/WeeXnes/Core/WXFile.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using WeeXnes.Views.KeyManager; + +namespace WeeXnes.Core +{ + public class WXFile + { + private const string FileIdentifier = "##WXfile##"; + public string path + { + get; + set; + } + public WXFile(string _path) + { + this.path = _path; + } + public string GetName() + { + string returnval = null; + string[] rawcontent = Methods.ReadFile(this.path); + + if (Methods.Verify(rawcontent)) + { + try + { + returnval = rawcontent[1]; + } + catch (Exception e) + { + returnval = null; + } + } + + return returnval; + } + public string GetValue() + { + string returnval = null; + string[] rawcontent = Methods.ReadFile(this.path); + + if (Methods.Verify(rawcontent)) + { + try + { + returnval = rawcontent[2]; + }catch (Exception e) + { + returnval = null; + } + } + + return returnval; + } + public static class Methods + { + public static void WriteFile(KeyItem keyItem, WXFile wxFile) + { + + string[] fileContent = new string[] + { + "##WXfile##", + keyItem.Name, + EncryptionLib.EncryptorLibary.encrypt( + Information.EncryptionHash, + keyItem.Value + ) + }; + Functions.writeFile(fileContent, wxFile.path); + } + 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 bool Verify(string[] content) + { + bool integ = false; + if(content != null) + { + if(content[0] == FileIdentifier) + { + integ = true; + } + } + return integ; + } + } + } +} \ No newline at end of file diff --git a/WeeXnes/Core/customEvent.cs b/WeeXnes/Core/customEvent.cs deleted file mode 100644 index 1952d41..0000000 --- a/WeeXnes/Core/customEvent.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Net; -using System.Threading.Tasks; -using System.Windows; - -namespace WeeXnes.Core -{ - public enum EventType - { - ProcessStartedEvent, - ProcessStoppedEvent, - RPCUpdateEvent, - RPCReadyEvent - } - public class customEvent - { - - public string Content { get; set; } - public EventType Type { get; set; } - - public string GradientColor1 { get; set; } - public string GradientColor2 { get; set; } - public customEvent(string content, EventType type) - { - this.Content = content; - this.Type = type; - if (this.Type == EventType.ProcessStartedEvent) - { - this.GradientColor1 = "#46db69"; - this.GradientColor2 = "#33a34d"; - } - else if (this.Type == EventType.ProcessStoppedEvent) - { - this.GradientColor1 = "#d1415d"; - this.GradientColor2 = "#a33349"; - } - else if (this.Type == EventType.RPCUpdateEvent) - { - this.GradientColor1 = "#3e65c9"; - this.GradientColor2 = "#3352a3"; - } - else if (this.Type == EventType.RPCReadyEvent) - { - this.GradientColor1 = "#c93eb4"; - this.GradientColor2 = "#a33389"; - } - } - - - public override string ToString() - { - return this.Content; - } - } -} \ No newline at end of file diff --git a/WeeXnes/Fonts/Poppins-Regular.ttf b/WeeXnes/Fonts/Poppins-Regular.ttf deleted file mode 100644 index be06e7f..0000000 Binary files a/WeeXnes/Fonts/Poppins-Regular.ttf and /dev/null differ diff --git a/WeeXnes/Images/discord.png b/WeeXnes/Images/discord.png deleted file mode 100644 index 5b6094f..0000000 Binary files a/WeeXnes/Images/discord.png and /dev/null differ diff --git a/WeeXnes/Images/green.png b/WeeXnes/Images/green.png deleted file mode 100644 index e20c542..0000000 Binary files a/WeeXnes/Images/green.png and /dev/null differ diff --git a/WeeXnes/Images/home.png b/WeeXnes/Images/home.png deleted file mode 100644 index 4c7b3dc..0000000 Binary files a/WeeXnes/Images/home.png and /dev/null differ diff --git a/WeeXnes/Images/key.png b/WeeXnes/Images/key.png deleted file mode 100644 index 1a8add4..0000000 Binary files a/WeeXnes/Images/key.png and /dev/null differ diff --git a/WeeXnes/Images/red.png b/WeeXnes/Images/red.png deleted file mode 100644 index ab502dc..0000000 Binary files a/WeeXnes/Images/red.png and /dev/null differ diff --git a/WeeXnes/Images/settings.png b/WeeXnes/Images/settings.png deleted file mode 100644 index 44ca6a8..0000000 Binary files a/WeeXnes/Images/settings.png and /dev/null differ diff --git a/WeeXnes/Images/yellow.png b/WeeXnes/Images/yellow.png deleted file mode 100644 index 606c3a8..0000000 Binary files a/WeeXnes/Images/yellow.png and /dev/null differ diff --git a/WeeXnes/Keys/KeyItem.cs b/WeeXnes/Keys/KeyItem.cs deleted file mode 100644 index 543c0fe..0000000 --- a/WeeXnes/Keys/KeyItem.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WeeXnes.Keys -{ - public class KeyItem - { - public string name { get; set; } - public string value { get; set; } - public KeyItem(string _name, string _value) - { - this.name = _name; - this.value = _value; - } - } -} diff --git a/WeeXnes/Keys/KeyManagerLib.cs b/WeeXnes/Keys/KeyManagerLib.cs deleted file mode 100644 index 76bde9a..0000000 --- a/WeeXnes/Keys/KeyManagerLib.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace WeeXnes.Keys -{ - public class KeyManagerLib - { - public static List KeyList = new List(); - } -} diff --git a/WeeXnes/MVVM/View/DiscordRpcView.xaml b/WeeXnes/MVVM/View/DiscordRpcView.xaml deleted file mode 100644 index 1457e05..0000000 --- a/WeeXnes/MVVM/View/DiscordRpcView.xaml +++ /dev/null @@ -1,277 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WeeXnes/MainWindow.xaml.cs b/WeeXnes/MainWindow.xaml.cs index 77fcb42..8130e06 100644 --- a/WeeXnes/MainWindow.xaml.cs +++ b/WeeXnes/MainWindow.xaml.cs @@ -1,4 +1,6 @@ using System; +using System.Windows; +using System.Windows.Controls; using System.ComponentModel; using System.IO; using System.Windows; @@ -7,184 +9,23 @@ using System.Windows.Forms; using System.Windows.Input; using System.Windows.Media; using WeeXnes.Core; -using WeeXnes.MVVM.View; +using Wpf.Ui.Mvvm.Services; +using Button = System.Windows.Controls.Button; +using MessageBox = System.Windows.MessageBox; namespace WeeXnes { /// /// Interaktionslogik für MainWindow.xaml /// - public partial class MainWindow : Window + public partial class MainWindow { - System.Windows.Forms.NotifyIcon trayIcon = new System.Windows.Forms.NotifyIcon(); - private ContextMenuStrip trayIconMenu = new ContextMenuStrip(); public MainWindow() { - buildTrayMenu(); - trayIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name); - trayIcon.Visible = false; - trayIcon.DoubleClick += TrayIcon_DoubleClick; - trayIcon.ContextMenuStrip = trayIconMenu; InitializeComponent(); } - private void buildTrayMenu() - { - trayIconMenu.Items.Add("Show Window",null, (sender, args) => - { - this.Show(); - this.WindowState = WindowState.Normal; - trayIcon.Visible = false; - }); - //RPC MENU////////////////////////////////////////////////////////////////////////////////////// - //monke - - ToolStripMenuItem DiscordMenu = new ToolStripMenuItem("DiscordRPC"); - - - DiscordMenu.DropDownItems.Add("Stop DiscordRPC",null, (sender, args) => - { - controllRpcFromTray(false); - }); - DiscordMenu.DropDownItems.Add("Start DiscordRPC",null, (sender, args) => - { - controllRpcFromTray(true); - }); - trayIconMenu.Items.Add(DiscordMenu); - //////////////////////////////////////////////////////////////////////////////////////////// - trayIconMenu.Items.Add("Exit",null, (sender, args) => - { - this.Close(); - }); - trayIconMenu.Opening += (sender, args) => - { - - }; - - } - - - public void controllRpcFromTray(bool start) - { - - //set tray controlls. - if (start) - { - HomeMenuButton.Command.Execute(null); - HomeMenuButton.IsChecked = true; - Globals.info_RpcAutoStart = true; - RpcMenuButton.Command.Execute(null); - RpcMenuButton.IsChecked = true; - } - else - { - HomeMenuButton.Command.Execute(null); - HomeMenuButton.IsChecked = true; - } - } - private void TrayIcon_DoubleClick(object sender, EventArgs e) - { - this.Show(); - this.WindowState = WindowState.Normal; - trayIcon.Visible = false; - } - - private void Window_Loaded(object sender, RoutedEventArgs e) - { - CheckForFolders(); - CheckForSettingsFile(); - CheckForAutoStartup(); - } - - private void CheckForSettingsFile() - { - //SettingView.CheckSetting(); - SettingsManager.start(); - if (Globals.settings_osxStyleControlls.Value) - { - OSXControlls.Visibility = Visibility.Visible; - } - else - { - MinimizeBtn.Visibility = Visibility.Visible; - CloseBtn.Visibility = Visibility.Visible; - } - } - - private void Border_MouseDown(object sender, MouseButtonEventArgs e) - { - if (e.ChangedButton == MouseButton.Left) - this.DragMove(); - } - - private void Searchbox_TextChanged(object sender, TextChangedEventArgs e) - { - Globals.searchbox_content.Value = Searchbox.Text; - } - - private void CloseBtn_Click(object sender, RoutedEventArgs e) - { - if (Globals.info_isRpcRunning) - { - WindowState = WindowState.Minimized; - } - else - { - this.Close(); - } - } - - private void MinimizeBtn_Click(object sender, RoutedEventArgs e) - { - WindowState = WindowState.Minimized; - } - - private void CheckForAutoStartup() - { - if (Globals.info_RpcAutoStart) - { - WindowState = WindowState.Minimized; - RpcMenuButton.Command.Execute(null); - RpcMenuButton.IsChecked = true; - } - } - - private void CheckForFolders() - { - if (!Directory.Exists(Globals.AppDataPath)) - { - Directory.CreateDirectory(Globals.AppDataPath); - Console.WriteLine("Created AppDataPath"); - } - } - - private void Window_Deactivated(object sender, EventArgs e) - { - Window window = (Window)sender; - if (Globals.settings_alwaysOnTop.Value) - { - window.Topmost = true; - } - else - { - window.Topmost = false; - } - } - - private void Window_StateChanged(object sender, EventArgs e) - { - if (WindowState == System.Windows.WindowState.Minimized) - { - this.Hide(); - trayIcon.Visible = true; - } - } - - private void Window_Closing(object sender, CancelEventArgs e) - { - trayIcon.Dispose(); - } } } diff --git a/WeeXnes/Misc/CriticalMessage.xaml b/WeeXnes/Misc/CriticalMessage.xaml deleted file mode 100644 index 3aaee94..0000000 --- a/WeeXnes/Misc/CriticalMessage.xaml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - -