public void RemoveLibraryItem(LibraryItem item) { if (items.ContainsKey(item.DefinitionId)) { uint id = item.DefinitionId; items.Remove(id); stage.vexObject.Definitions.Remove(id); removedPaths.Add(id, item.GetDataPath()); if (addedPaths.ContainsKey(id)) { addedPaths.Remove(id); } } }
public void AddLibraryItem(LibraryItem item) { if (!items.ContainsKey(item.DefinitionId)) { uint id = item.DefinitionId; items.Add(id, item); stage.vexObject.Definitions.Add(id, item.Definition); addedPaths.Add(id, item.GetDataPath()); if (removedPaths.ContainsKey(id)) { removedPaths.Remove(id); } } else { items[item.DefinitionId] = item; stage.vexObject.Definitions[item.DefinitionId] = item.Definition; } }
public bool Save(string folderPath) { bool result = false; Directory.CreateDirectory(folderPath); // next ID // root file // unnamed symbol counter (or calc) string libFileName = folderPath + Path.DirectorySeparatorChar + "Library.xml"; File.WriteAllText(libFileName, string.Empty); FileStream fs = new FileStream(libFileName, FileMode.OpenOrCreate); XmlTextWriter w = new XmlTextWriter(fs, System.Text.Encoding.UTF8); w.Formatting = Formatting.Indented; w.WriteStartElement("Library"); w.WriteElementString("LibraryIdCounter", definitionIdCounter.ToString()); w.WriteStartElement("LibraryItems"); foreach (uint key in items.Keys) { LibraryItem li = items[key]; w.WriteStartElement("Item"); w.WriteAttributeString("Id", li.Definition.Id.ToString()); w.WriteAttributeString("Type", li.Definition.GetType().ToString()); w.WriteAttributeString("Date", li.Date.ToString("u")); if (li.OriginalSourceId != 0) { w.WriteAttributeString("OriginalSourceId", li.OriginalSourceId.ToString()); } if (li.Definition.Name != null && li.Definition.Name != "") { w.WriteAttributeString("Name", li.Definition.Name); } if (li.LibraryPath != null && li.LibraryPath != "") { w.WriteAttributeString("LibraryPath", li.LibraryPath); } string dp = li.GetDataPath(); if (dp != null && dp != "") { w.WriteAttributeString("DataPath", dp); } w.WriteEndElement(); } w.WriteEndElement(); w.WriteEndElement(); w.Flush(); fs.Close(); // remove old defs foreach (uint key in removedPaths.Keys) { string[] paths = removedPaths[key].Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); foreach (string subPath in paths) { string path = folderPath + System.IO.Path.DirectorySeparatorChar + subPath; if (File.Exists(path)) { File.Delete(path); } } } addedPaths.Clear(); removedPaths.Clear(); // now write actual library Items foreach (uint key in items.Keys) { LibraryItem li = items[key]; if (li.HasSaveableChanges) { li.Save(folderPath); } } hasSaveableChanges = false; return(result); }