private void packPackButton_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.Description = "Select folder to package";
            if (folderBrowserDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && saveFileDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                Package newpack = null;
                try
                {
                    newpack = new Package(File.Create(saveFileDialog.FileName));
                    foreach (string path in Directory.GetFiles(folderBrowserDialog1.SelectedPath))
                    {
                        newpack.CreateEntry(path);
                    }

                    ProgressForm prog = new ProgressForm(callback => newpack.Save(saveFileDialog.FileName, callback));
                    prog.ShowDialog(this);
                    if (prog.Error == null)
                    {
                        MessageBox.Show(this, "Packing successful.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(this, "Error while packing: " + prog.Error, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Error while packing: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (newpack != null) newpack.Close();
                }
            }
        }
        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 packDumpButton_Click(object sender, EventArgs e)
 {
     if (pack == null)
     {
         MessageBox.Show(this, "Please open a sample package first.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     folderBrowserDialog1.Description = "Select folder to dump package to";
     if (folderBrowserDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             Directory.CreateDirectory(folderBrowserDialog1.SelectedPath);
             ProgressForm prog = new ProgressForm(callback =>
             {
                 var files = pack.Files;
                 for (int i = 0; i < files.Count; ++i)
                 {
                     PackageEntry entry = files[i];
                     if (callback != null) callback(string.Format("Extracting {0}", entry.Name), i, files.Count);
                     File.WriteAllBytes(Path.Combine(folderBrowserDialog1.SelectedPath, entry.Name), pack.GetFile(entry));
                 }
                 if (callback != null) callback("Complete!", files.Count, files.Count);
             });
             prog.ShowDialog(this);
             if (prog.Error == null)
             {
                 MessageBox.Show(this, "Extraction successful.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MessageBox.Show(this, "Error while extracting: " + prog.Error.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, "Error while extracting: " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }