private void packSaveButton_Click(object sender, EventArgs e) { if (manifest == null) { MessageBox.Show(this, "Please open a sample package first.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { saveDetails(curEntry); manifest.Author = packAuthorTextBox.Text; manifest.Website = packWebTextBox.Text; manifest.Description = packDescriptionTextBox.Text; writeManifest(manifest); List<PackageEntry> nonPresentEntries = new List<PackageEntry>(pack.Files); foreach (SampleEntry sample in manifest.Samples) { if (sample.StartPackFile != null) nonPresentEntries.Remove(sample.StartPackFile); if (sample.LoopPackFile != null) nonPresentEntries.Remove(sample.LoopPackFile); if (sample.EndPackFile != null) nonPresentEntries.Remove(sample.EndPackFile); } PackageEntry entry = pack.FindEntry("info.xml"); if (entry == null) pack.CreateEntry(Path.Combine(Path.GetTempPath(), "info.xml")); else { nonPresentEntries.Remove(entry); entry.Name = Path.Combine(Path.GetTempPath(), "info.xml"); entry.Offset = -1; } foreach (PackageEntry nonPresentEntry in nonPresentEntries) { pack.RemoveEntry(nonPresentEntry); } ProgressForm prog = new ProgressForm(new Action<Action<string, int, int>>(callback => pack.Save(openFileDialog.FileName, callback))); prog.ShowDialog(this); if (prog.Error == null) { itm = null; curEntry = null; samplesListView.Items.Clear(); ClearDetails(); refreshSamples(); MessageBox.Show(this, "Save successful.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Error while saving: " + prog.Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(this, "Error while saving: " + ex, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (File.Exists(Path.Combine(Path.GetTempPath(), "info.xml"))) File.Delete(Path.Combine(Path.GetTempPath(), "info.xml")); } }
private void addButton_Click(object sender, EventArgs e) { if (manifest == null) { MessageBox.Show(this, "Please open a sample package first.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SampleEntry entry = new SampleEntry { Name = "New Sample" }; manifest.Samples.Add(entry); curEntry = entry; ListViewItem itm = new ListViewItem(entry.Name) { Tag = entry }; samplesListView.Items.Add(itm); itm.Selected = true; itm.EnsureVisible(); }
void saveDetails(SampleEntry entry) { if (entry == null) return; entry.Name = sampNameTextBox.Text; entry.Type = sampTypeComboBox.Text; entry.Description = sampDescriptionTextBox.Text; entry.TagsString = sampTagsTextBox.Text; itm.SubItems[0].Text = entry.Name; itm.SubItems[1].Text = entry.Type; itm.SubItems[2].Text = entry.Description; }
void loadDetails(SampleEntry entry) { sampNameTextBox.Text = entry.Name; sampTypeComboBox.Text = entry.Type; sampDescriptionTextBox.Text = entry.Description; sampTagsTextBox.Text = entry.TagsString; PackageEntry pEntry = entry.StartPackFile; if (pEntry == null) { sampStartLabel.Text = "(none)"; } else { sampStartLabel.Text = (pEntry.Offset == -1 ? "(disk) " : string.Empty) + pEntry.Name; } pEntry = entry.LoopPackFile; if (pEntry == null) { sampLoopLabel.Text = "(none)"; } else { sampLoopLabel.Text = (pEntry.Offset == -1 ? "(disk) " : string.Empty) + pEntry.Name; } pEntry = entry.EndPackFile; if (pEntry == null) { sampEndLabel.Text = "(none)"; } else { sampEndLabel.Text = (pEntry.Offset == -1 ? "(disk) " : string.Empty) + pEntry.Name; } }
private void samplesListView_SelectedIndexChanged(object sender, EventArgs e) { if (pack == null) return; saveDetails(curEntry); if (samplesListView.SelectedIndices.Count == 0) { curEntry = null; ClearDetails(); } else { itm = samplesListView.SelectedItems[0]; curEntry = itm.Tag as SampleEntry; loadDetails(curEntry); } }
void openFile() { if (pack != null) pack.Close(); samplesListView.Items.Clear(); ClearDetails(); packAuthorTextBox.Text = packDescriptionTextBox.Text = packWebTextBox.Text = string.Empty; fileNameLabel.Text = string.Empty; pack = null; manifest = null; curEntry = null; pack = new Package(File.OpenRead(openFileDialog.FileName)); pack.Load(); fileNameLabel.Text = Path.GetFileName(openFileDialog.FileName); refreshSamples(); }