Exemple #1
0
        private async Task GetScriptFile()
        {
            byte[] scriptData = null;

            if (!string.IsNullOrEmpty(InstallScriptPath))
            {
                await Task.Run(() =>
                {
                    scriptData       = FileSystem.ReadAllBytes(Path.Combine(TempPath, InstallScriptPath));
                    ModInstallScript = InstallScriptType.LoadScript(TextUtil.ByteToString(scriptData));
                    // when we have an install script, do we really assume that this script uses paths relative
                    // to what our heuristics assumes is the top level directory?
                    int offset = InstallScriptPath.IndexOf(Path.Combine("fomod", "ModuleConfig.xml"),
                                                           StringComparison.InvariantCultureIgnoreCase);
                    if (offset == -1)
                    {
                        PathPrefix = ArchiveStructure.FindPathPrefix(ModFiles, StopPatterns);
                    }
                    else
                    {
                        PathPrefix = InstallScriptPath.Substring(0, offset);
                    }
                });
            }
        }
Exemple #2
0
        /// <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;
        }