/// <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); } }
/// <summary> /// Verifies if the readme file exists in the archive and saves it to the ReadMe folder. /// </summary> /// <param name="p_strArchivePath">The path to the mod archive.</param> public bool VerifyReadMeFile(TxFileManager p_tfmFileManager, string p_strArchivePath) { try { Archive arcFile = new Archive(p_strArchivePath); List <string> lstFiles = GetFileList(arcFile, true); string strReadMePath = m_strReadMePath; string strFileName = String.Empty; string strReadMeFile = String.Empty; string strModFile = Path.GetFileName(p_strArchivePath); string strArchiveFile = Path.GetFileNameWithoutExtension(strModFile) + ".7z"; byte[] bteData = null; PurgeTempFolder(); for (int i = 0; i < lstFiles.Count; i++) { strFileName = lstFiles[i].ToString(); if (Readme.IsValidReadme(strFileName)) { bteData = arcFile.GetFileContents(lstFiles[i]); if (bteData.Length > 0) { strReadMeFile = Path.GetFileName(strFileName); strReadMePath = Path.Combine(ReadMeTempPath, strReadMeFile); p_tfmFileManager.WriteAllBytes(strReadMePath, bteData); break; } } } string[] strFilesToCompress = Directory.GetFiles(ReadMeTempPath, "*.*", SearchOption.AllDirectories); if (strFilesToCompress.Length > 0) { if (CreateReadMeArchive(strArchiveFile, strFilesToCompress)) { for (int i = 0; i < strFilesToCompress.Length; i++) { strFilesToCompress[i] = Path.GetFileName(strFilesToCompress[i]); } m_dicReadMeFiles.Add(Path.GetFileNameWithoutExtension(strArchiveFile), strFilesToCompress); } } } catch { return(false); } return(true); }
/// <summary> /// This builds the fomod based on the given data. /// </summary> /// <remarks> /// This method is called by a <see cref="BackgroundWorkerProgressDialog" />. /// </remarks> /// <param name="p_objArgs">A <see cref="BuildFomodArgs" /> describing the fomod to build.</param> protected override void DoGenerateFomod(object p_objArgs) { var bfaArgs = p_objArgs as BuildFomodArgs; if (bfaArgs == null) { throw new ArgumentException("The given argument must be a BuildFomodArgs.", "p_objArgs"); } var strSource = bfaArgs.SourcePath; /** * 1) Unpack source, if required * 2) Delete unwanted files * 3) Remove extraneous top-level folders * 4) Create readme * 5) Create info file * 6) Pack fomod * * Total steps = 1 + 1 + 1 + 1 + 1 + 1 * = 6 */ ProgressDialog.OverallProgressMaximum = 6; // 1) Unpack source, if required if (File.Exists(bfaArgs.SourcePath)) { strSource = CreateTemporaryDirectory(); UnpackArchive(bfaArgs.SourcePath, strSource); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); } // 2) Delete unwanted files DeleteUnwantedFiles(strSource); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 3) Remove extraneous top-level folders strSource = DescendToFomodFolder(strSource); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); //warn if script is required but missing if (Program.GetFiles(strSource, "*.esp", SearchOption.AllDirectories).Length + Program.GetFiles(strSource, "*.esm", SearchOption.AllDirectories).Length > Program.GetFiles(strSource, "*.esp", SearchOption.TopDirectoryOnly).Length + Program.GetFiles(strSource, "*.esm", SearchOption.TopDirectoryOnly).Length) { var booHasScript = false; foreach (var strScriptName in FomodScript.ScriptNames) { if (File.Exists(Path.Combine(strSource, "fomod\\" + strScriptName))) { booHasScript = true; break; } } if (!booHasScript && (MessageBox.Show( "This archive contains plugins in subdirectories, and will need a script attached for fomm to install it correctly.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)) { return; } } // 4) Create readme var strReadmes = Directory.GetFiles(strSource, "readme - " + bfaArgs.FomodName + ".*", SearchOption.TopDirectoryOnly); if (strReadmes.Length == 0) { strReadmes = Directory.GetFiles(strSource, "*readme*.*", SearchOption.AllDirectories); foreach (var strExtension in Readme.ValidExtensions) { if (strReadmes.Length > 0) { break; } strReadmes = Program.GetFiles(strSource, "*" + strExtension, SearchOption.AllDirectories); } Readme rmeReadme = null; foreach (var strReadme in strReadmes) { if (Readme.IsValidReadme(strReadme)) { rmeReadme = new Readme(strReadme, File.ReadAllText(strReadme)); break; } } CreateReadmeFile(strSource, bfaArgs.FomodName, rmeReadme); } if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 5) Create info.xml if (!String.IsNullOrEmpty(bfaArgs.Url)) { var strFomodFomodPath = Path.Combine(strSource, "fomod"); if (!Directory.Exists(strFomodFomodPath)) { Directory.CreateDirectory(strFomodFomodPath); } if (!File.Exists(Path.Combine(strFomodFomodPath, "info.xml"))) { var xmlInfo = new XmlDocument(); xmlInfo.AppendChild(xmlInfo.CreateXmlDeclaration("1.0", "UTF-16", null)); var xndRoot = xmlInfo.AppendChild(xmlInfo.CreateElement("fomod")); var xndWebsite = xndRoot.AppendChild(xmlInfo.CreateElement("Website")); xndWebsite.InnerText = bfaArgs.Url; CreateInfoFile(strFomodFomodPath, xmlInfo); } } if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 6) Pack fomod PackFomod(strSource, bfaArgs.PackedPath); ProgressDialog.StepOverallProgress(); }