protected override void Save(NanoXmlElement doc) { NanoXmlElement recentsEl = doc.AppendChild(new NanoXmlElement("Recents")); foreach (RecentItem recent in recents) { recent.Save(recentsEl.AppendChild(new NanoXmlElement("Item"))); } NanoXmlElement settingsEl = doc.AppendChild(new NanoXmlElement("Settings")); settingsEl.AppendElement("ShowModules", showModules); settingsEl.AppendElement("ShowSkipped", showSkipped); settingsEl.AppendElement("ShowResources", showResources); settingsEl.AppendElement("GroupResources", groupResources); settingsEl.AppendElement("GroupNamespaces", groupNamespaces); settingsEl.AppendElement("GroupModules", groupModules); settingsEl.AppendElement("UseColumns", useColumns); settingsEl.AppendElement("ShowOriginal", showOriginal); settingsEl.AppendElement("ShowUnicode", showUnicode); settingsEl.AppendElement("SimplifySystem", simplifySystemNames); settingsEl.AppendElement("SimplifyNullable", simplifyNullable); settingsEl.AppendElement("SimplyfyRef", simplifyRef); settingsEl.AppendElement("SortingType", sortingType); settingsEl.AppendElement("Editor", editor); settingsEl.AppendElement("DoubleClickAction", doubleClickAction); settingsEl.AppendElement("WatchClipboard", watchClipboard); if (commandsElement != null) { doc.AppendChild(commandsElement); } updateHelper.Save(doc.AppendChild(new NanoXmlElement("Update"))); }
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { NanoXmlElement el = new NanoXmlElement("Actions"); commandManager.SaveToXml(el); Configs.Instance.CommandsElement = el; }
public RenamedClass(NanoXmlElement el, Mapping owner) { if (string.Compare(el.Name, "skippedClass", StringComparison.Ordinal) == 0) { ParseSkipped(el); } else { ParseClass(el, owner); } }
public RenamedItem(NanoXmlElement el, RenamedClass owner) { try { this.owner = owner; entityType = (EntityType)Enum.Parse(typeof (EntityType), el.Name.Substring(7)); string str = el.GetAttribute("oldName"); int i; if ((i = str.IndexOf(' ')) != -1) { string s = str.Substring(0, i); int k = s.IndexOf('/'); if (k != -1) resultType = new Renamed(s.Substring(0, k) + "." + s.Substring(k + 1)); else resultType = new Renamed(s); str = str.Substring(i + 1); } if ((i = str.IndexOf("::")) != -1) str = str.Substring(i + 2); if ((i = str.IndexOf('(')) != -1) { methodParams = new List<Renamed>(); foreach (string s in EntityName.ParseList(str, i + 1, ')')) { int k = s.IndexOf('/'); if (k != -1) methodParams.Add(new Renamed(s.Substring(0, k) + "." + s.Substring(k + 1))); else methodParams.Add(new Renamed(s)); } str = str.Substring(0, i); i = str.IndexOf('['); if (i != -1 && str[i + 2] == ']') str = str.Substring(0, i); } string strNew = el.GetAttribute("newName"); if (strNew != "dropped") name = new Renamed(str, strNew); else name = new Renamed(str); } catch (Exception e) { throw new ObfuscarParserException("Failed to process item element", e, el.Path); } }
private IEnumerable <IMappingEntity> ParseGroup(string name) { NanoXmlElement el = xml.GetElement(name); if (el == null) { yield break; } foreach (NanoXmlElement e in el.ChildElements) { yield return(new XmlMappingEntity(e)); } }
protected override void Load(NanoXmlElement doc) { NanoXmlElement recentsEl = doc.GetElement("Recents"); foreach (NanoXmlElement childElement in recentsEl.ChildElements) { if (File.Exists(childElement.GetAttribute("filename"))) { recents.Add(new RecentItem(childElement)); } } NanoXmlElement settingsEl = doc.GetElement("Settings"); settingsEl.GetValueIfExists("ShowModules", ref showModules); settingsEl.GetValueIfExists("ShowSkipped", ref showSkipped); settingsEl.GetValueIfExists("ShowResources", ref showResources); settingsEl.GetValueIfExists("GroupResources", ref groupResources); settingsEl.GetValueIfExists("GroupNamespaces", ref groupNamespaces); settingsEl.GetValueIfExists("GroupModules", ref groupModules); settingsEl.GetValueIfExists("UseColumns", ref useColumns); settingsEl.GetValueIfExists("ShowOriginal", ref showOriginal); settingsEl.GetValueIfExists("ShowUnicode", ref showUnicode); settingsEl.GetValueIfExists("SimplifySystem", ref simplifySystemNames); settingsEl.GetValueIfExists("SimplifyNullable", ref simplifyNullable); settingsEl.GetValueIfExists("SimplifyRef", ref simplifyRef); settingsEl.GetValueIfExists("SortingType", ref sortingType); settingsEl.GetValueIfExists("Editor", ref editor); settingsEl.GetValueIfExists("DoubleClickAction", ref doubleClickAction); settingsEl.GetValueIfExists("WatchClipboard", ref watchClipboard); if (editor == null) { editor = VisualStudioDetector.GetHighestVisualStudio().Description; } commandsElement = doc.GetElement("Actions"); NanoXmlElement updateEl = doc.GetElement("Update"); if (updateEl == null) { updateEl = doc.GetElement("update"); } if (updateEl != null) { updateHelper.Load(updateEl); } }
public void Save(NanoXmlElement el) { el.AddAttribute("filename", filename); foreach (KeyValuePair <string, string> property in properties) { el.AddAttribute(property.Key, property.Value); } foreach (KeyValuePair <string, List <string> > item in additionalItems) { foreach (string s in item.Value) { el.AppendChild(item.Key, s); } } }
public XmlMappingEntity(NanoXmlElement el) { this.el = el; Name = el.GetAttribute("oldName"); if (Name == null) { Name = el.GetAttribute("name"); } if (Name == null) { throw new ObfuscarParserException("Unable to get name", el.Path); } NewName = el.GetAttribute("newName"); if (NewName == null) { SkipReason = el.GetAttribute("reason"); if (SkipReason == null) { throw new ObfuscarParserException("Neither new name, nor skip reason not found", el.Path); } } string typeValue; if (el.Name.StartsWith(PREFIX_RENAMED)) { typeValue = el.Name.Substring(PREFIX_RENAMED.Length); } else if (el.Name.StartsWith(PREFIX_SKIPPED)) { typeValue = el.Name.Substring(PREFIX_SKIPPED.Length); } else { throw new ObfuscarParserException($"Invalid or unsupported tag: {el.Name}", el.Path); } Type = (EntityType)Enum.Parse(typeof(EntityType), typeValue); }
private void ParseClass(NanoXmlElement el, Mapping owner) { try { string newName = el.GetAttribute("newName"); int j = newName.IndexOf('/'); if (j != -1) { newName = newName.Substring(j + 1); } string str = el.GetAttribute("oldName"); j = str.IndexOf('/'); if (j != -1) { ownerClassName = str.Substring(0, j); name = new Renamed(str.Substring(j + 1), newName); } else { name = new Renamed(str, newName); } } catch (Exception e) { throw new ObfuscarParserException("Failed to process class element: ", e, el.Path); } foreach (NanoXmlElement element in el.ChildElements) { if (!element.Name.StartsWith("renamed")) { continue; } items.Add(new RenamedItem(element, this)); } }
public RecentItem(NanoXmlElement el) { filename = el.GetAttribute("filename"); foreach (NanoXmlAttribute attribute in el.Attributes) { if (attribute.Name != "filename") { properties.Add(attribute.Name, attribute.Value); } } foreach (NanoXmlElement element in el.ChildElements) { List <string> list; if (!additionalItems.TryGetValue(element.Name, out list)) { list = new List <string>(); additionalItems.Add(element.Name, list); } list.Add(element.Value); } }
private void ParseSkipped(NanoXmlElement el) { try { string str = el.GetAttribute("name"); int j = str.IndexOf('/'); if (j != -1) { ownerClassName = str.Substring(0, j); name = new Renamed(str.Substring(j + 1)); } else { name = new Renamed(str); } skipReason = el.GetAttribute("reason"); } catch (Exception e) { throw new ObfuscarParserException("Failed to process element", e, el.Path); } }
private void LoadFile() { Stopwatch sw = new Stopwatch(); sw.Start(); NanoXmlDocument xml = NanoXmlDocument.LoadFromFile(filename); timingXML = sw.ElapsedMilliseconds; Debug.WriteLine("XML Loading: " + timingXML + " ms"); sw.Reset(); sw.Start(); NanoXmlElement doc = xml.DocumentElement; NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"]; modules.Clear(); namespaces.Clear(); namespacesObfuscated.Clear(); classes.Clear(); haveSystemEntities = false; methodsCount = classesCount = subclassesCount = skippedCount = 0; lastModified = File.GetLastWriteTime(filename); List <RenamedClass> subclasses = new List <RenamedClass>(); if (types != null) { foreach (NanoXmlElement element in types.ChildElements) { if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0) { RenamedClass c = new RenamedClass(element, this); classesCount++; if (c.OwnerClassName == null) { classes.Add(c); if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null) { haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System."); } } else { subclasses.Add(c); } methodsCount += c.MethodsCount; if (c.ModuleNew != null && !modules.Contains(c.ModuleNew)) { modules.Add(c.ModuleNew); } if (c.Name.NameOld != null && !string.IsNullOrEmpty(c.Name.NameOld.Namespace) && !namespaces.Contains(c.Name.NameOld.Namespace)) { namespaces.Add(c.Name.NameOld.Namespace); } if (c.Name.NameNew != null && !string.IsNullOrEmpty(c.Name.NameNew.Namespace) && !namespacesObfuscated.Contains(c.Name.NameNew.Namespace)) { namespacesObfuscated.Add(c.Name.NameNew.Namespace); } } } } types = (NanoXmlElement)doc["skippedTypes"]; if (types != null) { foreach (NanoXmlElement element in types.ChildElements) { if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0) { skippedCount++; classesCount++; RenamedClass c = new RenamedClass(element, this); if (c.OwnerClassName == null) { classes.Add(c); } else { subclasses.Add(c); } } } } timingParsing = sw.ElapsedMilliseconds; Debug.WriteLine("Parsing: " + timingParsing + " ms"); sw.Reset(); sw.Start(); foreach (RenamedClass subclass in subclasses) { RenamedClass c = (RenamedClass)SearchForOldName(subclass.OwnerClassName); if (c == null) { c = (RenamedClass)SearchForNewName(subclass.OwnerClassName); } if (c != null) { c.Items.Add(subclass); subclass.OwnerClass = c; subclassesCount++; continue; } Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName); classes.Add(subclass); } timingSubclasses = sw.ElapsedMilliseconds; Debug.WriteLine("Subclasses processing: " + timingSubclasses + " ms"); sw.Reset(); sw.Start(); foreach (RenamedClass c in classes) { c.UpdateNewNames(this); } timingUpdateNewNames = sw.ElapsedMilliseconds; Debug.WriteLine("Values updating: " + timingUpdateNewNames + " ms"); Debug.WriteLine("Total elapsed: " + TimingTotal + " ms"); sw.Stop(); }
public RenamedItem(NanoXmlElement el, RenamedClass owner) { try { this.owner = owner; entityType = (EntityType)Enum.Parse(typeof(EntityType), el.Name.Substring(7)); string str = el.GetAttribute("oldName"); int i; if ((i = str.IndexOf(' ')) != -1) { string s = str.Substring(0, i); int k = s.IndexOf('/'); if (k != -1) { resultType = new RenamedParam(s.Substring(0, k) + "." + s.Substring(k + 1)); } else { resultType = new RenamedParam(s); } str = str.Substring(i + 1); } if ((i = str.IndexOf("::")) != -1) { str = str.Substring(i + 2); } if ((i = str.IndexOf('(')) != -1) { methodParams = new List <RenamedParam>(); foreach (string s in EntityName.ParseList(str, i + 1, ')')) { int k = s.IndexOf('/'); if (k != -1) { methodParams.Add(new RenamedParam(s.Substring(0, k) + "." + s.Substring(k + 1))); } else { methodParams.Add(new RenamedParam(s)); } } str = str.Substring(0, i); i = str.IndexOf('['); if (i != -1 && str[i + 2] == ']') { str = str.Substring(0, i); } } string strNew = el.GetAttribute("newName"); if (strNew != "dropped") { name = new Renamed(str, strNew); } else { name = new Renamed(str); } } catch (Exception e) { throw new ObfuscarParserException("Failed to process item element", e, el.Path); } }
public RecentItem(NanoXmlElement el) { filename = el.GetAttribute("filename"); foreach (NanoXmlAttribute attribute in el.Attributes) if (attribute.Name != "filename") properties.Add(attribute.Name, attribute.Value); foreach (NanoXmlElement element in el.ChildElements) { List<string> list; if (!additionalItems.TryGetValue(element.Name, out list)) { list = new List<string>(); additionalItems.Add(element.Name, list); } list.Add(element.Value); } }
public void Save(NanoXmlElement el) { el.AddAttribute("filename", filename); foreach (KeyValuePair<string, string> property in properties) el.AddAttribute(property.Key, property.Value); foreach (KeyValuePair<string, List<string>> item in additionalItems) foreach (string s in item.Value) el.AppendChild(item.Key, s); }
protected override void Load(NanoXmlElement doc) { NanoXmlElement recentsEl = (NanoXmlElement)doc["Recents"]; foreach (NanoXmlElement childElement in recentsEl.ChildElements) { if (File.Exists(childElement.GetAttribute("filename"))) recents.Add(new RecentItem(childElement)); } NanoXmlElement settingsEl = (NanoXmlElement)doc["Settings"]; settingsEl.GetValueIfExists("ShowModules", ref showModules); settingsEl.GetValueIfExists("GroupNamespaces", ref groupNamespaces); settingsEl.GetValueIfExists("GroupModules", ref groupModules); settingsEl.GetValueIfExists("UseColumns", ref useColumns); settingsEl.GetValueIfExists("ShowOriginal", ref showOriginal); settingsEl.GetValueIfExists("ShowUnicode", ref showUnicode); settingsEl.GetValueIfExists("SimplifySystem", ref simplifySystemNames); settingsEl.GetValueIfExists("SimplifyNullable", ref simplifyNullable); settingsEl.GetValueIfExists("SortingType", ref sortingType); settingsEl.GetValueIfExists("VisualStudioVersion", ref visualStudioVersion); }
protected override void Save(NanoXmlElement doc) { NanoXmlElement recentsEl = doc.AppendChild(new NanoXmlElement("Recents")); foreach (RecentItem recent in recents) recent.Save(recentsEl.AppendChild(new NanoXmlElement("Item"))); NanoXmlElement settingsEl = doc.AppendChild(new NanoXmlElement("Settings")); settingsEl.AppendChild(new NanoXmlElement("ShowModules", showModules.ToString())); settingsEl.AppendChild(new NanoXmlElement("GroupNamespaces", groupNamespaces.ToString())); settingsEl.AppendChild(new NanoXmlElement("GroupModules", groupModules.ToString())); settingsEl.AppendChild(new NanoXmlElement("UseColumns", useColumns.ToString())); settingsEl.AppendChild(new NanoXmlElement("ShowOriginal", showOriginal.ToString())); settingsEl.AppendChild(new NanoXmlElement("ShowUnicode", showUnicode.ToString())); settingsEl.AppendChild(new NanoXmlElement("SimplifySystem", simplifySystemNames.ToString())); settingsEl.AppendChild(new NanoXmlElement("SimplifyNullable", simplifyNullable.ToString())); settingsEl.AppendChild(new NanoXmlElement("SortingType", sortingType.ToString())); settingsEl.AppendChild(new NanoXmlElement("VisualStudioVersion", visualStudioVersion.ToString())); }
private void LoadFile() { loadTime = 0; LoadTimer timer = new LoadTimer("XML Parsing"); NanoXmlDocument xml = NanoXmlDocument.LoadFromFile(filename); loadTime += timer.Stop(); timer = new LoadTimer("Items Processing"); NanoXmlElement doc = xml.DocumentElement; NanoXmlElement types = (NanoXmlElement)doc["renamedTypes"]; modules.Clear(); namespaces.Clear(); namespacesObfuscated.Clear(); classes.Clear(); classesCache.Clear(); haveSystemEntities = false; methodsCount = classesCount = subclassesCount = skippedCount = 0; lastModified = File.GetLastWriteTime(filename); List <RenamedClass> subclasses = new List <RenamedClass>(); if (types != null) { foreach (NanoXmlElement element in types.ChildElements) { if (string.Compare(element.Name, "renamedClass", StringComparison.Ordinal) == 0) { RenamedClass c = new RenamedClass(element, this); classesCount++; if (c.OwnerClassName == null) { classes.Add(c); if (c.Name.NameOld != null && c.Name.NameOld.Namespace != null) { haveSystemEntities |= c.Name.NameOld.Namespace.StartsWith("System."); } } else { subclasses.Add(c); } methodsCount += c.MethodsCount; if (c.ModuleNew != null) { modules.Add(c.ModuleNew); } if (c.Name.NameOld != null) { classesCache[c.NameOld] = c; classesCache[c.NameOldFull] = c; if (!string.IsNullOrEmpty(c.Name.NameOld.Namespace)) { namespaces.Add(c.Name.NameOld.Namespace); } } if (c.Name.NameNew != null) { classesCache[c.NameNew] = c; classesCache[c.NameNewFull] = c; if (!string.IsNullOrEmpty(c.Name.NameNew.Namespace)) { namespacesObfuscated.Add(c.Name.NameNew.Namespace); } } } } } types = (NanoXmlElement)doc["skippedTypes"]; if (types != null) { foreach (NanoXmlElement element in types.ChildElements) { if (string.Compare(element.Name, "skippedClass", StringComparison.Ordinal) == 0) { skippedCount++; classesCount++; RenamedClass c = new RenamedClass(element, this); if (c.OwnerClassName == null) { classes.Add(c); } else { subclasses.Add(c); } classesCache[c.NameOld] = c; classesCache[c.NameOldFull] = c; } } } loadTime += timer.Stop(); timer = new LoadTimer("Subclasses Processing"); foreach (RenamedClass subclass in subclasses) { RenamedClass c; if (classesCache.TryGetValue(subclass.OwnerClassName, out c)) { c.Items.Add(subclass); subclass.OwnerClass = c; subclassesCount++; continue; } Debug.WriteLine("Failed to find root class: " + subclass.OwnerClassName); classes.Add(subclass); } loadTime += timer.Stop(); timer = new LoadTimer("Values Updating"); foreach (RenamedClass c in classes) { c.UpdateNewNames(this); } loadTime += timer.Stop(); Debug.WriteLine("Total Elapsed: {0} ms", loadTime); }
public void Load() { NanoXmlDocument doc = NanoXmlDocument.LoadFromFile(filename); xml = doc.DocumentElement; }