Esempio n. 1
0
        private void saveFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            var      profile     = (Profile)profileComboBox.SelectedItem;
            var      dest        = Path.Combine(flashpointPath, profile.DestinationPath);
            var      commandLine = GetLaunchCommand(profile.CommandLine, executable, dest);
            Curation curation    = new Curation
            {
                Title         = titleTextBox.Text,
                Genre         = genreComboBox.SelectedItem.ToString(),
                Developer     = developerTextBox.Text,
                Series        = seriesTextBox.Text,
                PlayMode      = playModeComboBox.SelectedItem.ToString(),
                Status        = statusComboBox.SelectedItem.ToString(),
                Source        = sourceTextBox.Text,
                Extreme       = extremeCheckBox.Checked ? "Yes" : "No",
                Platform      = profile.Platform,
                Publisher     = publisherTextBox.Text,
                LaunchCommand = commandLine,
                Notes         = notesTextBox.Text,
                AuthorNotes   = authorNotesTextBox.Text
            };

            if (dateTimePicker.Checked)
            {
                curation.ReleaseDate = dateTimePicker.Value;
            }
            string meta = MetaParser.Serialize(curation);
            var    ms   = new MemoryStream();

            using (var zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
            {
                var metaStream = new MemoryStream(Encoding.UTF8.GetBytes(meta));
                var name       = new string(curation.Title.Select(c => Path.GetInvalidPathChars().Contains(c) ? '_' : c).ToArray());
                var metaEntry  = zip.CreateEntry(name + "/meta.txt");
                using (var entryStream = metaEntry.Open())
                {
                    metaStream.CopyTo(entryStream);
                }
                var logoEntry = zip.CreateEntry(name + "/logo.png");
                using (var entryStream = logoEntry.Open())
                {
                    logoPictureBox.Image.Save(entryStream, ImageFormat.Png);
                }
                var ssEntry = zip.CreateEntry(name + "/ss.png");
                using (var entryStream = ssEntry.Open())
                {
                    screenshotPictureBox.Image.Save(entryStream, ImageFormat.Png);
                }
                source.CopyToZip(zip, name);
            }
            File.WriteAllBytes(saveFileDialog.FileName, ms.ToArray());
        }