public bool Save(string folderPath) { bool result = false; // Save using ID // save def using name // LibraryId // Date // Path in tree // path to Def // save def on path FileStream fs; string dataFileName = folderPath + System.IO.Path.DirectorySeparatorChar + GetDataPath(); if (Definition is Vex.Timeline) { //save definition File.WriteAllText(dataFileName, string.Empty); fs = new FileStream(dataFileName, FileMode.OpenOrCreate); XmlSerializer xs = new XmlSerializer(this.Definition.GetType()); xs.Serialize(fs, this.Definition); fs.Close(); } else if (Definition is Vex.Image) { Vex.Image vi = (Vex.Image)Definition; string fileName = System.IO.Path.GetFileName(vi.Path); if (fileName != vi.Path) { stage.BitmapCache.RemoveBitmap(vi); File.Copy(vi.Path, folderPath + System.IO.Path.DirectorySeparatorChar + fileName, true); vi.Path = fileName; } dataFileName = folderPath + System.IO.Path.DirectorySeparatorChar + GetDataPath(); File.WriteAllText(dataFileName, string.Empty); fs = new FileStream(dataFileName, FileMode.OpenOrCreate); XmlSerializer xs = new XmlSerializer(this.Definition.GetType()); xs.Serialize(fs, this.Definition); fs.Close(); } else if (Definition is Vex.Symbol) { //save definition File.WriteAllText(dataFileName, string.Empty); fs = new FileStream(dataFileName, FileMode.OpenOrCreate); XmlSerializer xs = GetShapeSerializer(); xs.Serialize(fs, this.Definition); fs.Close(); } HasSaveableChanges = false; return(result); }
protected LibraryItem[] CreateLibraryItems() { string testPath = Directory.GetCurrentDirectory() + @"\Images"; string[] pngPaths = Directory.GetFiles(testPath, "*.png", SearchOption.AllDirectories); LibraryItem[] items = new LibraryItem[pngPaths.Length]; LibraryItem li; for (int i = 0; i < pngPaths.Length; i++) { Vex.Image img = new Vex.Image(pngPaths[i], lib.NextLibraryId()); li = new LibraryItem(MainForm.CurrentStage, img); items[i] = li; } return(items); }
public LibraryItem AddImage(string path) { LibraryItem result; string imgName = Path.GetFileName(path); string wf = MainForm.CurrentStage.WorkingFolderFull; bool inWorkingFolder = path.IndexOf(wf) == 0; string pathAndName = inWorkingFolder ? path.Substring(wf.Length) : imgName; string workingPath = pathAndName.Substring(0, pathAndName.Length - imgName.Length); //bool isUpdatingImage = MainForm.CurrentLibrary.HasPath(img.WorkingPath, img.Name); TreeNode existingNode = symbolTree.GetNode(workingPath, imgName); bool isUpdatingImage = (existingNode != null); Vex.Image img = new Vex.Image(path); img.Name = imgName; if (isUpdatingImage) { result = MainForm.CurrentLibrary.GetLibraryItem(workingPath, imgName); img.Id = result.DefinitionId; MainForm.CurrentStage.vexObject.Definitions[img.Id] = img; result.Definition = img; MainForm.CurrentStage.BitmapCache.RemoveBitmap(img); } else { result = MainForm.CurrentStage.CreateLibraryItem(img, false); result.LibraryPath = workingPath; AddItemToLibrary(result); } result.EnsureImageLoaded(); DateTime time = File.GetLastAccessTimeUtc(path); result.Date = time; return(result); }