private List <string> LoadSettings()
        {
            OnBeforeMoonbyteCommandsEventArgs OnBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeLoadSetting?.Invoke(this, OnBeforeRequest);

            if (OnBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                List <string> LoadedSettings = new List <string>();

                string loadedFileValue      = File.ReadAllText(settingsFullDirectory);
                string decryptedLoadedValue = Decrypt(loadedFileValue);

                LoadedSettings = decryptedLoadedValue.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();

                OnAfterLoadSetting?.Invoke(this, new EventArgs());
                return(LoadedSettings);
            }

            OnAfterLoadSetting?.Invoke(this, new EventArgs());
            return(null);
        }
        private string Decrypt(string input)
        {
            OnBeforeMoonbyteCommandsEventArgs OnBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeDecryptMessage?.Invoke(this, OnBeforeRequest);

            if (OnBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                input = input.Replace(" ", "+");
                byte[] cipherBytes = Convert.FromBase64String(input);
                using (Aes encryptor = Aes.Create())
                {
                    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey.GetEncryptionKey(), new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

                    encryptor.Key = pdb.GetBytes(32);
                    encryptor.IV  = pdb.GetBytes(16);

                    using (MemoryStream ms = new MemoryStream())
                    {
                        using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                        { cs.Write(cipherBytes, 0, cipherBytes.Length); cs.Close(); }

                        input = Encoding.Unicode.GetString(ms.ToArray());
                    }
                }
            }

            OnAfterDecryptMessage?.Invoke(this, new EventArgs());
            return(input);
        }
        private void SaveSettings(List <string> Settings)
        {
            OnBeforeMoonbyteCommandsEventArgs OnBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeSaveSetting?.Invoke(this, OnBeforeRequest);

            if (OnBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                string FullSettings = string.Join(Environment.NewLine, Settings);
                string saveValue    = Encrypt(FullSettings);
                File.WriteAllText(settingsFullDirectory, saveValue);

                Settings     = null;
                FullSettings = null;
                saveValue    = null;

                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            OnAfterSaveSetting?.Invoke(this, new EventArgs());
        }
        public void SaveSettings()
        {
            OnBeforeMoonbyteCommandsEventArgs onBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeSaveSettings?.Invoke(this, onBeforeRequest);

            if (onBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                File.WriteAllLines(settingsFullDirectory, settings);
            }

            OnAfterSaveSettings?.Invoke(this, new EventArgs());
        }
        public void DeleteSetting(string SettingTitle)
        {
            OnBeforeMoonbyteCommandsEventArgs onBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeDeleteSetting?.Invoke(this, onBeforeRequest);

            if (onBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                if (CheckValues())
                {
                    BaseCommands.BaseDeleteSetting(SettingTitle, settings);
                }
            }

            OnAfterDeleteSetting?.Invoke(this, new EventArgs());
        }
        public string ReadSetting(string SettingTitle)
        {
            OnBeforeMoonbyteCommandsEventArgs onBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeReadSetting?.Invoke(this, onBeforeRequest);

            if (onBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                if (CheckValues())
                {
                    OnAfterReadSetting?.Invoke(this, new EventArgs());
                    return(BaseCommands.BaseReadSetting(SettingTitle, settings));
                }
            }

            OnAfterReadSetting?.Invoke(this, new EventArgs());
            return(null);
        }
        public void EditSetting(string SettingTitle, string SettingValue)
        {
            OnBeforeMoonbyteCommandsEventArgs OnBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeEditSetting?.Invoke(this, OnBeforeRequest);

            if (OnBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                if (CheckValues())
                {
                    List <string> Settings = LoadSettings();

                    BaseCommands.BaseEditSetting(SettingTitle, SettingValue, Settings);

                    SaveSettings(Settings);
                }
            }

            OnAfterEditSetting?.Invoke(this, new EventArgs());
        }
        public bool CheckSetting(string SettingTitle)
        {
            OnBeforeMoonbyteCommandsEventArgs OnBeforeRequest = new OnBeforeMoonbyteCommandsEventArgs()
            {
                SettingDirectory = this.SettingsDirectory
            };

            OnBeforeCheckSetting?.Invoke(this, OnBeforeRequest);

            if (OnBeforeRequest.CancelRequest == BaseCommands.MoonbyteCancelRequest.Continue)
            {
                if (CheckValues())
                {
                    List <string> Settings = LoadSettings();

                    OnAfterCheckSetting?.Invoke(this, new EventArgs());
                    return(BaseCommands.BaseCheckSetting(SettingTitle, Settings, true));
                }
            }

            OnAfterCheckSetting?.Invoke(this, new EventArgs());
            return(false);
        }