コード例 #1
0
        public ImportDialog(MainForm mainForm, string steamPathWithUser, ConfigFile configFile, List<SteamShortcut> steamShortcuts)
        {
            try
            {
                this.mainForm = mainForm;

                InitializeComponent();

                this.steamPathWithUser = steamPathWithUser;
                this.configFile = configFile;

                steamGameGroupBox.Visible = true;

                SteamShortcut emptyShortcut = new SteamShortcut();
                emptyShortcut.Name = "Select a shortcut";
                if (steamShortcuts.Count == 0)
                {
                    emptyShortcut.Name = "No shortcuts found";
                }
                shortcutsComboBox.Items.Add(emptyShortcut);
                shortcutsComboBox.Items.AddRange(steamShortcuts.ToArray());
                shortcutsComboBox.SelectedIndex = 0;

                foreach (SteamShortcut ss in shortcutsComboBox.Items)
                {
                    if (ss.Name.ToUpper().Trim() == configFile.GameName.ToUpper().Trim())
                    {
                        shortcutsComboBox.SelectedItem = ss;
                        break;
                    }
                }

                if (configFile.SteamAppId == null || configFile.SteamAppId <= 0)
                {
                    steamGameGroupBox.Visible = false;
                }
            }
            catch(Exception ex)
            {
                mainForm.GenericErrorHandler(ex);
            }
        }
コード例 #2
0
        private void LoadConfigFile()
        {
            gameNameTextBox.Text = "";
            configNameTextBox.Text = "";
            configDescriptionTextBox.Text = "";

            string shortcutsPath = Path.Combine(steamLocationTextBox.Text, @"userdata\" + ((SteamPlayer)steamUserComboBox.SelectedItem).id3 + @"\config\shortcuts.vdf");

            if (!string.IsNullOrWhiteSpace(configFileTextBox.Text))
            {
                Debug("Attempting to load config file " + configFileTextBox.Text);
                if (Path.GetExtension(configFileTextBox.Text).ToLower() == ".vdf")
                {
                    //This is a simple config file, nothing to parse
                    Debug("Simple config file loaded, nothing to parse");
                    loadedConfigFile = new ConfigFile();
                    loadedConfigFile.GameName = "<Simple Config Loaded>";
                    loadedConfigFile.Description = "";
                    loadedConfigFile.Name = Path.GetFileName(configFileTextBox.Text);
                    loadedConfigFile.FileName = Path.GetFileName(configFileTextBox.Text);
                    loadedConfigFile.ConfigData = File.ReadAllText(configFileTextBox.Text);
                }
                else
                {
                    using (StreamReader sr = File.OpenText(configFileTextBox.Text))
                    {
                        string fileContents = sr.ReadToEnd();

                        try
                        {
                            Debug("\tTrying parse config file");
                            loadedConfigFile = JsonConvert.DeserializeObject<ConfigFile>(fileContents);
                        }
                        catch (Exception parseException)
                        {
                            Debug("Error parsing config file", parseException);
                            MessageBox.Show("Unable to parse config file, please re-download and try again");
                        }
                    }
                }
                gameNameTextBox.Text = loadedConfigFile.GameName;
                configNameTextBox.Text = loadedConfigFile.Name;
                configDescriptionTextBox.Text = loadedConfigFile.Description;
            }
        }