/// <summary> /// This undoes any changes that were made by the previous version of the fomod being upgraded, but /// were not made by the current version. /// </summary> /// <remarks> /// This method is used for the background worker. /// </remarks> private void ReconcileDifferences() { m_bwdProgress.OverallProgressMaximum = 3; m_bwdProgress.ItemMessage = "Synchronizing Files"; var ilmPreviousChanges = InstallLog.Current.GetMergeModule(Fomod.BaseName); m_bwdProgress.ItemProgressMaximum = ilmPreviousChanges.DataFiles.Count; foreach (var strFile in ilmPreviousChanges.DataFiles) { if (!MergeModule.ContainsFile(strFile)) { Script.UninstallDataFile(strFile); } if (m_bwdProgress.Cancelled()) { return; } m_bwdProgress.StepItemProgress(); } m_bwdProgress.StepOverallProgress(); m_bwdProgress.ItemMessage = "Synchronizing Ini Edits"; m_bwdProgress.ItemProgressMaximum = ilmPreviousChanges.IniEdits.Count; foreach (var iniEdit in ilmPreviousChanges.IniEdits) { if (!MergeModule.IniEdits.Contains(iniEdit)) { Script.UneditIni(iniEdit.File, iniEdit.Section, iniEdit.Key); } if (m_bwdProgress.Cancelled()) { return; } m_bwdProgress.StepItemProgress(); } m_bwdProgress.StepOverallProgress(); m_bwdProgress.ItemMessage = "Synchronizing Game Specific Value Edits"; m_bwdProgress.ItemProgressMaximum = ilmPreviousChanges.GameSpecificValueEdits.Count; foreach (var gsvEdit in ilmPreviousChanges.GameSpecificValueEdits) { if (!MergeModule.GameSpecificValueEdits.Contains(gsvEdit)) { Script.UneditGameSpecificValue(gsvEdit.Key); } if (m_bwdProgress.Cancelled()) { return; } m_bwdProgress.StepItemProgress(); } m_bwdProgress.StepOverallProgress(); }
/// <summary> /// This performs the mirgration. /// </summary> /// <param name="p_objArgs">The path to the old FOMM installation.</param> protected void DoMigration(object p_objArgs) { var strOldFOMMLocation = (string)p_objArgs; var tfmFileManager = new TxFileManager(); //copy the mods //do we need to copy? if ( !Path.Combine(strOldFOMMLocation, "mods") .Equals(Program.GameMode.ModDirectory, StringComparison.InvariantCultureIgnoreCase)) { var lstModFiles = new List <string>(); lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.fomod")); lstModFiles.AddRange(Directory.GetFiles(Path.Combine(strOldFOMMLocation, "mods"), "*.xml")); m_bwdProgress.ItemMessage = "Copying mods..."; m_bwdProgress.ItemProgressMaximum = lstModFiles.Count; m_bwdProgress.ItemProgress = 0; foreach (var strMod in lstModFiles) { var strModFileName = Path.GetFileName(strMod); m_bwdProgress.ItemMessage = "Copying mods (" + strModFileName + ")..."; tfmFileManager.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, strModFileName), true); //File.Copy(strMod, Path.Combine(Program.GameMode.ModDirectory, Path.GetFileName(strMod))); m_bwdProgress.StepItemProgress(); if (m_bwdProgress.Cancelled()) { return; } } } m_bwdProgress.StepOverallProgress(); //copy overwrites folder //do we need to? if ( !Path.Combine(strOldFOMMLocation, "overwrites") .Equals(Program.GameMode.OverwriteDirectory, StringComparison.InvariantCultureIgnoreCase)) { var strOverwriteFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "overwrites"), "*.*", SearchOption.AllDirectories); m_bwdProgress.ItemMessage = "Copying overwrites..."; m_bwdProgress.ItemProgressMaximum = strOverwriteFiles.Length; m_bwdProgress.ItemProgress = 0; FileUtil.Copy(tfmFileManager, Path.Combine(strOldFOMMLocation, "overwrites"), Program.GameMode.OverwriteDirectory, OverwriteFileCopied); } m_bwdProgress.StepOverallProgress(); //copy install logs //do we need to? if ( !Path.Combine(strOldFOMMLocation, "fomm") .Equals(Program.GameMode.InstallInfoDirectory, StringComparison.InvariantCultureIgnoreCase)) { var strMiscFiles = Directory.GetFiles(Path.Combine(strOldFOMMLocation, "fomm"), "InstallLog.xml*"); m_bwdProgress.ItemMessage = "Copying info files..."; m_bwdProgress.ItemProgressMaximum = strMiscFiles.Length; m_bwdProgress.ItemProgress = 0; foreach (var strFile in strMiscFiles) { tfmFileManager.Copy(strFile, Path.Combine(Program.GameMode.InstallInfoDirectory, Path.GetFileName(strFile)), true); m_bwdProgress.StepItemProgress(); if (m_bwdProgress.Cancelled()) { return; } } } m_bwdProgress.StepOverallProgress(); }
/// <summary> /// Handles the <see cref="fomod.ReadOnlyInitStepStarted" /> event of the FOMod. /// </summary> /// <remarks> /// This cancels the operation if the user has clicked cancel. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">A <see cref="CancelEventArgs" /> describing the event arguments.</param> private void Fomod_ReadOnlyInitStepStarted(object sender, CancelEventArgs e) { e.Cancel = m_bwdProgress.Cancelled(); }
/// <summary> /// Called when a file is about to be extracted from a 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> private void UnpackFomod_FileExtractionStarted(object sender, FileInfoEventArgs e) { e.Cancel = m_bwdProgress.Cancelled(); }
/// <summary> /// Called when the conflict detector has processed a plugin. /// </summary> /// <remarks> /// This updates the detector progress bar. /// </remarks> /// <param name="sender">The object that trigger the event.</param> /// <param name="e">A <see cref="PluginProcessedEventArgs" /> describing the event arguments.</param> private void cdrDetector_PluginProcessed(object sender, PluginProcessedEventArgs e) { m_bwdProgress.StepOverallProgress(); e.Cancel = m_bwdProgress.Cancelled(); }
/// <summary> /// Performs a basic uninstall of the mod. /// </summary> /// <remarks> /// A basic uninstall removes all of the files that were installed by the mod, /// and undos all of the edits the mod made during install. /// </remarks> protected void PerformBasicUninstall() { var lstFiles = MergeModule.DataFiles; var lstIniEdits = MergeModule.IniEdits; var lstGameSpecificValueEdits = MergeModule.GameSpecificValueEdits; m_bwdProgress.OverallProgressMaximum = lstFiles.Count + lstIniEdits.Count + lstGameSpecificValueEdits.Count; m_bwdProgress.ItemProgressMaximum = lstFiles.Count; m_bwdProgress.ItemMessage = "Uninstalling Files"; foreach (var strFile in lstFiles) { if (m_bwdProgress.Cancelled()) { return; } if (Fomod == null) { Script.UninstallDataFile(m_strBaseName, strFile); } else { Script.UninstallDataFile(strFile); } m_bwdProgress.StepItemProgress(); m_bwdProgress.StepOverallProgress(); } m_bwdProgress.ItemProgressMaximum = lstIniEdits.Count; m_bwdProgress.ItemMessage = "Undoing Ini Edits"; foreach (var iniEdit in lstIniEdits) { if (m_bwdProgress.Cancelled()) { return; } if (Fomod == null) { Script.UneditIni(m_strBaseName, iniEdit.File, iniEdit.Section, iniEdit.Key); } else { Script.UneditIni(iniEdit.File, iniEdit.Section, iniEdit.Key); } m_bwdProgress.StepItemProgress(); m_bwdProgress.StepOverallProgress(); } m_bwdProgress.ItemProgressMaximum = lstGameSpecificValueEdits.Count; m_bwdProgress.ItemMessage = "Undoing Game Specific Value Edits"; foreach (var gsvEdit in lstGameSpecificValueEdits) { if (m_bwdProgress.Cancelled()) { return; } if (Fomod == null) { Script.UneditGameSpecificValue(m_strBaseName, gsvEdit.Key); } else { Script.UneditGameSpecificValue(gsvEdit.Key); } m_bwdProgress.StepItemProgress(); m_bwdProgress.StepOverallProgress(); } }
/// <summary> /// Installs and activates files are required. This method is used by the background worker. /// </summary> /// <param name="p_ifaArgs">The arguments used to configure what is installed.</param> protected void InstallFiles(object p_ifaArgs) { if (!(p_ifaArgs is InstallFilesArguments)) { throw new ArgumentException("The given argument obejct is not of type InstallFilesArguments.", "p_ifaArgs"); } var prsParser = ((InstallFilesArguments)p_ifaArgs).Parser; var ofmOptions = ((InstallFilesArguments)p_ifaArgs).Form; var lstRequiredFiles = prsParser.GetRequiredInstallFiles(); var lstInstallFiles = ofmOptions.FilesToInstall; m_bwdProgress.OverallProgressMaximum = lstRequiredFiles.Count + lstInstallFiles.Count; foreach (var pflRequiredFile in lstRequiredFiles) { if (m_bwdProgress.Cancelled()) { return; } if (!InstallPluginFile(pflRequiredFile, true)) { return; } m_bwdProgress.StepOverallProgress(); } var lstActivateFiles = ofmOptions.PluginsToActivate; foreach (var plfFile in lstInstallFiles) { if (m_bwdProgress.Cancelled()) { return; } if (!InstallPluginFile(plfFile, lstActivateFiles.Contains(plfFile))) { return; } m_bwdProgress.StepOverallProgress(); } var lstConditionInstallPatterns = prsParser.GetConditionalFileInstallPatterns(); foreach (var cipPattern in lstConditionInstallPatterns) { if (cipPattern.Dependency.IsFufilled) { foreach (var plfFile in cipPattern.Files) { if (m_bwdProgress.Cancelled()) { return; } if (!InstallPluginFile(plfFile, true)) { return; } m_bwdProgress.StepOverallProgress(); } } } }
/// <summary> /// Recursively searches the specified directory for the search files. /// </summary> /// <param name="p_strPath">The path of the directory to recursively search.</param> protected string Search(string p_strPath) { m_bwdProgress.OverallMessage = p_strPath; foreach (var strSearchFile in m_strSearchFiles) { if (m_bwdProgress.Cancelled()) { return(null); } try { var strFoundFiles = Directory.GetFiles(p_strPath, strSearchFile, SearchOption.TopDirectoryOnly); foreach (var strFoundFile in strFoundFiles) { if ( MessageBox.Show(m_bwdProgress, "Found: " + Path.GetDirectoryName(strFoundFile) + Environment.NewLine + "Is this correct?", "Found File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { return(Path.GetDirectoryName(strFoundFile)); } } } catch (UnauthorizedAccessException) { //we don't have access to the path we are trying to search, so let's bail return(null); } catch (PathTooLongException) { // Full paths must not exceed 260 characters to maintain compatibility with Windows operating systems. // More Info: https://msdn.microsoft.com/en-us/library/system.io.pathtoolongexception(v=vs.110).aspx continue; // This statement is unnecessary, but makes it clear to the developer what actually happens. } } String[] strDirectories; try { strDirectories = Directory.GetDirectories(p_strPath); } catch (PathTooLongException) { // Full paths must not exceed 260 characters to maintain compatibility with Windows operating systems. // More Info: https://msdn.microsoft.com/en-us/library/system.io.pathtoolongexception(v=vs.110).aspx return(null); } foreach (var strDirectory in strDirectories) { if (m_bwdProgress.Cancelled()) { return(null); } if (Path.GetFileName(p_strPath).StartsWith("$")) { continue; } var strFound = Search(strDirectory); if (!String.IsNullOrEmpty(strFound)) { return(strFound); } } return(null); }