コード例 #1
0
        private void addToFlashpointToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (profileComboBox.SelectedItem == null)
            {
                MessageBox.Show("Please select a profile before saving the curation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (executable == null)
            {
                MessageBox.Show("Please flag a file as an executable.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var  profile     = (Profile)profileComboBox.SelectedItem;
            var  dest        = Path.Combine(flashpointPath, profile.DestinationPath);
            var  commandLine = GetLaunchCommand(profile.CommandLine, executable, dest);
            var  now         = DateTime.UtcNow;
            Game game        = new Game
            {
                ApplicationPath = profile.ApplicationPath,
                CommandLine     = commandLine,
                DateAdded       = now,
                DateModified    = now,
                Developer       = developerTextBox.Text,
                Id        = Guid.NewGuid(),
                Platform  = profile.Platform,
                Publisher = publisherTextBox.Text,
                Source    = sourceTextBox.Text,
                Title     = titleTextBox.Text,
                Series    = seriesTextBox.Text,
                PlayMode  = playModeComboBox.SelectedItem.ToString(),
                Hide      = extremeCheckBox.Checked,
                Genre     = genreComboBox.SelectedItem.ToString()
            };
            var platformRepo = Path.Combine(flashpointPath, "Data", "Platforms");
            var dataFile     = Path.Combine(platformRepo, profile.Platform + ".xml");

            string xml;

            using (var ms = new MemoryStream())
                using (var writer = new StreamWriter(ms, Encoding.UTF8))
                {
                    var serializer = new XmlSerializer(typeof(List <Game>), new XmlRootAttribute("LaunchBox"));
                    serializer.Serialize(writer, new List <Game>()
                    {
                        game
                    });
                    xml = Encoding.UTF8.GetString(ms.ToArray());
                }
            var lines = File.Exists(dataFile) ? File.ReadAllLines(dataFile).ToList() : null;

            if (lines == null || lines.Count < 3)
            {
                File.WriteAllText(dataFile, xml);
            }
            else
            {
                var xmlLines = xml.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                // Skip xml declaration and root element tags
                lines.InsertRange(2, xmlLines.ToList().GetRange(2, xmlLines.Length - 3));
                File.WriteAllLines(dataFile, lines);
            }
            source.CopyTo(dest);
            var platformImagesRepo = Path.Combine(flashpointPath, "Images", profile.Platform);
            var logoPath           = Path.Combine(platformImagesRepo, "Box - Front", titleTextBox.Text + "-01.png");
            var ssPath             = Path.Combine(platformImagesRepo, "Screenshot - Gameplay", titleTextBox.Text + "-01.png");

            Directory.CreateDirectory(Path.GetDirectoryName(logoPath));
            Directory.CreateDirectory(Path.GetDirectoryName(ssPath));
            logoPictureBox.Image.Save(logoPath, ImageFormat.Png);
            screenshotPictureBox.Image.Save(ssPath, ImageFormat.Png);
            MessageBox.Show("Added to Flashpoint!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }