Exemple #1
0
 public TextDialog()
 {
     InitializeComponent();
     settingsFile = new IniFile("SAMSettings.ini");
 }
Exemple #2
0
        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");
        }
Exemple #3
0
        public static string CheckSteamPath()
        {
            var settingsFile = new IniFile(SAMSettings.FILE_NAME);

            string steamPath = settingsFile.Read(SAMSettings.STEAM_PATH, SAMSettings.SECTION_STEAM);

            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(SAMSettings.STEAM_PATH, steamPath, SAMSettings.SECTION_STEAM);

            return(steamPath);
        }
Exemple #4
0
        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");
            }
            else
            {
                // Find Steam
                Utils.CheckSteamPath();
            }

            // 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")
            {
                int tryParseResult = -1;
                Int32.TryParse(settingsFile.Read("RecentAcc", "AutoLog"), out tryParseResult);

                if (tryParseResult != -1)
                {
                    recent    = true;
                    recentAcc = tryParseResult;
                }
                else
                {
                    settingsFile.Write("Recent", "False", "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")
            {
                int tryParseResult = -1;
                Int32.TryParse(settingsFile.Read("SelectedAcc", "AutoLog"), out tryParseResult);

                if (tryParseResult != -1)
                {
                    selected    = true;
                    selectedAcc = tryParseResult;
                }
                else
                {
                    settingsFile.Write("Selected", "False", "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");
        }