/// <summary> /// Upgrades the install log. /// </summary> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> protected override void UpgradeInstallLog(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mrgModRegistry) { if (!File.Exists(p_strLogPath)) return; string strModInstallDirectory = p_strModInstallDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; XDocument docLog = XDocument.Load(p_strLogPath); string strLogVersion = docLog.Element("installLog").Attribute("fileVersion").Value; if (!SUPPORTED_VERSION.ToString().Equals(strLogVersion)) throw new UpgradeException(String.Format("Cannot upgrade Install Log version: {0} Expecting {1}", strLogVersion, SUPPORTED_VERSION)); XElement xelModList = docLog.Descendants("modList").FirstOrDefault(); if (xelModList != null) { foreach (XElement xelMod in xelModList.Elements("mod")) { xelMod.Add(new XElement("installDate", new XText("<No Data>"))); } } docLog.Element("installLog").Attribute("fileVersion").Value = InstallLog.CurrentVersion.ToString(); if (!Directory.Exists(Path.GetDirectoryName(p_strLogPath))) Directory.CreateDirectory(Path.GetDirectoryName(p_strLogPath)); docLog.Save(p_strLogPath); }
/// <summary> /// Upgrades the install log. /// </summary> /// <returns>The task that performs the upgrading.</returns> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed modss.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> public IBackgroundTask UpgradeInstallLog(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mrgModRegistry) { Version verLogVersion = InstallLog.ReadVersion(p_strLogPath); if (!m_dicUpgraders.ContainsKey(verLogVersion)) throw new UpgradeException("Unrecognized log version: " + verLogVersion.ToString()); m_dicUpgraders[verLogVersion].Upgrade(p_strLogPath, p_strModInstallDirectory, p_mrgModRegistry); return m_dicUpgraders[verLogVersion]; }
/// <summary> /// Upgrades the install log. /// </summary> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> protected override void UpgradeInstallLog(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mrgModRegistry) { if (!File.Exists(p_strLogPath)) return; string strModInstallDirectory = p_strModInstallDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; XDocument docLog = XDocument.Load(p_strLogPath); string strLogVersion = docLog.Element("installLog").Attribute("fileVersion").Value; if (!SUPPORTED_VERSION.ToString().Equals(strLogVersion)) throw new UpgradeException(String.Format("Cannot upgrade Install Log version: {0} Expecting {1}", strLogVersion, SUPPORTED_VERSION)); XElement xelModList = docLog.Descendants("modList").FirstOrDefault(); if (xelModList != null) { foreach (XElement xelMod in xelModList.Elements("mod")) { string strModName = xelMod.Attribute("name").Value; IMod modMod = p_mrgModRegistry.RegisteredMods.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x.Filename).Equals(strModName, StringComparison.CurrentCultureIgnoreCase)); string strPath = null; if (modMod == null) { if ("FOMM".Equals(strModName)) modMod = InstallLog.ModManagerValueMod; else if ("ORIGINAL_VALUES".Equals(strModName)) modMod = InstallLog.OriginalValueMod; else throw new UpgradeException(String.Format("Missing Mod ({0}), cannot upgrade install log.", strModName)); strPath = modMod.Filename; } else strPath = modMod.Filename.Substring(strModInstallDirectory.Length); xelMod.Attribute("name").Remove(); XElement xelVersion = xelMod.Element("version"); if (xelVersion != null) xelVersion.Remove(); xelMod.Add(new XAttribute("path", strPath)); xelMod.Add(new XElement("version", new XAttribute("machineVersion", modMod.MachineVersion ?? new Version()), new XText(modMod.HumanReadableVersion ?? "0"))); xelMod.Add(new XElement("name", new XText(modMod.ModName))); } } XElement xelFiles = docLog.Descendants("dataFiles").FirstOrDefault(); if (xelFiles != null) foreach (XElement xelFile in xelFiles.Elements("file")) xelFile.Attribute("path").Value = Path.Combine("Data", xelFile.Attribute("path").Value); docLog.Element("installLog").Attribute("fileVersion").Value = InstallLog.CurrentVersion.ToString(); if (!Directory.Exists(Path.GetDirectoryName(p_strLogPath))) Directory.CreateDirectory(Path.GetDirectoryName(p_strLogPath)); docLog.Save(p_strLogPath); }
/// <summary> /// Called to perform the upgrade. /// </summary> /// <remarks> /// Sets up the resources required to upgrade the install log. /// </remarks> /// <param name="p_mdrManagedModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> public void Upgrade(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mdrManagedModRegistry) { Trace.WriteLine("Beginning Install Log Upgrade."); m_tfmFileManager = new TxFileManager(); using (TransactionScope tsTransaction = new TransactionScope()) { m_tfmFileManager.Snapshot(p_strLogPath); Start(p_strLogPath, p_strModInstallDirectory, p_mdrManagedModRegistry); tsTransaction.Complete(); m_tfmFileManager = null; } }
/// <summary> /// Upgrades the install log. /// </summary> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> protected override void UpgradeInstallLog(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mrgModRegistry) { if (!File.Exists(p_strLogPath)) return; string strModInstallDirectory = p_strModInstallDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; XDocument docLog = XDocument.Load(p_strLogPath); string strLogVersion = docLog.Element("installLog").Attribute("fileVersion").Value; if (!SUPPORTED_VERSION.ToString().Equals(strLogVersion)) throw new UpgradeException(String.Format("Cannot upgrade Install Log version: {0} Expecting {1}", strLogVersion, SUPPORTED_VERSION)); XElement xelModList = docLog.Descendants("modList").FirstOrDefault(); if (xelModList != null) { foreach (XElement xelMod in xelModList.Elements("mod")) { string strModPath = xelMod.Attribute("path").Value; if (InstallLog.OriginalValueMod.Filename.Equals(strModPath)) xelMod.Add(new XElement("name", new XText(InstallLog.OriginalValueMod.ModName))); else if (InstallLog.ModManagerValueMod.Filename.Equals(strModPath)) xelMod.Add(new XElement("name", new XText(InstallLog.ModManagerValueMod.ModName))); else { strModPath = Path.GetFileName(xelMod.Attribute("path").Value); IMod modMod = p_mrgModRegistry.RegisteredMods.FirstOrDefault(x => Path.GetFileName(x.Filename).Equals(strModPath, StringComparison.OrdinalIgnoreCase)); if (modMod != null) { strModPath = modMod.Filename.Substring(strModInstallDirectory.Length); xelMod.Attribute("path").Value = strModPath; xelMod.Add(new XElement("name", new XText(modMod.ModName))); } else xelMod.Add(new XElement("name", new XText("MISSING MOD"))); } } } docLog.Element("installLog").Attribute("fileVersion").Value = InstallLog.CurrentVersion.ToString(); if (!Directory.Exists(Path.GetDirectoryName(p_strLogPath))) Directory.CreateDirectory(Path.GetDirectoryName(p_strLogPath)); docLog.Save(p_strLogPath); }
/// <summary> /// Upgrades the install log. /// </summary> /// <param name="p_mrgModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed mods.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> protected abstract void UpgradeInstallLog(string p_strLogPath, string p_strModInstallDirectory, ModRegistry p_mrgModRegistry);
/// <summary> /// Initializes the install log. /// </summary> /// <param name="p_mdrManagedModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed <see cref="IMod"/>s.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> /// <returns>The initialized install log.</returns> /// <exception cref="InvalidOperationException">Thrown if the install log has already /// been initialized.</exception> public static IInstallLog Initialize(ModRegistry p_mdrManagedModRegistry, string p_strModInstallDirectory, string p_strLogPath) { if (m_ilgCurrent != null) throw new InvalidOperationException("The Install Log has already been initialized."); m_ilgCurrent = new InstallLog(p_mdrManagedModRegistry, p_strModInstallDirectory, p_strLogPath); return m_ilgCurrent; }
/// <summary> /// A simple constructor that initializes the object with its dependencies. /// </summary> /// <param name="p_mdrManagedModRegistry">The <see cref="ModRegistry"/> that contains the list /// of managed <see cref="IMod"/>s.</param> /// <param name="p_strModInstallDirectory">The path of the directory where all of the mods are installed.</param> /// <param name="p_strLogPath">The path from which to load the install log information.</param> private InstallLog(ModRegistry p_mdrManagedModRegistry, string p_strModInstallDirectory, string p_strLogPath) { m_dicInstalledFiles = new InstalledItemDictionary<string, object>(StringComparer.OrdinalIgnoreCase); m_dicInstalledIniEdits = new InstalledItemDictionary<IniEdit, string>(); m_dicInstalledGameSpecificValueEdits = new InstalledItemDictionary<string, byte[]>(); ModInstallDirectory = p_strModInstallDirectory.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).Trim(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar; ManagedModRegistry = p_mdrManagedModRegistry; LogPath = p_strLogPath; LoadInstallLog(); if (!m_amrModKeys.IsModRegistered(OriginalValueMod)) AddActiveMod(OriginalValueMod, true); }