private void SaveSettings(string apr) { settings.File = new IniFile(SAMSettings.FILE_NAME); if (passwordProtectCheckBox.IsChecked == true && !Convert.ToBoolean(settings.File.Read(SAMSettings.PASSWORD_PROTECT, SAMSettings.SECTION_GENERAL))) { var passwordDialog = new PasswordWindow(); if (passwordDialog.ShowDialog() == true && passwordDialog.PasswordText != "") { Password = passwordDialog.PasswordText; settings.File.Write(SAMSettings.PASSWORD_PROTECT, true.ToString(), SAMSettings.SECTION_GENERAL); } else { Password = ""; } } else if (passwordProtectCheckBox.IsChecked == false && Convert.ToBoolean(settings.File.Read(SAMSettings.PASSWORD_PROTECT, SAMSettings.SECTION_GENERAL))) { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to decrypt your data file?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.Yes) { var passwordDialog = new PasswordWindow(); if (passwordDialog.ShowDialog() == true) { messageBoxResult = MessageBoxResult.OK; while (messageBoxResult == MessageBoxResult.OK) { try { Utils.PasswordDeserialize("info.dat", passwordDialog.PasswordText); messageBoxResult = MessageBoxResult.None; } catch (Exception e) { Console.WriteLine(e.Message); messageBoxResult = MessageBox.Show("Invalid Password", "Invalid", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.Cancel) { passwordProtectCheckBox.IsChecked = true; return; } passwordDialog = new PasswordWindow(); passwordDialog.ShowDialog(); } } } } else { passwordProtectCheckBox.IsChecked = true; return; } settings.File.Write(SAMSettings.PASSWORD_PROTECT, false.ToString(), SAMSettings.SECTION_GENERAL); Password = ""; Decrypt = true; } else if (passwordProtectCheckBox.IsChecked == false) { settings.File.Write(SAMSettings.PASSWORD_PROTECT, false.ToString(), SAMSettings.SECTION_GENERAL); } // General settings.File.Write(SAMSettings.REMEMBER_PASSWORD, rememberLoginPasswordCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.CLEAR_USER_DATA, clearUserDataCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.ACCOUNTS_PER_ROW, apr, SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.SLEEP_TIME, sleepTimeSpinBox.Text, SAMSettings.SECTION_GENERAL); if (startupCheckBox.IsChecked == true) { settings.File.Write(SAMSettings.START_WITH_WINDOWS, true.ToString(), SAMSettings.SECTION_GENERAL); WshShell shell = new WshShell(); string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + SAMshortcut; IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress); shortcut.Description = "Start with windows shortcut for SAM."; shortcut.TargetPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + SAMexe; shortcut.WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); shortcut.Save(); } else { string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + SAMshortcut; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } settings.File.Write(SAMSettings.START_WITH_WINDOWS, false.ToString(), SAMSettings.SECTION_GENERAL); } settings.File.Write(SAMSettings.START_MINIMIZED, startupMinCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.MINIMIZE_TO_TRAY, minimizeToTrayCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.HIDE_ADD_BUTTON, HideAddButtonCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.CHECK_FOR_UPDATES, CheckForUpdatesCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.CLOSE_ON_LOGIN, CloseOnLoginCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.LIST_VIEW, ListViewCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); settings.File.Write(SAMSettings.SANDBOX_MODE, SandboxModeCheckBox.IsChecked.ToString(), SAMSettings.SECTION_GENERAL); // Customize settings.File.Write(SAMSettings.THEME, ThemeSelectBox.Text, SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.ACCENT, AccentSelectBox.Text, SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_SIZE, buttonSizeSpinBox.Text, SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_COLOR, new ColorConverter().ConvertToString(ButtonColorPicker.SelectedColor), SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_FONT_SIZE, ButtonFontSizeSpinBox.Text, SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_FONT_COLOR, new ColorConverter().ConvertToString(ButtonFontColorPicker.SelectedColor), SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_BANNER_COLOR, new ColorConverter().ConvertToString(BannerColorPicker.SelectedColor), SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_BANNER_FONT_SIZE, BannerFontSizeSpinBox.Text, SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.BUTTON_BANNER_FONT_COLOR, new ColorConverter().ConvertToString(BannerFontColorPicker.SelectedColor), SAMSettings.SECTION_CUSTOMIZE); settings.File.Write(SAMSettings.HIDE_BAN_ICONS, HideBanIconsCheckBox.IsChecked.ToString(), SAMSettings.SECTION_CUSTOMIZE); // AutoLog settings.File.Write(SAMSettings.LOGIN_RECENT_ACCOUNT, mostRecentCheckBox.IsChecked.ToString(), SAMSettings.SECTION_AUTOLOG); settings.File.Write(SAMSettings.LOGIN_RECENT_ACCOUNT, selectedAccountCheckBox.IsChecked.ToString(), SAMSettings.SECTION_AUTOLOG); // Steam settings.File.Write(SAMSettings.STEAM_PATH, SteamPathTextBox.Text, SAMSettings.SECTION_STEAM); settings.File.Write(SAMSettings.STEAM_API_KEY, Regex.Replace(ApiKeyTextBox.Text, @"\s+", string.Empty), SAMSettings.SECTION_STEAM); settings.File.Write(SAMSettings.AUTO_RELOAD_ENABLED, AutoReloadCheckBox.IsChecked.ToString(), SAMSettings.SECTION_STEAM); settings.File.Write(SAMSettings.AUTO_RELOAD_INTERVAL, AutoReloadIntervalSpinBox.Text, SAMSettings.SECTION_STEAM); // Parameters settings.File.Write(SAMSettings.CAFE_APP_LAUNCH_PARAMETER, CafeAppLaunchCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.CLEAR_BETA_PARAMETER, ClearBetaCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.CONSOLE_PARAMETER, ConsoleCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.LOGIN_PARAMETER, LoginCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.DEVELOPER_PARAMETER, DeveloperCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.FORCE_SERVICE_PARAMETER, ForceServiceCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.NO_CACHE_PARAMETER, NoCacheCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.NO_VERIFY_FILES_PARAMETER, NoVerifyFilesCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.SILENT_PARAMETER, SilentCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.SINGLE_CORE_PARAMETER, SingleCoreCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.TCP_PARAMETER, TcpCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.TEN_FOOT_PARAMETER, TenFootCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.CUSTOM_PARAMETERS, CustomParametersCheckBox.IsChecked.ToString(), SAMSettings.SECTION_PARAMETERS); settings.File.Write(SAMSettings.CUSTOM_PARAMETERS_VALUE, CustomParametersTextBox.Text, SAMSettings.SECTION_PARAMETERS); }
private void SaveSettings(string apr) { settings.File = new IniFile("SAMSettings.ini"); if (passwordProtectCheckBox.IsChecked == true && !Convert.ToBoolean(settings.File.Read("PasswordProtect", "Settings"))) { var passwordDialog = new PasswordWindow(); if (passwordDialog.ShowDialog() == true && passwordDialog.PasswordText != "") { Password = passwordDialog.PasswordText; settings.File.Write("PasswordProtect", "true", "Settings"); } else { Password = ""; } } else if (passwordProtectCheckBox.IsChecked == false && Convert.ToBoolean(settings.File.Read("PasswordProtect", "Settings"))) { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to decrypt your data file?", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.Yes) { var passwordDialog = new PasswordWindow(); if (passwordDialog.ShowDialog() == true) { messageBoxResult = MessageBoxResult.OK; while (messageBoxResult == MessageBoxResult.OK) { try { Utils.PasswordDeserialize("info.dat", passwordDialog.PasswordText); messageBoxResult = MessageBoxResult.None; } catch (Exception e) { Console.WriteLine(e.Message); messageBoxResult = MessageBox.Show("Invalid Password", "Invalid", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.Cancel) { passwordProtectCheckBox.IsChecked = true; return; } passwordDialog = new PasswordWindow(); passwordDialog.ShowDialog(); } } } } else { passwordProtectCheckBox.IsChecked = true; return; } settings.File.Write("PasswordProtect", "false", "Settings"); Password = ""; Decrypt = true; } else if (passwordProtectCheckBox.IsChecked == false) { settings.File.Write("PasswordProtect", "false", "Settings"); } // General settings.File.Write("RememberPassword", rememberLoginPasswordCheckBox.IsChecked.ToString(), "Settings"); settings.File.Write("ClearUserData", clearUserDataCheckBox.IsChecked.ToString(), "Settings"); settings.File.Write("AccountsPerRow", apr, "Settings"); settings.File.Write("SleepTime", sleepTimeSpinBox.Text, "Settings"); if (startupCheckBox.IsChecked == true) { settings.File.Write("StartWithWindows", "true", "Settings"); WshShell shell = new WshShell(); string shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\SAM.lnk"; IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress); shortcut.Description = "Start with windows shortcut for SAM."; shortcut.TargetPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\SAM.exe"; shortcut.WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); shortcut.Save(); } else { string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\SAM.lnk"; if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } settings.File.Write("StartWithWindows", "false", "Settings"); } settings.File.Write("StartMinimized", startupMinCheckBox.IsChecked.ToString(), "Settings"); settings.File.Write("MinimizeToTray", minimizeToTrayCheckBox.IsChecked.ToString(), "Settings"); settings.File.Write("HideAddButton", HideAddButtonCheckBox.IsChecked.ToString(), "Settings"); settings.File.Write("CheckForUpdates", CheckForUpdatesCheckBox.IsChecked.ToString(), "Settings"); // Customize settings.File.Write("ButtonSize", buttonSizeSpinBox.Text, "Customize"); settings.File.Write("ButtonColor", new ColorConverter().ConvertToString(ButtonColorPicker.SelectedColor), "Customize"); settings.File.Write("ButtonFontSize", ButtonFontSizeSpinBox.Text, "Customize"); settings.File.Write("ButtonFontColor", new ColorConverter().ConvertToString(ButtonFontColorPicker.SelectedColor), "Customize"); settings.File.Write("ButtonBannerColor", new ColorConverter().ConvertToString(BannerColorPicker.SelectedColor), "Customize"); settings.File.Write("ButtonBannerFontSize", BannerFontSizeSpinBox.Text, "Customize"); settings.File.Write("ButtonBannerFontColor", new ColorConverter().ConvertToString(BannerFontColorPicker.SelectedColor), "Customize"); // AutoLog settings.File.Write("LoginRecentAccount", mostRecentCheckBox.IsChecked.ToString(), "AutoLog"); settings.File.Write("LoginSelectedAccount", selectedAccountCheckBox.IsChecked.ToString(), "AutoLog"); // Steam settings.File.Write("Path", SteamPathTextBox.Text, "Steam"); // Parameters settings.File.Write("cafeapplaunch", CafeAppLaunchCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("clearbeta", ClearBetaCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("console", ConsoleCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("login", LoginCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("developer", DeveloperCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("forceservice", ForceServiceCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("nocache", NoCacheCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("noverifyfiles", NoVerifyFilesCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("silent", SilentCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("single_core", SingleCoreCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("tcp", TcpCheckBox.IsChecked.ToString(), "Parameters"); settings.File.Write("tenfoot", TenFootCheckBox.IsChecked.ToString(), "Parameters"); }