public async Task SetInstallStatusAsync(bool isCompleted, string errorMsg) { try { var userAgent = _userAgentProvider.GetUserAgent(); // Check for current install ID var installCookie = _cookieManager.GetCookieValue(Constants.Web.InstallerCookieName); if (!Guid.TryParse(installCookie, out var installId)) { installId = Guid.NewGuid(); _cookieManager.SetCookieValue(Constants.Web.InstallerCookieName, installId.ToString()); } var dbProvider = string.Empty; if (IsBrandNewInstall == false) { // we don't have DatabaseProvider anymore... doing it differently //dbProvider = ApplicationContext.Current.DatabaseContext.DatabaseProvider.ToString(); dbProvider = _umbracoDatabaseFactory.SqlContext.SqlSyntax.DbProvider; } var installLog = new InstallLog(installId: installId, isUpgrade: IsBrandNewInstall == false, installCompleted: isCompleted, timestamp: DateTime.Now, versionMajor: _umbracoVersion.Version.Major, versionMinor: _umbracoVersion.Version.Minor, versionPatch: _umbracoVersion.Version.Build, versionComment: _umbracoVersion.Comment, error: errorMsg, userAgent: userAgent, dbProvider: dbProvider); await _installationService.LogInstall(installLog); } catch (Exception ex) { _logger.LogError(ex, "An error occurred in InstallStatus trying to check upgrades"); } }
/// <summary> /// Undoes the edit made to the specified game specific value. /// </summary> /// <param name="p_strKey">The key of the edited Game Specific Value.</param> public void UnEditGameSpecificValue(string p_strKey) { ShaderEdit sedShader = new ShaderEdit(p_strKey); SDPArchives sdpManager = new SDPArchives(GameModeInfo, FileUtility); if (!TouchedFiles.Contains(sdpManager.GetPath(sedShader.Package))) { TouchedFiles.Add(sdpManager.GetPath(sedShader.Package)); TransactionalFileManager.Snapshot(sdpManager.GetPath(sedShader.Package)); } string strKey = InstallLog.GetModKey(Mod); string strCurrentOwnerKey = InstallLog.GetCurrentGameSpecificValueEditOwnerKey(p_strKey); //if we didn't edit the shader, then leave it alone if (!strKey.Equals(strCurrentOwnerKey)) { return; } //if we did edit the shader, replace it with the shader we overwrote // if we didn't overwrite the shader, then just delete it byte[] btePreviousData = InstallLog.GetPreviousGameSpecificValue(p_strKey); if (btePreviousData != null) { /*TODO (likely never): I'm not sure if this is the strictly correct way to unedit a shader * the original unedit code was: * * if (m_xelModInstallLogSdpEdits != null) * { * foreach (XmlNode node in m_xelModInstallLogSdpEdits.ChildNodes) * { * //TODO (likely never): Remove this workaround for the release version * if (node.Attributes.GetNamedItem("crc") == null) * { * InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value, 0); * } * else * { * InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value, * uint.Parse(node.Attributes.GetNamedItem("crc").Value)); * } * } * } * * where InstallLog.UndoShaderEdit was: * * public void UndoShaderEdit(int package, string shader, uint crc) * { * XmlNode node = sdpEditsNode.SelectSingleNode("sdp[@package='" + package + "' and @shader='" + shader + "']"); * if (node == null) return; * byte[] b = new byte[node.InnerText.Length / 2]; * for (int i = 0; i < b.Length; i++) * { * b[i] = byte.Parse("" + node.InnerText[i * 2] + node.InnerText[i * 2 + 1], System.Globalization.NumberStyles.AllowHexSpecifier); * } * if (SDPArchives.RestoreShader(package, shader, b, crc)) sdpEditsNode.RemoveChild(node); * } * * after looking at SDPArchives it is not clear to me why a crc was being used. * if ever it becomes evident that a crc is required, I will have to alter the log to store * a crc and pass it to the RestoreShader method. */ if (!sdpManager.RestoreShader(sedShader.Package, sedShader.ShaderName, btePreviousData, 0)) { throw new Exception("Failed to unedit the shader"); } } //TODO (likely never): how do we delete a shader? Right now, if there was no previous shader the current shader // remains }
/// <summary> /// Writes the file represented by the given byte array to the given path. /// </summary> /// <remarks> /// This method writes the given data as a file at the given path. If the file /// already exists the user is prompted to overwrite the file. /// </remarks> /// <param name="p_strPath">The path where the file is to be created.</param> /// <param name="p_bteData">The data that is to make up the file.</param> /// <returns><c>true</c> if the file was written; <c>false</c> if the user chose /// not to overwrite an existing file.</returns> /// <exception cref="IllegalFilePathException">Thrown if <paramref name="p_strPath"/> is /// not safe.</exception> public virtual bool GenerateDataFile(string p_strPath, byte[] p_bteData) { DataFileUtility.AssertFilePathIsSafe(p_strPath); string[] components = p_strPath.Split(Path.DirectorySeparatorChar); p_strPath = string.Join("" + Path.DirectorySeparatorChar, components.Skip(1).Take(components.Length - 1).ToArray()); string strInstallFilePath = installPath(p_strPath); //string strInstallFilePath = null; //strInstallFilePath = Path.Combine(GameModeInfo.InstallationPath, p_strPath); string installDirPath = Path.GetDirectoryName(strInstallFilePath); FileInfo Info = new FileInfo(strInstallFilePath); if (!Directory.Exists(installDirPath)) { CreateDirectory(installDirPath); } else { if (!TestDoOverwrite(p_strPath)) { return(false); } if (File.Exists(strInstallFilePath)) { if (Info.IsReadOnly == true) { File.SetAttributes(strInstallFilePath, File.GetAttributes(strInstallFilePath) & ~FileAttributes.ReadOnly); } string strInstallDirectory = Path.GetDirectoryName(p_strPath); string strBackupDirectory = Path.Combine(GameModeInfo.OverwriteDirectory, strInstallDirectory); string strOldModKey = InstallLog.GetCurrentFileOwnerKey(p_strPath); if (strOldModKey == null) { InstallLog.LogOriginalDataFile(p_strPath); strOldModKey = InstallLog.OriginalValuesKey; } string strInstallingModKey = InstallLog.GetModKey(Mod); //if this mod has installed this file already we just replace it and don't // need to back it up. if (!strOldModKey.Equals(strInstallingModKey)) { //back up the current version of the file if the current mod // didn't install it if (!Directory.Exists(strBackupDirectory)) { CreateDirectory(strBackupDirectory); } //we get the file name this way in order to preserve the file name's case string strFile = Path.GetFileName(Directory.GetFiles(installDirPath, Path.GetFileName(strInstallFilePath))[0]); strFile = strOldModKey + "_" + strFile; string strBackupFilePath = Path.Combine(strBackupDirectory, strFile); Info = new FileInfo(strBackupFilePath); if ((Info.IsReadOnly == true) && (File.Exists(strBackupFilePath))) { File.SetAttributes(strBackupFilePath, File.GetAttributes(strBackupFilePath) & ~FileAttributes.ReadOnly); } TransactionalFileManager.Copy(strInstallFilePath, strBackupFilePath, true); } TransactionalFileManager.Delete(strInstallFilePath); } } TransactionalFileManager.WriteAllBytes(strInstallFilePath, p_bteData); // Checks whether the file is a gamebryo plugin if (IsPlugin) { if (PluginManager.IsActivatiblePluginFile(strInstallFilePath)) { PluginManager.AddPlugin(strInstallFilePath); } } InstallLog.AddDataFile(Mod, p_strPath); return(IsPlugin); }
/// <summary> /// Verifies if the given file can be written. /// </summary> /// <remarks> /// This method checks if the given path is valid. If so, and the file does not /// exist, the file can be written. If the file does exist, than the user is /// asked to overwrite the file. /// </remarks> /// <param name="p_strPath">The file path, relative to the Data folder, whose writability is to be verified.</param> /// <returns><c>true</c> if the location specified by <paramref name="p_strPath"/> /// can be written; <c>false</c> otherwise.</returns> protected bool TestDoOverwrite(string p_strPath) { string strDataPath = Path.Combine(GameModeInfo.InstallationPath, p_strPath); if (!File.Exists(strDataPath)) { return(true); } string strLoweredPath = strDataPath.ToLowerInvariant(); if (m_lstOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath))) { return(true); } if (m_lstDontOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath))) { return(false); } if (m_booOverwriteAll) { return(true); } if (m_booDontOverwriteAll) { return(false); } IMod modOld = InstallLog.GetCurrentFileOwner(p_strPath); if (modOld == Mod) { return(true); } string strMessage = null; if (modOld != null) { strMessage = String.Format("Data file '{{0}}' has already been installed by '{0}'" + Environment.NewLine + "Overwrite with this mod's file?", modOld.ModName); } else { strMessage = "Data file '{0}' already exists." + Environment.NewLine + "Overwrite with this mod's file?"; } switch (m_dlgOverwriteConfirmationDelegate(String.Format(strMessage, p_strPath), true, (modOld != null))) { case OverwriteResult.Yes: return(true); case OverwriteResult.No: return(false); case OverwriteResult.NoToAll: m_booDontOverwriteAll = true; return(false); case OverwriteResult.YesToAll: m_booOverwriteAll = true; return(true); case OverwriteResult.NoToGroup: Queue <string> folders = new Queue <string>(); folders.Enqueue(Path.GetDirectoryName(strLoweredPath)); while (folders.Count > 0) { strLoweredPath = folders.Dequeue(); if (!m_lstOverwriteFolders.Contains(strLoweredPath)) { m_lstDontOverwriteFolders.Add(strLoweredPath); foreach (string s in Directory.GetDirectories(strLoweredPath)) { folders.Enqueue(s.ToLowerInvariant()); } } } return(false); case OverwriteResult.YesToGroup: folders = new Queue <string>(); folders.Enqueue(Path.GetDirectoryName(strLoweredPath)); while (folders.Count > 0) { strLoweredPath = folders.Dequeue(); if (!m_lstDontOverwriteFolders.Contains(strLoweredPath)) { m_lstOverwriteFolders.Add(strLoweredPath); foreach (string s in Directory.GetDirectories(strLoweredPath)) { folders.Enqueue(s.ToLowerInvariant()); } } } return(true); default: throw new Exception("Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum"); } }
/// <summary> /// Uninstalls the specified file. /// </summary> /// <remarks> /// If the mod we are uninstalling doesn't own the file, then its version is removed /// from the overwrites directory. If the mod we are uninstalling overwrote a file when it /// installed the specified file, then the overwritten file is restored. Otherwise /// the file is deleted. /// </remarks> /// <param name="p_strPath">The path to the file that is to be uninstalled.</param> /// <param name="p_booSecondaryInstallPath">Whether to use the secondary install path.</param> public void UninstallDataFile(string p_strPath, bool p_booSecondaryInstallPath) { string strInstallFilePath = String.Empty; DataFileUtility.AssertFilePathIsSafe(p_strPath); string strUninstallingModKey = InstallLog.GetModKey(Mod); if (p_booSecondaryInstallPath && !(String.IsNullOrEmpty(GameModeInfo.SecondaryInstallationPath))) { strInstallFilePath = Path.Combine(GameModeInfo.SecondaryInstallationPath, p_strPath); } else { strInstallFilePath = Path.Combine(GameModeInfo.InstallationPath ?? "", p_strPath); } string strBackupDirectory = Path.Combine(GameModeInfo.OverwriteDirectory, Path.GetDirectoryName(p_strPath)); string strFile; string strRestoreFromPath = string.Empty; bool booRestoreFile = false; FileInfo fiInfo = null; if (File.Exists(strInstallFilePath)) { string strCurrentOwnerKey = InstallLog.GetCurrentFileOwnerKey(p_strPath); //if we didn't install the file, then leave it alone if (strUninstallingModKey.Equals(strCurrentOwnerKey)) { //if we did install the file, replace it with the file we overwrote // when we installed the file // if we didn't overwrite a file, then just delete the current file fiInfo = new FileInfo(strInstallFilePath); if (fiInfo.IsReadOnly) { m_lstErrorMods.Add(strInstallFilePath); } else { TransactionalFileManager.Delete(strInstallFilePath); } string strPreviousOwnerKey = InstallLog.GetPreviousFileOwnerKey(p_strPath); if (strPreviousOwnerKey != null) { strFile = strPreviousOwnerKey + "_" + Path.GetFileName(p_strPath); strRestoreFromPath = Path.Combine(strBackupDirectory, strFile); if (File.Exists(strRestoreFromPath)) { booRestoreFile = true; } } if (IsPlugin) { if ((PluginManager.IsActivatiblePluginFile(strInstallFilePath)) && !booRestoreFile) { PluginManager.RemovePlugin(strInstallFilePath); } } if (booRestoreFile) { //we get the file name this way in order to preserve the file name's case string strBackupFileName = Path.GetFileName(Directory.GetFiles(Path.GetDirectoryName(strRestoreFromPath), Path.GetFileName(strRestoreFromPath))[0]); strBackupFileName = strBackupFileName.Substring(strBackupFileName.IndexOf('_') + 1); string strNewDataPath = Path.Combine(Path.GetDirectoryName(strInstallFilePath), strBackupFileName); fiInfo = new FileInfo(strRestoreFromPath); try { TransactionalFileManager.Copy(strRestoreFromPath, strNewDataPath, true); } catch { } if (fiInfo.IsReadOnly) { m_lstErrorMods.Add(strInstallFilePath); } else { TransactionalFileManager.Delete(strRestoreFromPath); } } //remove any empty directories from the data folder we may have created TrimEmptyDirectories(Path.GetDirectoryName(strInstallFilePath), GameModeInfo.InstallationPath); } } //remove our version of the file from the backup directory string strOverwritePath = Path.Combine(strBackupDirectory, strUninstallingModKey + "_" + Path.GetFileName(p_strPath)); if (File.Exists(strOverwritePath)) { fiInfo = new FileInfo(strOverwritePath); if (((fiInfo.Attributes | FileAttributes.Hidden) == fiInfo.Attributes) || (fiInfo.IsReadOnly)) { m_lstErrorMods.Add(strInstallFilePath); } else { TransactionalFileManager.Delete(strOverwritePath); } } //remove any empty directories from the overwrite folder we may have created string strStopDirectory = GameModeInfo.OverwriteDirectory; string strFileName = Path.GetFileName(strOverwritePath); TrimEmptyDirectories(strOverwritePath.Replace(strFileName, ""), strStopDirectory); InstallLog.RemoveDataFile(Mod, p_strPath); }
/// <summary> /// Writes the file represented by the given byte array to the given path. /// </summary> /// <remarks> /// This method writes the given data as a file at the given path. If the file /// already exists the user is prompted to overwrite the file. /// </remarks> /// <param name="p_strPath">The path where the file is to be created.</param> /// <param name="p_bteData">The data that is to make up the file.</param> /// <param name="p_booSecondaryInstallPath">Whether to use the secondary install path.</param> /// <returns><c>true</c> if the file was written; <c>false</c> if the user chose /// not to overwrite an existing file.</returns> /// <exception cref="IllegalFilePathException">Thrown if <paramref name="p_strPath"/> is /// not safe.</exception> public virtual bool GenerateDataFile(string p_strPath, byte[] p_bteData, bool p_booSecondaryInstallPath) { DataFileUtility.AssertFilePathIsSafe(p_strPath); string strInstallFilePath = String.Empty; if (p_booSecondaryInstallPath && !(String.IsNullOrEmpty(GameModeInfo.SecondaryInstallationPath))) { strInstallFilePath = Path.Combine(GameModeInfo.SecondaryInstallationPath, p_strPath); } else { strInstallFilePath = Path.Combine(GameModeInfo.InstallationPath, p_strPath); } FileInfo Info = new FileInfo(strInstallFilePath); if (!Directory.Exists(Path.GetDirectoryName(strInstallFilePath))) { TransactionalFileManager.CreateDirectory(Path.GetDirectoryName(strInstallFilePath)); } else { if (!TestDoOverwrite(p_strPath)) { return(false); } if (File.Exists(strInstallFilePath)) { if (Info.IsReadOnly == true) { File.SetAttributes(strInstallFilePath, File.GetAttributes(strInstallFilePath) & ~FileAttributes.ReadOnly); } string strInstallDirectory = Path.GetDirectoryName(p_strPath); string strBackupDirectory = Path.Combine(GameModeInfo.OverwriteDirectory, strInstallDirectory); string strOldModKey = InstallLog.GetCurrentFileOwnerKey(p_strPath); if (strOldModKey == null) { InstallLog.LogOriginalDataFile(p_strPath); strOldModKey = InstallLog.OriginalValuesKey; } string strInstallingModKey = InstallLog.GetModKey(Mod); //if this mod has installed this file already we just replace it and don't // need to back it up. if (!strOldModKey.Equals(strInstallingModKey)) { //back up the current version of the file if the current mod // didn't install it if (!Directory.Exists(strBackupDirectory)) { TransactionalFileManager.CreateDirectory(strBackupDirectory); } //we get the file name this way in order to preserve the file name's case string strFile = Path.GetFileName(Directory.GetFiles(Path.GetDirectoryName(strInstallFilePath), Path.GetFileName(strInstallFilePath))[0]); strFile = strOldModKey + "_" + strFile; string strBackupFilePath = Path.Combine(strBackupDirectory, strFile); Info = new FileInfo(strBackupFilePath); if ((Info.IsReadOnly == true) && (File.Exists(strBackupFilePath))) { File.SetAttributes(strBackupFilePath, File.GetAttributes(strBackupFilePath) & ~FileAttributes.ReadOnly); } TransactionalFileManager.Copy(strInstallFilePath, strBackupFilePath, true); } TransactionalFileManager.Delete(strInstallFilePath); } } TransactionalFileManager.WriteAllBytes(strInstallFilePath, p_bteData); // Checks whether the file is a gamebryo plugin if (IsPlugin) { if (PluginManager.IsActivatiblePluginFile(strInstallFilePath)) { if (!PluginManager.CanActivatePlugins()) { string strTooManyPlugins = String.Format("The requested change to the active plugins list would result in over {0} plugins being active.", PluginManager.MaxAllowedActivePluginsCount); strTooManyPlugins += Environment.NewLine + String.Format("The current game doesn't support more than {0} active plugins, you need to disable at least one plugin to continue.", PluginManager.MaxAllowedActivePluginsCount); strTooManyPlugins += Environment.NewLine + Environment.NewLine + String.Format("NOTE: This is a game engine limitation.") + Environment.NewLine; throw new Exception(strTooManyPlugins); } PluginManager.AddPlugin(strInstallFilePath); } } InstallLog.AddDataFile(Mod, p_strPath); return(IsPlugin); }
public async Task LogInstall(InstallLog installLog) { await _installationRepository.SaveInstallLogAsync(installLog); }
/// <summary> /// A simple constructor that initializes the object with its dependencies. /// </summary> /// <param name="p_gmiGameModeInfo">The environment info of the current game mode.</param> /// <param name="p_modMod">The mod being installed.</param> /// <param name="p_ilgInstallLog">The install log to use to log file installations.</param> /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param> /// <param name="p_futFileUtility">The file utility class.</param> /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param> public GamebryoGameSpecificValueUpgradeInstaller(IMod p_modMod, IGameModeEnvironmentInfo p_gmiGameModeInfo, IInstallLog p_ilgInstallLog, TxFileManager p_tfmFileManager, FileUtil p_futFileUtility, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate) : base(p_modMod, p_gmiGameModeInfo, p_ilgInstallLog, p_tfmFileManager, p_futFileUtility, p_dlgOverwriteConfirmationDelegate) { OriginallyInstalledEdits = new Set <string>(); OriginallyInstalledEdits.AddRange(InstallLog.GetInstalledGameSpecificValueEdits(Mod)); }
private static void Main(string[] args) { if (!Settings.Default.settingsUpgraded) { Settings.Default.Upgrade(); Settings.Default.settingsUpgraded = true; Settings.Default.Save(); } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += Application_ThreadException; if (Array.IndexOf(args, "-mono") != -1) { MonoMode = true; } Directory.SetCurrentDirectory(ExecutableDirectory); //Style setup Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0 && (args[0] == "-?" || args[0] == "/?" || args[0] == "-help")) { WriteHelp(); return; } var sgmSelectedGame = Settings.Default.rememberedGameMode; var booChooseGame = true; if ((args.Length > 0) && args[0].StartsWith("-")) { switch (args[0]) { case "-game": try { sgmSelectedGame = (SupportedGameModes)Enum.Parse(typeof(SupportedGameModes), args[1], true); booChooseGame = false; } catch {} break; } } var booChangeGameMode = false; do { if (booChangeGameMode || (booChooseGame && !Settings.Default.rememberGameMode)) { var gmsSelector = new GameModeSelector(); gmsSelector.ShowDialog(); sgmSelectedGame = gmsSelector.SelectedGameMode; } switch (sgmSelectedGame) { case SupportedGameModes.Fallout3: GameMode = new Fallout3GameMode(); break; case SupportedGameModes.FalloutNV: GameMode = new FalloutNewVegasGameMode(); break; default: MessageBox.Show("Unrecognized game selection.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Mutex mutex; bool booNewMutex; string autoLoad = null; if (!booChangeGameMode && (args.Length > 0)) { var booArgsHandled = true; if (!args[0].StartsWith("-") && File.Exists(args[0])) { switch (Path.GetExtension(args[0]).ToLowerInvariant()) { case ".rar": case ".7z": case ".zip": case ".fomod": mutex = new Mutex(true, "fommMainMutex", out booNewMutex); mutex.Close(); if (!booNewMutex) { Messaging.TransmitMessage(args[0]); return; } autoLoad = args[0]; break; default: booArgsHandled = false; break; } } else { switch (args[0]) { case "-u": var strGuid = args[1]; var strPath = Environment.GetFolderPath(Environment.SpecialFolder.System); var psiInfo = new ProcessStartInfo(strPath + @"\msiexec.exe", "/x " + strGuid); Process.Start(psiInfo); return; default: booArgsHandled = false; break; } } if (!booArgsHandled && GameMode.HandleStandaloneArguments(args)) { return; } } mutex = new Mutex(true, "fommMainMutex", out booNewMutex); if (!booNewMutex) { MessageBox.Show(ProgrammeAcronym + " is already running", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); mutex.Close(); return; } try { string strErrorMessage; if (!GameMode.SetWorkingDirectory(out strErrorMessage)) { MessageBox.Show(null, strErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); booChangeGameMode = false; if (Settings.Default.rememberGameMode) { booChangeGameMode = true; Settings.Default.rememberGameMode = false; Settings.Default.Save(); } continue; } GameMode.PreInit(); //Check that we're in fallout's directory and that we have write access var cancellaunch = true; if (!Settings.Default.NoUACCheck || Array.IndexOf(args, "-no-uac-check") == -1) { try { File.Delete("limited"); var strVirtualStore = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "VirtualStore\\"); strVirtualStore = Path.Combine(strVirtualStore, Directory.GetCurrentDirectory().Remove(0, 3)); strVirtualStore = Path.Combine(strVirtualStore, "limited"); if (File.Exists(strVirtualStore)) { File.Delete(strVirtualStore); } var fs = File.Create("limited"); fs.Close(); if (File.Exists(strVirtualStore)) { MessageBox.Show( "UAC is preventing Fallout mod manager from obtaining write access to fallout's installation directory.\n" + "Either right click fomm.exe and check the 'run as administrator' checkbox on the comptibility tab, or disable UAC", "Error"); File.Delete("limited"); } else { File.Delete("limited"); cancellaunch = false; } } catch { MessageBox.Show( "Unable to get write permissions for:" + Environment.NewLine + GameMode.PluginsPath + Environment.NewLine + "Please read" + Environment.NewLine + Path.Combine(ProgrammeInfoDirectory, "Readme - fomm.txt") + Environment.NewLine + "for the solution.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { cancellaunch = false; } if (cancellaunch) { return; } if (!Directory.Exists(tmpPath)) { Directory.CreateDirectory(tmpPath); } var str7zPath = ""; if (Environment.Is64BitProcess) { str7zPath = Path.Combine(ProgrammeInfoDirectory, "7z-64bit.dll"); } else { str7zPath = Path.Combine(ProgrammeInfoDirectory, "7z-32bit.dll"); } SevenZipBase.SetLibraryPath(str7zPath); if (!GameMode.Init()) { return; } PermissionsManager.Init(); //check to see if we need to upgrade the install log format if (InstallLog.Current.GetInstallLogVersion() != InstallLog.CURRENT_VERSION) { var iluUgrader = new InstallLogUpgrader(); try { MessageBox.Show( "FOMM needs to upgrade some of its files. This could take a few minutes, depending on how many mods are installed.", "Upgrade Required"); if (!iluUgrader.UpgradeInstallLog()) { return; } } catch (Exception e) { HandleException(e, "An error occurred while upgrading your log file.", "Upgrade Error"); return; } } InstallLog.Reload(); //let's uninstall any fomods that have been deleted since we last ran var lstMods = InstallLog.Current.GetVersionedModList(); foreach (var fifMod in lstMods) { var strFomodPath = Path.Combine(GameMode.ModDirectory, fifMod.BaseName + ".fomod"); if (!File.Exists(strFomodPath)) { var strMessage = "'" + fifMod.BaseName + ".fomod' was deleted without being deactivated. " + Environment.NewLine + "If you don't uninstall the FOMod, FOMM will close and you will " + "have to put the FOMod back in the mods folder." + Environment.NewLine + "Would you like to uninstall the missing FOMod?"; if (MessageBox.Show(strMessage, "Missing FOMod", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } var mduUninstaller = new ModUninstaller(fifMod.BaseName); mduUninstaller.Uninstall(true); } } try { //check to see if any fomod versions have changed, and whether to upgrade them var upsScanner = new UpgradeScanner(); upsScanner.Scan(); } catch (Exception e) { HandleException(e, "An error occurred while scanning your fomods for new versions.", "Scan Error"); return; } if (booChangeGameMode || !GameMode.HandleInAppArguments(args)) { try { var frmMain = new MainForm(autoLoad); frmMain.Text += " (" + MVersion + ") - " + GameMode.GameName; Application.Run(frmMain); booChangeGameMode = frmMain.ChangeGameMode; } catch (Exception e) { HandleException(e, "Something bad seems to have happened.", "Error"); } } //backup the install log if (File.Exists(InstallLog.Current.InstallLogPath)) { var strLogPath = InstallLog.Current.InstallLogPath + ".bak"; var fifInstallLog = new FileInfo(InstallLog.Current.InstallLogPath); FileInfo fifInstallLogBak = null; if (File.Exists(strLogPath)) { fifInstallLogBak = new FileInfo(strLogPath); } if ((fifInstallLogBak == null) || (fifInstallLogBak.LastWriteTimeUtc != fifInstallLog.LastWriteTimeUtc)) { for (var i = 4; i > 0; i--) { if (File.Exists(strLogPath + i)) { File.Copy(strLogPath + i, strLogPath + (i + 1), true); } } if (File.Exists(strLogPath)) { File.Copy(strLogPath, strLogPath + "1", true); } File.Copy(InstallLog.Current.InstallLogPath, InstallLog.Current.InstallLogPath + ".bak", true); } } FileUtil.ForceDelete(tmpPath); } finally { if (mutex != null) { mutex.Close(); } } }while (booChangeGameMode); }
/// <summary> /// Verifies if the given file can be written. /// </summary> /// <remarks> /// This method checks if the given path is valid. If so, and the file does not /// exist, the file can be written. If the file does exist, than the user is /// asked to overwrite the file. /// </remarks> /// <param name="p_strPath">The file path, relative to the Data folder, whose writability is to be verified.</param> /// <returns><c>true</c> if the location specified by <paramref name="p_strPath"/> /// can be written; <c>false</c> otherwise.</returns> protected bool TestDoOverwrite(string p_strPath) { string strDataPath = Path.Combine(GameModeInfo.InstallationPath, p_strPath); bool booFIDataPath = false; if (!File.Exists(strDataPath)) { return(true); } else { booFIDataPath = new FileInfo(strDataPath).IsReadOnly; if (booFIDataPath) { m_booOverwriteAll = false; } } if (m_mmModManager.IsBackupActive) { ModBackupInfo mbInfo = m_mmModManager.lstMBInfo.Where(x => x.Mod == Mod).FirstOrDefault(); if (mbInfo == null) { return(false); } else { KeyValuePair <string, bool> Dictionary = mbInfo.ModFileDictionary.Where(x => x.Key == p_strPath).FirstOrDefault(); if (Dictionary.Key == null) { return(false); } else { return(Dictionary.Value); } } } string strLoweredPath = strDataPath.ToLowerInvariant(); if (m_lstOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath))) { return(true); } if (m_lstDontOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath))) { return(false); } if (m_booOverwriteAll) { return(true); } if (m_booDontOverwriteAll) { return(false); } IMod modOld = InstallLog.GetCurrentFileOwner(p_strPath); if (modOld == Mod) { return(true); } string strModFile = String.Empty; string strModFileID = String.Empty; string strMessage = null; if (modOld != null) { strModFile = modOld.Filename; strModFileID = modOld.Id; if (!String.IsNullOrEmpty(strModFileID)) { if (m_lstOverwriteMods.Contains(strModFileID)) { return(true); } if (m_lstDontOverwriteMods.Contains(strModFileID)) { return(false); } } else { if (m_lstOverwriteMods.Contains(strModFile)) { return(true); } if (m_lstDontOverwriteMods.Contains(strModFile)) { return(false); } } strMessage = String.Format("Data file '{{0}}' has already been installed by '{0}'", modOld.ModName); if (booFIDataPath) { strMessage += " and is ReadOnly."; } strMessage += Environment.NewLine + "Overwrite with this mod's file?"; } else { strMessage = "Data file '{0}' already exists"; if (booFIDataPath) { strMessage += " and is ReadOnly."; } else { strMessage += "."; } strMessage += Environment.NewLine + "Overwrite with this mod's file?"; } if (booFIDataPath) { switch (m_dlgOverwriteConfirmationDelegate(String.Format(strMessage, p_strPath), true, (modOld != null))) { case OverwriteResult.Yes: return(true); case OverwriteResult.YesToAll: m_booOverwriteAll = true; return(true); case OverwriteResult.NoToAll: m_booDontOverwriteAll = true; return(false); case OverwriteResult.No: return(false); default: throw new Exception("Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum"); } } else { switch (m_dlgOverwriteConfirmationDelegate(String.Format(strMessage, p_strPath), true, (modOld != null))) { case OverwriteResult.Yes: return(true); case OverwriteResult.No: return(false); case OverwriteResult.NoToAll: m_booDontOverwriteAll = true; return(false); case OverwriteResult.YesToAll: m_booOverwriteAll = true; return(true); case OverwriteResult.NoToGroup: Queue <string> folders = new Queue <string>(); folders.Enqueue(Path.GetDirectoryName(strLoweredPath)); while (folders.Count > 0) { strLoweredPath = folders.Dequeue(); if (!m_lstOverwriteFolders.Contains(strLoweredPath)) { m_lstDontOverwriteFolders.Add(strLoweredPath); foreach (string s in Directory.GetDirectories(strLoweredPath)) { folders.Enqueue(s.ToLowerInvariant()); } } } return(false); case OverwriteResult.YesToGroup: folders = new Queue <string>(); folders.Enqueue(Path.GetDirectoryName(strLoweredPath)); while (folders.Count > 0) { strLoweredPath = folders.Dequeue(); if (!m_lstDontOverwriteFolders.Contains(strLoweredPath)) { m_lstOverwriteFolders.Add(strLoweredPath); foreach (string s in Directory.GetDirectories(strLoweredPath)) { folders.Enqueue(s.ToLowerInvariant()); } } } return(true); case OverwriteResult.NoToMod: strModFile = modOld.Filename; strModFileID = modOld.Id; if (!String.IsNullOrEmpty(strModFileID)) { if (!m_lstOverwriteMods.Contains(strModFileID)) { m_lstDontOverwriteMods.Add(strModFileID); } } else { if (!m_lstOverwriteMods.Contains(strModFile)) { m_lstDontOverwriteMods.Add(strModFile); } } return(false); case OverwriteResult.YesToMod: strModFile = modOld.Filename; strModFileID = modOld.Id; if (!String.IsNullOrEmpty(strModFileID)) { if (!m_lstDontOverwriteMods.Contains(strModFileID)) { m_lstOverwriteMods.Add(strModFileID); } } else { if (!m_lstDontOverwriteMods.Contains(strModFile)) { m_lstOverwriteMods.Add(strModFile); } } return(true); default: throw new Exception("Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum"); } } }
/// <summary> /// A simple constructor that initializes the object with its dependencies. /// </summary> /// <param name="p_modMod">The mod being installed.</param> /// <param name="p_ilgInstallLog">The install log to use to log file installations.</param> /// <param name="p_tfmFileManager">The transactional file manager to use to interact with the file system.</param> /// <param name="p_dlgOverwriteConfirmationDelegate">The method to call in order to confirm an overwrite.</param> public IniUpgradeInstaller(IMod p_modMod, IInstallLog p_ilgInstallLog, IVirtualModActivator p_ivaVirtualModActivator, TxFileManager p_tfmFileManager, ConfirmItemOverwriteDelegate p_dlgOverwriteConfirmationDelegate) : base(p_modMod, p_ilgInstallLog, p_ivaVirtualModActivator, p_tfmFileManager, p_dlgOverwriteConfirmationDelegate) { OriginallyInstalledEdits = new Set <IniEdit>(); OriginallyInstalledEdits.AddRange(InstallLog.GetInstalledIniEdits(Mod)); }
/// <summary> /// Determines if the specified install log can be upgraded. /// </summary> /// <param name="p_strLogPath">The path of the install log whose upgradable status is to be determined.</param> /// <returns><c>true</c> if the specified install log can to be upgraded; /// <c>false</c> otherwise.</returns> public bool CanUpgrade(string p_strLogPath) { Version verLogVersion = InstallLog.ReadVersion(p_strLogPath); return(m_dicUpgraders.ContainsKey(verLogVersion)); }
/// <summary> /// Installs the specified file from the Mod to the file system. /// </summary> /// <param name="p_strModFilePath">The path of the file in the Mod to install.</param> /// <param name="p_strInstallPath">The path on the file system where the file is to be installed.</param> /// <returns><c>true</c> if the file was written; <c>false</c> if the user chose /// not to overwrite an existing file.</returns> public bool InstallFileFromMod(string p_strModFilePath, string p_strInstallPath, bool p_booSecondaryInstallPath) { Console.WriteLine("install " + p_strModFilePath + " to " + p_strInstallPath); string destinationPath = installPath(p_strInstallPath, p_booSecondaryInstallPath); if (!Directory.Exists(Path.GetDirectoryName(destinationPath))) { TransactionalFileManager.CreateDirectory(Path.GetDirectoryName(destinationPath)); } else { if (!TestDoOverwrite(p_strInstallPath)) { return(false); } if (File.Exists(destinationPath)) { FileInfo Info = new FileInfo(destinationPath); if (Info.IsReadOnly == true) { File.SetAttributes(destinationPath, File.GetAttributes(destinationPath) & ~FileAttributes.ReadOnly); } string strInstallDirectory = Path.GetDirectoryName(p_strInstallPath); string strBackupDirectory = Path.Combine(GameModeInfo.OverwriteDirectory, strInstallDirectory); string strOldModKey = InstallLog.GetCurrentFileOwnerKey(p_strInstallPath); if (strOldModKey == null) { InstallLog.LogOriginalDataFile(p_strInstallPath); strOldModKey = InstallLog.OriginalValuesKey; } string strInstallingModKey = InstallLog.GetModKey(Mod); //if this mod has installed this file already we just replace it and don't // need to back it up. if (!strOldModKey.Equals(strInstallingModKey)) { //back up the current version of the file if the current mod // didn't install it if (!Directory.Exists(strBackupDirectory)) { TransactionalFileManager.CreateDirectory(strBackupDirectory); } //we get the file name this way in order to preserve the file name's case string strFile = Path.GetFileName(Directory.GetFiles(Path.GetDirectoryName(destinationPath), Path.GetFileName(destinationPath))[0]); strFile = strOldModKey + "_" + strFile; string strBackupFilePath = Path.Combine(strBackupDirectory, strFile); Info = new FileInfo(strBackupFilePath); if ((Info.IsReadOnly == true) && (File.Exists(strBackupFilePath))) { File.SetAttributes(strBackupFilePath, File.GetAttributes(strBackupFilePath) & ~FileAttributes.ReadOnly); } TransactionalFileManager.Copy(destinationPath, strBackupFilePath, true); } TransactionalFileManager.Delete(destinationPath); } } try { using (FileStream stream = File.Create(destinationPath)) { Mod.ExtractFileTo(p_strModFilePath, stream); } } catch (FileNotFoundException e) { MessageBox.Show("File " + p_strModFilePath + " couldn't be extracted.\n" + "This probably means the mod is broken though you may still get partial functionality.\n" + "Please inform the mod author.\n" + "Detailed Error: " + e.Message, "File not found in FOMod", MessageBoxButtons.OK, MessageBoxIcon.Error); File.Delete(destinationPath); throw; } catch (Exception ex) { MessageBox.Show("Exception: " + ex.ToString()); throw; } // Checks whether the file is a gamebryo plugin if (IsPlugin) { if (PluginManager.IsActivatiblePluginFile(destinationPath)) { PluginManager.AddPlugin(destinationPath); } } InstallLog.AddDataFile(Mod, p_strInstallPath); return(IsPlugin); }
void IInstallAction.Run(SetupVariables vars) { var siteName = vars.ComponentFullName; var ip = vars.WebSiteIP; var port = vars.WebSitePort; var domain = vars.WebSiteDomain; var contentPath = vars.InstallationFolder; var iisVersion = vars.IISVersion; var iis7 = (iisVersion.Major == 7); var userName = CreateWebApplicationPoolAction.GetWebIdentity(vars); var userPassword = vars.UserPassword; var appPool = vars.WebApplicationPoolName; var componentId = vars.ComponentId; var newSiteId = String.Empty; // Begin(LogStartMessage); // Log.WriteStart(LogStartMessage); // Log.WriteInfo(String.Format("Creating web site \"{0}\" ( IP: {1}, Port: {2}, Domain: {3} )", siteName, ip, port, domain)); //check for existing site var oldSiteId = iis7 ? WebUtils.GetIIS7SiteIdByBinding(ip, port, domain) : WebUtils.GetSiteIdByBinding(ip, port, domain); // if (oldSiteId != null) { // get site name string oldSiteName = iis7 ? oldSiteId : WebUtils.GetSite(oldSiteId).Name; throw new Exception( String.Format("'{0}' web site already has server binding ( IP: {1}, Port: {2}, Domain: {3} )", oldSiteName, ip, port, domain)); } // create site var site = new WebSiteItem { Name = siteName, SiteIPAddress = ip, ContentPath = contentPath, AllowExecuteAccess = false, AllowScriptAccess = true, AllowSourceAccess = false, AllowReadAccess = true, AllowWriteAccess = false, AnonymousUsername = userName, AnonymousUserPassword = userPassword, AllowDirectoryBrowsingAccess = false, AuthAnonymous = true, AuthWindows = true, DefaultDocs = null, HttpRedirect = "", InstalledDotNetFramework = AspNetVersion.AspNet20, ApplicationPool = appPool, // Bindings = new ServerBinding[] { new ServerBinding(ip, port, domain) }, }; // create site if (iis7) { newSiteId = WebUtils.CreateIIS7Site(site); } else { newSiteId = WebUtils.CreateSite(site); } vars.VirtualDirectory = String.Empty; vars.NewWebSite = true; vars.NewVirtualDirectory = false; // update setup variables vars.WebSiteId = newSiteId; //update log Log.WriteEnd("Created web site"); // Finish(LogStartMessage); //update install log InstallLog.AppendLine(string.Format("- Created a new web site named \"{0}\" ({1})", siteName, newSiteId)); InstallLog.AppendLine(" You can access the application by the following URLs:"); string[] urls = Utils.GetApplicationUrls(ip, domain, port, null); foreach (string url in urls) { InstallLog.AppendLine(" http://" + url); } }
void IInstallAction.Run(SetupVariables vars) { var appPoolName = String.Format(AppPoolNameFormatString, vars.ComponentFullName); var userDomain = vars.UserDomain; var netbiosDomain = userDomain; var userName = vars.UserAccount; var userPassword = vars.UserPassword; var identity = GetWebIdentity(vars); var componentId = vars.ComponentId; var iisVersion = vars.IISVersion; var iis7 = (iisVersion.Major == 7); var poolExists = false; // vars.WebApplicationPoolName = appPoolName; // Maintain backward compatibility if (iis7) { poolExists = WebUtils.IIS7ApplicationPoolExists(appPoolName); } else { poolExists = WebUtils.ApplicationPoolExists(appPoolName); } // This flag is the opposite of poolExists flag vars.NewWebApplicationPool = !poolExists; if (poolExists) { //update app pool Log.WriteStart("Updating application pool"); Log.WriteInfo(String.Format("Updating application pool \"{0}\"", appPoolName)); // if (iis7) { WebUtils.UpdateIIS7ApplicationPool(appPoolName, userName, userPassword); } else { WebUtils.UpdateApplicationPool(appPoolName, userName, userPassword); } // //update log Log.WriteEnd("Updated application pool"); //update install log InstallLog.AppendLine(String.Format("- Updated application pool named \"{0}\"", appPoolName)); } else { // create app pool Log.WriteStart("Creating application pool"); Log.WriteInfo(String.Format("Creating application pool \"{0}\"", appPoolName)); // if (iis7) { WebUtils.CreateIIS7ApplicationPool(appPoolName, userName, userPassword); } else { WebUtils.CreateApplicationPool(appPoolName, userName, userPassword); } //update log Log.WriteEnd("Created application pool"); //update install log InstallLog.AppendLine(String.Format("- Created a new application pool named \"{0}\"", appPoolName)); } }
/// <summary> /// Sets the specified value in the specified Ini file to the given value. /// </summary> /// <param name="p_strSettingsFileName">The name of the settings file to edit.</param> /// <param name="p_strSection">The section in the Ini file to edit.</param> /// <param name="p_strKey">The key in the Ini file to edit.</param> /// <param name="p_strValue">The value to which to set the key.</param> /// <returns><c>true</c> if the value was set; <c>false</c> /// if the user chose not to overwrite the existing value.</returns> public virtual bool EditIni(string p_strSettingsFileName, string p_strSection, string p_strKey, string p_strValue) { if (m_booDontOverwriteAllIni) { return(false); } if (!TouchedFiles.Contains(p_strSettingsFileName)) { TouchedFiles.Add(p_strSettingsFileName); TransactionalFileManager.Snapshot(p_strSettingsFileName); } IMod modOldMod = InstallLog.GetCurrentIniEditOwner(p_strSettingsFileName, p_strSection, p_strKey); string strOldValue = IniMethods.GetPrivateProfileString(p_strSection, p_strKey, null, p_strSettingsFileName); if (!m_booOverwriteAllIni) { string strMessage = null; if (modOldMod != null) { strMessage = String.Format("Key '{{0}}' in section '{{1}}' of {{2}} has already been overwritten by '{0}'\n" + "Overwrite again with this mod?\n" + "Current value '{{3}}', new value '{{4}}'", modOldMod.ModName); } else { strMessage = "The mod wants to modify key '{0}' in section '{1}' of {2}.\n" + "Allow the change?\n" + "Current value '{3}', new value '{4}'"; } switch (m_dlgOverwriteConfirmationDelegate(String.Format(strMessage, p_strKey, p_strSection, p_strSettingsFileName, strOldValue, p_strValue), false, false)) { case OverwriteResult.YesToAll: m_booOverwriteAllIni = true; break; case OverwriteResult.NoToAll: m_booDontOverwriteAllIni = true; break; case OverwriteResult.Yes: break; default: return(false); } } //if we are overwriting an original value, back it up if ((modOldMod == null) && (strOldValue != null)) { InstallLog.LogOriginalIniValue(p_strSettingsFileName, p_strSection, p_strKey, strOldValue); } IniMethods.WritePrivateProfileString(p_strSection, p_strKey, p_strValue, p_strSettingsFileName); InstallLog.AddIniEdit(Mod, p_strSettingsFileName, p_strSection, p_strKey, p_strValue); if (VirtualModActivator != null) { VirtualModActivator.LogIniEdits(Mod, p_strSettingsFileName, p_strSection, p_strKey, p_strValue); } return(true); }