Пример #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);
                    }
                });
            }
        }
Пример #2
0
        /// <summary>
        ///   If no readme has been entered, this method looks for a readme file in the selected
        ///   files, and, if one is found, uses it to populate the readme editor.
        /// </summary>
        protected void SetReadmeDefault()
        {
            if (redReadmeEditor.Readme == null)
            {
                List <KeyValuePair <string, string> > lstReadmes = null;
                foreach (var strExtension in Readme.ValidExtensions)
                {
                    lstReadmes = ffsFileStructure.FindFomodFiles("readme - " + tbxFomodFileName.Text + strExtension);
                    if (lstReadmes.Count > 0)
                    {
                        break;
                    }
                }
                if (lstReadmes.Count == 0)
                {
                    foreach (var strExtension in Readme.ValidExtensions)
                    {
                        lstReadmes = ffsFileStructure.FindFomodFiles("*readme*" + strExtension);
                        if (lstReadmes.Count > 0)
                        {
                            break;
                        }
                    }
                }
                if (lstReadmes.Count == 0)
                {
                    foreach (var strExtension in Readme.ValidExtensions)
                    {
                        lstReadmes = ffsFileStructure.FindFomodFiles("*" + strExtension);
                        if (lstReadmes.Count > 0)
                        {
                            break;
                        }
                    }
                }

                Readme rmeReadme = null;
                foreach (var kvpReadme in lstReadmes)
                {
                    if (Readme.IsValidReadme(kvpReadme.Key))
                    {
                        string strReadme = null;
                        if (kvpReadme.Value.StartsWith(Archive.ARCHIVE_PREFIX))
                        {
                            var kvpArchiveInfo = Archive.ParseArchivePath(kvpReadme.Value);
                            var arcArchive     = new Archive(kvpArchiveInfo.Key);
                            strReadme = TextUtil.ByteToString(arcArchive.GetFileContents(kvpArchiveInfo.Value));
                        }
                        else if (File.Exists(kvpReadme.Value))
                        {
                            strReadme = File.ReadAllText(kvpReadme.Value);
                        }
                        rmeReadme = new Readme(kvpReadme.Key, strReadme);
                        break;
                    }
                }
                redReadmeEditor.Readme = rmeReadme ?? new Readme(ReadmeFormat.PlainText, null);
            }
        }
Пример #3
0
 public Readme GetReadme()
 {
     if (String.IsNullOrEmpty(m_strReadmePath) || !Readme.IsValidReadme(m_strReadmePath))
     {
         return(null);
     }
     return(new Readme(m_strReadmePath, TextUtil.ByteToString(GetFileContents(m_strReadmePath))));
 }
Пример #4
0
 internal FomodScript GetInstallScript()
 {
     if (!HasInstallScript)
     {
         return(null);
     }
     return(new FomodScript(m_strScriptPath, TextUtil.ByteToString(GetFileContents(m_strScriptPath))));
 }
Пример #5
0
        public void ByteToStringTest()
        {
            var result = TextUtil.ByteToString(new byte[0]);

            Assert.AreEqual("", result);

            const string thisIsATestString = "this is a test";

            result = TextUtil.ByteToString(_thisIsATest);
            Assert.AreEqual(thisIsATestString, result);
        }
Пример #6
0
        /// <summary>
        ///   Updates the BOSS Fallout 3 Masterlist used by FOMM.
        /// </summary>
        public void UpdateMasterlist(string p_strPath)
        {
            string strMasterlist;

            using (var wclGetter = new WebClient())
            {
                //the substring is to remove the 3byte EFBBBF Byte Order Mark (BOM)
                strMasterlist = TextUtil.ByteToString(wclGetter.DownloadData(MasterListURL));
            }
            File.WriteAllText(p_strPath, GetMasterlistVersion() + Environment.NewLine + strMasterlist);
        }
Пример #7
0
        /// <summary>
        /// Downloads the specified file, and returns the file contents as a string.
        /// </summary>
        /// <param name="p_uriUrl">The URL of the file to download.</param>
        /// <returns>The file contents as a string.</returns>
        protected string DownloadFileContentsAsString(Uri p_uriUrl)
        {
            string strFileName = DownloadFile(p_uriUrl);

            byte[] bteFile = null;
            if (!String.IsNullOrEmpty(strFileName))
            {
                bteFile = File.ReadAllBytes(strFileName);
                FileUtil.ForceDelete(strFileName);
            }
            return(TextUtil.ByteToString(bteFile));
        }
 /// <summary>
 /// Writes all remaining data to the underlying listener.
 /// </summary>
 public override void Flush()
 {
     base.Flush();
     if (!TraceIsForced && m_booSaveToFile)
     {
         Int64  intPosition = TraceStream.Position;
         byte[] bteData     = new byte[intPosition - m_intLastStreamPosition];
         Array.Copy(TraceStream.GetBuffer(), m_intLastStreamPosition, bteData, 0, bteData.Length);
         File.AppendAllText(FilePath, TextUtil.ByteToString(bteData));
         m_intLastStreamPosition = intPosition;
     }
 }
Пример #9
0
        /// <summary>
        ///   If no info has been entered, this method looks for an info file in the selected
        ///   files, and, if one is found, uses it to populate the info editor. If one is not found,
        ///   the editor is populated with default values.
        /// </summary>
        protected void SetInfoDefault()
        {
            if (!m_booLoadedInfo)
            {
                m_booLoadedInfo = true;
                var strInfoFileName = "fomod" + Path.DirectorySeparatorChar + "info.xml";
                IList <KeyValuePair <string, string> > lstFiles = ffsFileStructure.FindFomodFiles(strInfoFileName);
                if (lstFiles.Count > 0)
                {
                    var xmlInfo   = new XmlDocument();
                    var kvpScript = lstFiles[0];
                    if (kvpScript.Value.StartsWith(Archive.ARCHIVE_PREFIX))
                    {
                        var kvpArchiveInfo = Archive.ParseArchivePath(kvpScript.Value);
                        var arcArchive     = new Archive(kvpArchiveInfo.Key);
                        var strInfo        = TextUtil.ByteToString(arcArchive.GetFileContents(kvpArchiveInfo.Value));
                        xmlInfo.LoadXml(strInfo);
                    }
                    else if (File.Exists(kvpScript.Value))
                    {
                        xmlInfo.Load(kvpScript.Value);
                    }

                    fomod.LoadInfo(xmlInfo, finInfo, false);
                }
                else if (String.IsNullOrEmpty(finInfo.ModName))
                {
                    finInfo.ModName = tbxFomodFileName.Text;
                }

                var strScreenshotFileName = "fomod" + Path.DirectorySeparatorChar + "screenshot.*";
                IList <KeyValuePair <string, string> > lstScreenshotFiles = ffsFileStructure.FindFomodFiles(strScreenshotFileName);
                if (lstScreenshotFiles.Count > 0)
                {
                    var kvpScreenshot = lstScreenshotFiles[0];
                    if (kvpScreenshot.Value.StartsWith(Archive.ARCHIVE_PREFIX))
                    {
                        var kvpArchiveInfo = Archive.ParseArchivePath(kvpScreenshot.Value);
                        var arcArchive     = new Archive(kvpArchiveInfo.Key);
                        var bteScreenshot  = arcArchive.GetFileContents(kvpArchiveInfo.Value);
                        finInfo.Screenshot = new Screenshot(kvpArchiveInfo.Value, bteScreenshot);
                    }
                    else if (File.Exists(kvpScreenshot.Value))
                    {
                        finInfo.Screenshot = new Screenshot(kvpScreenshot.Value, File.ReadAllBytes(kvpScreenshot.Value));
                    }
                }
            }
        }
Пример #10
0
 protected void LoadInfo()
 {
     if (ContainsFile("fomod/info.xml"))
     {
         HasInfo = true;
         var doc = new XmlDocument();
         doc.LoadXml(TextUtil.ByteToString(GetFileContents("fomod/info.xml")));
         LoadInfo(doc, this);
         if (Program.MVersion < MinFommVersion)
         {
             throw new fomodLoadException("This fomod requires a newer version of Fallout mod manager to load." +
                                          Environment.NewLine + "Expected " + MachineVersion);
         }
     }
 }
Пример #11
0
        /// <summary>
        ///   If no script has been entered, this method looks for a script file in the selected
        ///   files, and, if one is found, uses it to populate the script editor. If one is not found,
        ///   the script is populated with the default value.
        /// </summary>
        protected void SetScriptDefault()
        {
            if (fseScriptEditor.Script == null)
            {
                FomodScript fscInstallScript = null;
                string      strScriptPath    = null;
                foreach (var strScriptName in FomodScript.ScriptNames)
                {
                    strScriptPath = Path.Combine("fomod", strScriptName);
                    IList <KeyValuePair <string, string> > lstFiles = ffsFileStructure.FindFomodFiles(strScriptPath);
                    if (lstFiles.Count > 0)
                    {
                        fscInstallScript = new FomodScript(strScriptName, null);
                        strScriptPath    = lstFiles[0].Value;
                        break;
                    }
                }

                if (fscInstallScript == null)
                {
                    if (cbxUseScript.Checked)
                    {
                        fscInstallScript = new FomodScript(FomodScriptType.CSharp, Program.GameMode.DefaultCSharpScript);
                    }
                }
                else
                {
                    cbxUseScript.Checked = true;
                    if (strScriptPath.StartsWith(Archive.ARCHIVE_PREFIX))
                    {
                        var kvpArchiveInfo = Archive.ParseArchivePath(strScriptPath);
                        var arcArchive     = new Archive(kvpArchiveInfo.Key);
                        fscInstallScript.Text = TextUtil.ByteToString(arcArchive.GetFileContents(kvpArchiveInfo.Value));
                    }
                    else if (File.Exists(strScriptPath))
                    {
                        fscInstallScript.Text = File.ReadAllText(strScriptPath);
                    }
                }

                fseScriptEditor.Script = fscInstallScript;
            }
        }