private void importCurationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openCurationFileDialog.ShowDialog() == DialogResult.OK)
     {
         var logoStream = new MemoryStream();
         var ssStream   = new MemoryStream();
         var metaStream = new MemoryStream();
         using (var zip = ZipFile.OpenRead(openCurationFileDialog.FileName))
         {
             ZipArchiveEntry logoEntry, ssEntry, metaEntry;
             if (!zip.TryFind("logo.png", out logoEntry))
             {
                 MessageBox.Show("Cannot import curation. Missing logo.png.", "Invalid curation.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             if (!zip.TryFind("ss.png", out ssEntry))
             {
                 MessageBox.Show("Cannot import curation. Missing ss.png.", "Invalid curation.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             if (!zip.TryFind("meta.txt", out metaEntry))
             {
                 MessageBox.Show("Cannot import curation. Missing meta.txt.", "Invalid curation.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             logoEntry.Open().CopyTo(logoStream);
             ssEntry.Open().CopyTo(ssStream);
             metaEntry.Open().CopyTo(metaStream);
         }
         SetLogo(Image.FromStream(logoStream));
         SetScreenshot(Image.FromStream(ssStream));
         SetContent(ZipContentSource.FromPath(openCurationFileDialog.FileName));
         LoadCuration(MetaParser.Deserialize <Curation>(metaStream));
     }
 }
Example #2
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());
        }