/// <summary> /// Loads the project from the specified file. /// </summary> public void Load(string fileName) { SetToDefault(); FileName = fileName; XmlDocument xmlDoc = new(); xmlDoc.Load(fileName); XmlElement rootElem = xmlDoc.DocumentElement; Version = ProjectVersion.Parse(rootElem.GetChildAsString("ProjectVersion")); Description = rootElem.GetChildAsString("Description"); // load instances if (rootElem.SelectSingleNode("Instances") is XmlNode instancesNode) { XmlNodeList instanceNodes = instancesNode.SelectNodes("Instance"); string projectDir = ProjectDir; foreach (XmlNode instanceNode in instanceNodes) { ProjectInstance instance = new(); instance.LoadFromXml(instanceNode); instance.InstanceDir = Path.Combine(projectDir, "Instances", instance.Name); Instances.Add(instance); // fix instance ID if (instance.ID <= 0) { instance.ID = Instances.Count; } } } }
/// <summary> /// Loads the project from the specified file. /// </summary> public void Load(string fileName) { SetToDefault(); FileName = fileName; XmlDocument xmlDoc = new(); xmlDoc.Load(fileName); XmlElement rootElem = xmlDoc.DocumentElement; Version = ProjectVersion.Parse(rootElem.GetChildAsString("ProjectVersion")); Description = rootElem.GetChildAsString("Description"); // load instances if (rootElem.SelectSingleNode("Instances") is XmlNode instancesNode) { HashSet <int> instanceIDs = new(); string projectDir = ProjectDir; foreach (XmlNode instanceNode in instancesNode.SelectNodes("Instance")) { ProjectInstance instance = new(); instance.LoadFromXml(instanceNode); instance.InstanceDir = Path.Combine(projectDir, "Instances", instance.Name); if (instance.ID > 0 && instanceIDs.Add(instance.ID)) // check uniqueness { Instances.Add(instance); } } } }