示例#1
0
 public void saveTemplate(ObjectBuilder objectBuilder, bool force)
 {
     DialogResult result;
     String filename = "";
     if (!force)
     {
         SaveFileDialog saveDialog;
         saveDialog = new SaveFileDialog();
         saveDialog.Title = "Save Template";
         saveDialog.Filter = "Template files (*.ctl)|*.ctl";
         FolderOption path = Config.getOption("Save Path") as FolderOption;
         saveDialog.InitialDirectory = path.Value;
         result = saveDialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             filename = saveDialog.FileName;
         }
     }
     else
     {
         String path = "";
         if (CurrentProject != null)
         {
             path = CurrentProject.ProjectDirectory.TrimEnd('\\');
             path += "\\";
             filename = path + objectBuilder.Name + ".ctl";
         }
     }
     if (filename != "")
     {
         using (System.IO.Stream file = new FileStream(filename, FileMode.OpenOrCreate))
         {
             using (System.IO.BinaryWriter bw = new System.IO.BinaryWriter(file))
             {
                 Version v = new Version();
                 v.serialize(bw);
                 objectBuilder.serialize(bw);
                 objectBuilder.Dirty = false;
             }
         }
     }
 }