/// <summary> /// Creates a new AdParkImportForm /// </summary> /// <param name="conn">An IGADatabaseConnector object.</param> /// <param name="ads">An AdPack instance to import</param> public AdPackImportForm(IGADatabaseConnector conn, AdPack ads) { this.ads = ads; foreach (KeyValuePair<uint, ContentEntry> item in conn.GetAllEntries(false)) { ContentTypes.Add(item.Key, item.Value.contentType); } this.conn = conn; InitializeComponent(); }
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."); } }
private void ImportAdPack(String filename) { // attempt to open FileStream fs; try { fs = new FileStream(filename, FileMode.Open, FileAccess.Read); } catch (Exception ex) { MessageBox.Show("There was a problem opening the adpack. The error was: " + ex.Message); return; } AdPack ap = new AdPack(_igaconnector.AppID); try { ap.Deserialize(fs); } catch (Exception ex) { MessageBox.Show("An error occured reading the adpack. The error was: " + ex.Message); return; } if (ap.Files.Count == 0) { MessageBox.Show("Sorry, no importable ads were found."); return; } // jump to import wizard thingy AdPackImportForm apif = new AdPackImportForm(_igaconnector, ap); apif.ShowDialog(); if (apif.Success) { RefreshList(); } }