Beispiel #1
0
        private void FormExportButton_Click(object sender, EventArgs e)
        {
            if (SelectedAdsCheckListBox.CheckedItems.Count > 0)
            {
                if (AuthorTextBox.Text.Trim().Length == 0)
                {
                    MessageBox.Show("You must enter an author name.");
                    return;
                }

                if (TitleTextBox.Text.Trim().Length == 0)
                {
                    MessageBox.Show("You must enter a title.");
                    return;
                }

                if (DescriptionTextBox.Text.Trim().Length == 0)
                {
                    DescriptionTextBox.Text = "No description.";
                }

                if (ExportAdpackSaveDialogue.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }

                // there are items
                AdPack adpack = new AdPack(AppID);
                for (uint x = 0; x < SelectedAdsCheckListBox.CheckedItems.Count; x++)
                {
                    // iterate through selected items...
                    uint index = (uint)SelectedAdsCheckListBox.Items.IndexOf(SelectedAdsCheckListBox.CheckedItems[(int)x]);

                    // grab data of image
                    byte[] ImageData = (conn.ExportImage(adcontentids[(int)index]));
                    if (ImageData.Length > 0)
                    {

                        // insert into system
                        AdPackEntry ape = ads[adcontentids[(int)index]];
                        ape.SetDDSData(ImageData);

                        adpack.Files.Add(ape.FileName, ape);
                    }
                    else
                    {
                        MessageBox.Show("Image #" + adcontentids[(int)index].ToString() + " (" + ads[index].FileName + ") cannot be exported as it has no data.");
                    }
                }
                adpack.Metadata["author"] = AuthorTextBox.Text.Trim();
                adpack.Metadata["title"] = TitleTextBox.Text.Trim();
                adpack.Metadata["description"] = DescriptionTextBox.Text.Trim();
                // all done, zip it up and finalize.
                FileStream fs;
                try
                {
                    fs = new FileStream(ExportAdpackSaveDialogue.FileName, FileMode.OpenOrCreate, FileAccess.Write);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to open adpack file for writing.  The error was: " + ex.Message);
                    return;
                }

                adpack.Serialize(fs);

                this.Close();

            }
            else
            {
                MessageBox.Show("You haven't selected any items for export.");
            }
        }