/// <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(); }
/// <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"); } /** * 1) Create tmp dirs for source extraction * 2) Extract sources * 3) Create dest fomod dir * 4) Copy sources to dest fomod dir * 5) Create readme * 6) Create info.xml * 7) Create screenshot * 8) Create script * 9) Pack fomod * * Total steps = 1 + (# sources to extract) + 1 + (# of copies needed) + 1 + 1 + 1 + 1 + 1 * = 7 + (# sources to extract) + (# of copies needed) */ var intBaseStepCount = 7; // 1) Create tmp dirs for source extraction var dicSources = CreateExtractionDirectories(bfaArgs.CopyInstructions); ProgressDialog.OverallProgressMaximum = intBaseStepCount + dicSources.Count + bfaArgs.CopyInstructions.Count; if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 2) Extract sources foreach (var kvpArchive in dicSources) { UnpackArchive(kvpArchive.Key, kvpArchive.Value); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); } // 3) Create dest fomod dir var strTempFomodFolder = CreateFomodDirectory(); var strTempFomodFomodFolder = Path.Combine(strTempFomodFolder, "fomod"); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 4) Copy sources to dest fomod dir foreach (var kvpCopyInstruction in bfaArgs.CopyInstructions) { CopyFiles(strTempFomodFolder, dicSources, kvpCopyInstruction); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); } if (!Directory.Exists(strTempFomodFomodFolder)) { Directory.CreateDirectory(strTempFomodFomodFolder); } // 5) Create readme CreateReadmeFile(strTempFomodFolder, bfaArgs.FomodName, bfaArgs.Readme); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 6) Create info.xml CreateInfoFile(strTempFomodFomodFolder, bfaArgs.InfoFile); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 7) Create screenshot CreateScreenshot(strTempFomodFomodFolder, bfaArgs.SetScreenshot, bfaArgs.Screenshot); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 8) Create script CreateScriptFile(strTempFomodFomodFolder, bfaArgs.Script); if (ProgressDialog.Cancelled()) { return; } ProgressDialog.StepOverallProgress(); // 9) Pack fomod PackFomod(strTempFomodFolder, bfaArgs.PackedPath); ProgressDialog.StepOverallProgress(); }
/// <summary> /// Called when a file is about to be extracted from a source archive. /// </summary> /// <remarks> /// This cancels the compression if the user has clicked the cancel button of the progress dialog. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">A <see cref="FileNameEventArgs" /> describing the event arguments.</param> private void FileExtractionStarted(object sender, FileInfoEventArgs e) { e.Cancel = ProgressDialog.Cancelled(); }
/// <summary> /// Called when a file is about to be added to a new fomod. /// </summary> /// <remarks> /// This cancels the compression if the user has clicked the cancel button of the progress dialog. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">A <see cref="FileNameEventArgs" /> describing the event arguments.</param> protected void FileCompressionStarted(object sender, FileNameEventArgs e) { e.Cancel = ProgressDialog.Cancelled(); }
/// <summary> /// Updates the progress window when a file is copied. /// </summary> /// <remarks> /// This is passed as the callback method for the <see cref="FileUtil.Copy" /> used to /// execute the copy instructions. /// </remarks> /// <param name="p_strFile">The file the was copied.</param> /// <returns><lang langref="true" /> if the user cancelled the operation; <lang langref="false" /> otherwise.</returns> protected bool FileCopied(string p_strFile) { ProgressDialog.StepItemProgress(); return(ProgressDialog.Cancelled()); }