/// <summary> /// Loads the project from a file. /// </summary> /// <param name="p_strPath">The path to the file from which to load the project.</param> protected void Load(string p_strPath) { XmlDocument xmlProject = new XmlDocument(); xmlProject.Load(p_strPath); XmlNode xndRoot = xmlProject.SelectSingleNode("modProject"); XmlNode xndInfo = xndRoot.SelectSingleNode("info"); this.LoadInfo(xndInfo); XmlNode xndScript = xndRoot.SelectSingleNode("InstallScript"); if (xndScript != null) { IScriptType stpType = ScriptTypeRegistry.GetType(xndScript.Attributes["type"].Value); if (stpType == null) throw new Exception("Unrecognized script type: " + xndScript.Attributes["type"].Value); InstallScript = stpType.LoadScript(xndScript.InnerXml); } XmlNode xndReadme = xndRoot.SelectSingleNode("ModReadme"); if (xndReadme != null) { string strFormat = xndReadme.Attributes["format"].Value; ReadmeFormat fmtFormat = ReadmeFormat.PlainText; if (Enum.GetNames(typeof(ReadmeFormat)).Contains(x => x.Equals(strFormat, StringComparison.InvariantCultureIgnoreCase))) fmtFormat = (ReadmeFormat)Enum.Parse(typeof(ReadmeFormat), strFormat); ModReadme = new Readme(fmtFormat, xndReadme.InnerText); } XmlNode xndFiles = xndRoot.SelectSingleNode("ModFiles"); if (xndFiles != null) { foreach (XmlNode xndFile in xndFiles.ChildNodes) { bool booIsDirectory = false; if (!bool.TryParse(xndFile.Attributes["IsDirectory"].Value, out booIsDirectory)) booIsDirectory = false; ModFiles.Add(new VirtualFileSystemItem(xndFile.Attributes["Source"].Value, xndFile.Attributes["Path"].Value, booIsDirectory)); } } FilePath = p_strPath; IsDirty = false; }
/// <summary> /// A simple constructor that initializes the object with the required dependencies. /// </summary> /// <param name="p_strScriptTypeRegistry">The <see cref="IScriptTypeRegistry"/> contianing the list of available script types.</param> public Project(IScriptTypeRegistry p_strScriptTypeRegistry) { m_setFiles = new ThreadSafeObservableList<VirtualFileSystemItem>(); ModReadme = new Readme(ReadmeFormat.PlainText, null); ScriptTypeRegistry = p_strScriptTypeRegistry; }