public void HandleDeprecatedSettings() { // Update Recent and Selected login setting names. if (File.KeyExists("Recent", SECTION_AUTOLOG)) { File.Write(LOGIN_RECENT_ACCOUNT, File.Read("Recent", SECTION_AUTOLOG), SECTION_AUTOLOG); File.DeleteKey("Recent", SECTION_AUTOLOG); } if (File.KeyExists("RecentAcc", SECTION_AUTOLOG)) { File.Write(RECENT_ACCOUNT_INDEX, File.Read("RecentAcc", SECTION_AUTOLOG), SECTION_AUTOLOG); File.DeleteKey("RecentAcc", SECTION_AUTOLOG); } if (File.KeyExists("Selected", SECTION_AUTOLOG)) { File.Write(LOGIN_SELECTED_ACCOUNT, File.Read("Selected", SECTION_AUTOLOG), SECTION_AUTOLOG); File.DeleteKey("Selected", SECTION_AUTOLOG); } if (File.KeyExists("SelectedAcc", SECTION_AUTOLOG)) { File.Write(SELECTED_ACCOUNT_INDEX, File.Read("SelectedAcc", SECTION_AUTOLOG), SECTION_AUTOLOG); File.DeleteKey("SelectedAcc", SECTION_AUTOLOG); } // Move Steam file path to it's own section. if (File.KeyExists(SECTION_STEAM, SECTION_GENERAL)) { File.Write(STEAM_PATH, File.Read(SECTION_STEAM, SECTION_GENERAL), SECTION_STEAM); File.DeleteKey(SECTION_STEAM, SECTION_GENERAL); } // Move button size to 'Customize' section. if (File.KeyExists(BUTTON_SIZE, SECTION_GENERAL)) { File.Write(BUTTON_SIZE, File.Read(BUTTON_SIZE, SECTION_GENERAL), SECTION_CUSTOMIZE); File.DeleteKey(BUTTON_SIZE, SECTION_GENERAL); } // Update developer launch parameter. if (File.KeyExists("developer", SECTION_PARAMETERS)) { File.Write(DEVELOPER_PARAMETER, File.Read("developer", SECTION_PARAMETERS), SECTION_PARAMETERS); File.DeleteKey("developer", SECTION_PARAMETERS); } }
public void HandleDeprecatedSettings() { // Update Recent and Selected login setting names. if (File.KeyExists("Recent", "AutoLog")) { File.Write("LoginRecentAccount", File.Read("Recent", "AutoLog"), "AutoLog"); File.DeleteKey("Recent", "AutoLog"); } if (File.KeyExists("RecentAcc", "AutoLog")) { File.Write("RecentAccountIndex", File.Read("RecentAcc", "AutoLog"), "AutoLog"); File.DeleteKey("RecentAcc", "AutoLog"); } if (File.KeyExists("Selected", "AutoLog")) { File.Write("LoginSelectedAccount", File.Read("Selected", "AutoLog"), "AutoLog"); File.DeleteKey("Selected", "AutoLog"); } if (File.KeyExists("SelectedAcc", "AutoLog")) { File.Write("SelectedAccountIndex", File.Read("SelectedAcc", "AutoLog"), "AutoLog"); File.DeleteKey("SelectedAcc", "AutoLog"); } // Move Steam file path to it's own section. if (File.KeyExists("Steam", "Settings")) { File.Write("Path", File.Read("Steam", "Settings"), "Steam"); File.DeleteKey("Steam", "Settings"); } // Move button size to 'Customize' section. if (File.KeyExists("ButtonSize", "Settings")) { File.Write("ButtonSize", File.Read("ButtonSize", "Settings"), "Customize"); File.DeleteKey("ButtonSize", "Settings"); } }
public static string CheckSteamPath() { var settingsFile = new IniFile("SAMSettings.ini"); string steamPath = settingsFile.Read("Steam", "Settings"); int tryCount = 0; // If Steam's filepath was not specified in settings or is invalid, attempt to find it and save it. while (steamPath == null || !File.Exists(steamPath + "\\steam.exe")) { // Check registry keys first. string regPath = GetSteamPathFromRegistry(); string localPath = System.Windows.Forms.Application.StartupPath; if (Directory.Exists(regPath)) { steamPath = regPath; } // Check if SAM is isntalled in Steam directory. // Useful for users in portable mode. else if (File.Exists(localPath + "\\steam.exe")) { steamPath = localPath; } // Prompt user for manual selection. else { if (tryCount == 0) { MessageBox.Show("Could not find Steam path automatically.\n\nPlease select Steam manually."); } // Create OpenFileDialog OpenFileDialog dlg = new OpenFileDialog { DefaultExt = ".exe", Filter = "Steam (*.exe)|*.exe" }; // Display OpenFileDialog by calling ShowDialog method Nullable <bool> result = dlg.ShowDialog(); // Get the selected file path if (result == true) { steamPath = Path.GetDirectoryName(dlg.FileName) + "\\"; } } if (steamPath == null || steamPath == string.Empty) { MessageBoxResult messageBoxResult = MessageBox.Show("Steam path required!\n\nTry again?", "Confirm", MessageBoxButton.YesNo); if (messageBoxResult.Equals(MessageBoxResult.No)) { Environment.Exit(0); } } tryCount++; } // Save path to settings file. settingsFile.Write("Steam", steamPath, "Settings"); return(steamPath); }
private void LoadSettings() { settingsFile = new IniFile("SAMSettings.ini"); accPerRow = settingsFile.Read("AccountsPerRow", "Settings"); if (!Regex.IsMatch(accPerRow, @"^\d+$") || Int32.Parse(accPerRow) < 1) { accPerRow = "1"; } if (settingsFile.KeyExists("Steam", "Settings")) { steamPath = settingsFile.Read("Steam", "Settings"); } // If the recent autolog entry exists and is set to true. // else create defualt settings file entry. if (settingsFile.KeyExists("Recent", "AutoLog") && settingsFile.Read("Recent", "AutoLog") == "True" && Int32.Parse(settingsFile.Read("RecentAcc", "AutoLog")) >= 0) { recent = true; recentAcc = Int32.Parse(settingsFile.Read("RecentAcc", "AutoLog")); } else if (!settingsFile.KeyExists("Recent", "AutoLog")) { settingsFile.Write("Recent", "False", "AutoLog"); settingsFile.Write("RecentAcc", "-1", "AutoLog"); } // If the selected autolog entry exists and is set to true. // else create defualt settings file entry. if (settingsFile.KeyExists("Selected", "AutoLog") && settingsFile.Read("Selected", "AutoLog") == "True") { selected = true; selectedAcc = Int32.Parse(settingsFile.Read("SelectedAcc", "AutoLog")); } else if (!settingsFile.KeyExists("Selected", "AutoLog")) { settingsFile.Write("Selected", "False", "AutoLog"); settingsFile.Write("SelectedAcc", "-1", "AutoLog"); } if (settingsFile.KeyExists("StartMinimized", "Settings") && settingsFile.Read("StartMinimized", "Settings") == "True") { WindowState = WindowState.Minimized; } else if (!settingsFile.KeyExists("StartMinimized", "Settings")) { settingsFile.Write("StartMinimized", "False", "Settings"); } if (File.Exists("info.dat")) { StreamReader datReader = new StreamReader("info.dat"); string temp = datReader.ReadLine(); datReader.Close(); // If the user is some how using an older info.dat, delete it. if (!temp.Contains("xml")) { MessageBox.Show("Your info.dat is out of date and must be deleted.\nSorry for the inconvenience!", "Invalid File", MessageBoxButton.OK, MessageBoxImage.Information); try { File.Delete("info.dat"); } catch (Exception m) { Console.WriteLine(m.Message); } } } settingsFile.Write("Version", AssemblyVer, "System"); }
private void NewAccount() { // User entered info var dialog = new TextDialog(); if (dialog.ShowDialog() == true && dialog.AccountText != "" && dialog.PasswordText != "") { account = dialog.AccountText; string password = dialog.PasswordText; string sharedSecret = dialog.SharedSecretText; string aviUrl; if (dialog.AviText != null && dialog.AviText.Length > 1) { aviUrl = dialog.AviText; } else { aviUrl = Utils.HtmlAviScrape(dialog.UrlText); } string steamId = dialog.SteamId; // If the auto login checkbox was checked, update settings file and global variables. if (dialog.AutoLogAccountIndex == true) { settingsFile.Write("SelectedAcc", (encryptedAccounts.Count + 1).ToString(), "AutoLog"); settingsFile.Write("Selected", "True", "AutoLog"); settingsFile.Write("Recent", "False", "AutoLog"); selected = true; recent = false; selectedAcc = encryptedAccounts.Count + 1; } try { // Encrypt info before saving to file ePassword = StringCipher.Encrypt(password, eKey); eSharedSecret = StringCipher.Encrypt(sharedSecret, eKey); encryptedAccounts.Add(new Account() { Name = dialog.AccountText, Password = ePassword, SharedSecret = eSharedSecret, ProfUrl = dialog.UrlText, AviUrl = aviUrl, SteamId = steamId, Description = dialog.DescriptionText }); Utils.Serialize(encryptedAccounts); RefreshWindow(); } catch (Exception m) { MessageBox.Show(m.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); var itemToRemove = encryptedAccounts.Single(r => r.Name == dialog.AccountText); encryptedAccounts.Remove(itemToRemove); Utils.Serialize(encryptedAccounts); NewAccount(); } } }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Version number from assembly AssemblyVer = Assembly.GetExecutingAssembly().GetName().Version.ToString(); MenuItem ver = new MenuItem(); MenuItem newExistMenuItem = (MenuItem)this.FileMenu.Items[2]; ver.Header = "v" + AssemblyVer; ver.IsEnabled = false; newExistMenuItem.Items.Add(ver); // Check for a new version. if (await UpdateCheck.CheckForUpdate(updateCheckUrl) == 1) { // An update is available, but user has chosen not to update. ver.Header = "Update Available!"; ver.Click += Ver_Click; ver.IsEnabled = true; } // If no settings file exists, create one and initialize values. if (!File.Exists("SAMSettings.ini")) { settingsFile = new IniFile("SAMSettings.ini"); settingsFile.Write("Version", AssemblyVer, "System"); settingsFile.Write("AccountsPerRow", "5", "Settings"); settingsFile.Write("StartWithWindows", "False", "Settings"); settingsFile.Write("StartMinimized", "False", "Settings"); settingsFile.Write("AccountsPerRow", "5", "Settings"); settingsFile.Write("Recent", "False", "AutoLog"); settingsFile.Write("RecentAcc", "", "AutoLog"); settingsFile.Write("Selected", "False", "AutoLog"); settingsFile.Write("SelectedAcc", "", "AutoLog"); accPerRow = "5"; } // Else load settings from preexisting file. else { LoadSettings(); } loginThreads = new List <Thread>(); // Load window with account buttons. RefreshWindow(); // Login to auto log account if enabled and steam is not already open. Process[] SteamProc = Process.GetProcessesByName("Steam"); if (SteamProc.Length == 0) { if (recent == true) { Login(recentAcc); } else if (selected == true) { Login(selectedAcc); } } }
private void SaveSettings(string apr) { settingsFile = new IniFile("SAMSettings.ini"); if (passwordProtectCheckBox.IsChecked == true && !Convert.ToBoolean(settingsFile.Read("PasswordProtect", "Settings"))) { var passwordDialog = new PasswordWindow(); if (passwordDialog.ShowDialog() == true && passwordDialog.PasswordText != "") { Password = passwordDialog.PasswordText; settingsFile.Write("PasswordProtect", "true", "Settings"); } else { Password = ""; } } else if (passwordProtectCheckBox.IsChecked == false && Convert.ToBoolean(settingsFile.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; } settingsFile.Write("PasswordProtect", "false", "Settings"); Password = ""; Decrypt = true; } else if (passwordProtectCheckBox.IsChecked == false) { settingsFile.Write("PasswordProtect", "false", "Settings"); } settingsFile.Write("RememberPassword", rememberLoginPasswordCheckBox.IsChecked.ToString(), "Settings"); settingsFile.Write("ClearUserData", clearUserDataCheckBox.IsChecked.ToString(), "Settings"); settingsFile.Write("AccountsPerRow", apr, "Settings"); settingsFile.Write("ButtonSize", buttonSizeSpinBox.Text, "Settings"); settingsFile.Write("SleepTime", sleepTimeSpinBox.Text, "Settings"); if (startupCheckBox.IsChecked == true) { settingsFile.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); } settingsFile.Write("StartWithWindows", "false", "Settings"); } settingsFile.Write("StartMinimized", startupMinCheckBox.IsChecked.ToString(), "Settings"); settingsFile.Write("MinimizeToTray", minimizeToTrayCheckBox.IsChecked.ToString(), "Settings"); settingsFile.Write("Recent", mostRecentCheckBox.IsChecked.ToString(), "AutoLog"); settingsFile.Write("Selected", selectedAccountCheckBox.IsChecked.ToString(), "AutoLog"); settingsFile.Write("cafeapplaunch", CafeAppLaunchCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("clearbeta", ClearBetaCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("console", ConsoleCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("login", LoginCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("developer", DeveloperCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("forceservice", ForceServiceCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("nocache", NoCacheCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("noverifyfiles", NoVerifyFilesCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("silent", SilentCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("single_core", SingleCoreCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("tcp", TcpCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("tenfoot", TenFootCheckBox.IsChecked.ToString(), "Parameters"); settingsFile.Write("Steam", SteamPathTextBox.Text, "Settings"); }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { // Verion number from assembly AssemblyVer = Assembly.GetExecutingAssembly().GetName().Version.ToString(); MenuItem ver = new MenuItem(); MenuItem newExistMenuItem = (MenuItem)this.FileMenu.Items[2]; ver.Header = "v" + AssemblyVer; ver.IsEnabled = false; newExistMenuItem.Items.Add(ver); // Check for a new version. if (await UpdateCheck.CheckForUpdate("http://textuploader.com/58mva/raw") == 1) { // An update is available, but user has chosen not to update. ver.Header = "Update Available!"; ver.Click += Ver_Click; ver.IsEnabled = true; } // If no settings file exists, create one and initialize values. if (!File.Exists("SAMSettings.ini")) { settingsFile = new IniFile("SAMSettings.ini"); settingsFile.Write("Version", AssemblyVer, "System"); settingsFile.Write("AccountsPerRow", "5", "Settings"); settingsFile.Write("StartWithWindows", "False", "Settings"); settingsFile.Write("StartMinimized", "False", "Settings"); settingsFile.Write("AccountsPerRow", "5", "Settings"); settingsFile.Write("Recent", "False", "AutoLog"); settingsFile.Write("RecentAcc", "", "AutoLog"); settingsFile.Write("Selected", "False", "AutoLog"); settingsFile.Write("SelectedAcc", "", "AutoLog"); accPerRow = "5"; } // Else load settings from preexisting file. else { settingsFile = new IniFile("SAMSettings.ini"); accPerRow = settingsFile.Read("AccountsPerRow", "Settings"); if (!Regex.IsMatch(accPerRow, @"^\d+$") || Int32.Parse(accPerRow) < 1) { accPerRow = "1"; } if (settingsFile.KeyExists("Steam", "Settings")) { steamPath = settingsFile.Read("Steam", "Settings"); } // If the recent autolog entry exists and is set to true. // else create defualt settings file entry. if (settingsFile.KeyExists("Recent", "AutoLog") && settingsFile.Read("Recent", "AutoLog") == "True" && Int32.Parse(settingsFile.Read("RecentAcc", "AutoLog")) >= 0) { recent = true; recentAcc = Int32.Parse(settingsFile.Read("RecentAcc", "AutoLog")); } else if (!settingsFile.KeyExists("Recent", "AutoLog")) { settingsFile.Write("Recent", "False", "AutoLog"); settingsFile.Write("RecentAcc", "-1", "AutoLog"); } // If the selected autolog entry exists and is set to true. // else create defualt settings file entry. if (settingsFile.KeyExists("Selected", "AutoLog") && settingsFile.Read("Selected", "AutoLog") == "True") { selected = true; selectedAcc = Int32.Parse(settingsFile.Read("SelectedAcc", "AutoLog")); } else if (!settingsFile.KeyExists("Selected", "AutoLog")) { settingsFile.Write("Selected", "False", "AutoLog"); settingsFile.Write("SelectedAcc", "-1", "AutoLog"); } if (settingsFile.KeyExists("StartMinimized", "Settings") && settingsFile.Read("StartMinimized", "Settings") == "True") { WindowState = WindowState.Minimized; } else if (!settingsFile.KeyExists("StartMinimized", "Settings")) { settingsFile.Write("StartMinimized", "False", "Settings"); } if (File.Exists("info.dat")) { StreamReader datReader = new StreamReader("info.dat"); string temp = datReader.ReadLine(); datReader.Close(); // If the user is some how using an older info.dat, delete it. if (!temp.Contains("xml")) { MessageBox.Show("Your info.dat is out of date and must be deleted.\nSorry for the inconvenience!", "Invalid File", MessageBoxButton.OK, MessageBoxImage.Information); try { File.Delete("info.dat"); } catch (Exception m) { Console.WriteLine(m.Message); } } } settingsFile.Write("Version", AssemblyVer, "System"); } // Load window with account buttons. RefreshWindow(); // Login to auto log account if enabled and steam is not already open. Process[] SteamProc = Process.GetProcessesByName("Steam"); if (SteamProc.Length == 0) { if (recent == true) { Login(recentAcc); } else if (selected == true) { Login(selectedAcc); } } }