Exemple #1
0
 private void buttonStore_Click(object sender, EventArgs e)
 {
     try
     {
         FileInfo f = new FileInfo(@".//Presets//" + textBoxFileName.Text + ".xml");
         if (f.Exists)
         {
             if (MessageBox.Show("Preset with this name already exists.\nOverwrite?", "Preset already exists",
                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
             {
                 return;
             }
             else
             {
                 f.Delete();
             }
         }
         toStore.description = textBoxDescription.Text;
         FileStream fs = f.OpenWrite();
         toStore.Serialize().Save(fs);
         fs.Close();
         chosenName   = textBoxFileName.Text;
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (Exception exc)
     {
         MessageBox.Show("Saving preset to a file failed (make sure the name is a valid name for a file):"
                         + Environment.NewLine + Environment.NewLine + exc.Message + Environment.NewLine,
                         "Storing preset failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #2
0
 private void buttonStore_Click(object sender, EventArgs e)
 {
     try
     {
         FileInfo f = new FileInfo(@".//Presets//" + textBoxFileName.Text + ".xml");
         if (f.Exists)
         {
             if (MessageBox.Show("Preset with this name already exists.\nOverwrite?", "Preset already exists",
                                 MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
             {
                 return;
             }
         }
         toStore.description = textBoxDescription.Text;
         // first try to write it into a memory stream to see if Save() finishes correctly
         // only if it does, delete the previous file (if there was one) and write into it
         MemoryStream ms = new MemoryStream();
         toStore.Serialize().Save(ms);
         if (f.Exists)
         {
             f.Delete();
         }
         FileStream fs = f.OpenWrite();
         ms.Position = 0;
         ms.CopyTo(fs);
         ms.Close();
         fs.Close();
         chosenName   = textBoxFileName.Text;
         DialogResult = DialogResult.OK;
         Close();
     }
     catch (Exception exc)
     {
         MessageBox.Show("Saving preset to a file failed (make sure the name is a valid name for a file):"
                         + Environment.NewLine + Environment.NewLine + exc.Message + Environment.NewLine,
                         "Storing preset failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }