private void LoadConfiguration(BuildForm bf) { _objConfig = new InstallerConfig(SparkGlobals.BuildConfigPath); _objConfig.Load(); _objConfig.BuildFileList(); if (_objConfig.Options.GetOption(InstallOption.AppGuid) == null) { Globals.Throw("The install option 'AppGuid' is required. Please add this option to the input configuration file."); } //Attempt to parse GUID - if it is invalid an exception will throw. ProgramInfo.TryParseGuidToUninstallGuid(_objConfig.Options.GetOption(InstallOption.AppGuid).Value); if (_objConfig.Options.GetOption(InstallOption.DisplayName) == null) { Globals.Throw("The install option 'DisplayName' is required. Please add this option to the input configuration file."); } Globals.Logger.LogInfo("Excluded " + _objConfig.NumExcludedFiles + " files."); Globals.Logger.LogInfo("Excluded " + _objConfig.NumExcludedDirectories + " directories."); Globals.Logger.LogInfo("Packaging " + _objConfig.GetFiles().Count + " total files."); _objFileTable = new InstallerFileTable(_objConfig); bf.Progress(0.01); }
private void RemoveAppRegistryKeys(ProgramInfo objProgramInfo) { // ** This keeps the publisher key there. I tis possible to remove publisher key // if there are no further keys.. but we don't do that. RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software", true); if (softwareKey != null) { RegistryKey publisherKey; publisherKey = softwareKey.OpenSubKey(objProgramInfo.Publisher, true); if (publisherKey != null) { publisherKey.DeleteSubKeyTree(objProgramInfo.DisplayName, false); publisherKey.Close(); } else { Globals.Logger.LogError("Could not find application subkey " + objProgramInfo.DisplayName + ". The uninstall may not have succeeded."); } softwareKey.Close(); } else { Globals.Logger.LogError("Could not find HKLM\\Software. The uninstall may not have succeeded."); } }
private RegistryKey GetUninstallerRegistryKey(ProgramInfo objProgramInfo, bool blnCreateIfNotFound = false) { RegistryKey appKey; RegistryKey softwareKey; softwareKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true); if (softwareKey == null) { Globals.Logger.LogError("HKLM\\Software registry key not found.", true, true); } string guidText = objProgramInfo.GetUninstallerGuidAsString(); appKey = softwareKey.OpenSubKey(guidText, true) ?? softwareKey.CreateSubKey(guidText); if (appKey == null) { Globals.Throw(String.Format("Unable to create uninstaller {0}", guidText)); } if (softwareKey != null) { softwareKey.Close(); } return(appKey); }
private void WriteUninstallerRegistryKeys(ProgramInfo objProgramInfo, string strUninstallExePath, string installLocation) { //https://msdn.microsoft.com/en-us/library/aa372105(v=vs.85).aspx RegistryKey key = GetUninstallerRegistryKey(objProgramInfo, true); WriteUninstallRegistryKeyValues(objProgramInfo, key, strUninstallExePath, installLocation); if (key != null) { key.Close(); } }
private void CreateUninstaller(ProgramInfo objProgramInfo, InstallerBinary objBinary, InstallerFileTable objTable, string strInstallRoot) { string strUninstallExePath; Globals.Logger.LogInfo("Creating Uninstaller"); //Add the root to the options. _objOptions.AddOrReplaceOption(new InstallOption(InstallOption.UninstallFolderRoot_Uninstaller_Only, strInstallRoot)); strUninstallExePath = objTable.WriteUninstaller(_objOptions, strInstallRoot); WriteUninstallerRegistryKeys(objProgramInfo, strUninstallExePath, strInstallRoot); }
private void CreateAppRegistryKeys(ProgramInfo objProgramInfo, string strInstallRoot) { // Adds HKLM\Software\*Publisher*\*App* // Adds HKLM\Software\*Publisher*\*App*\InstallDir //**Note: registry keys in HKLM will fall under Wow6432Node in 32 bit apps. HKLM\Software\Wow6432Node\.. DisplayMsg("Creating App Reg key"); RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software", true); if (!string.IsNullOrEmpty(objProgramInfo.Publisher)) { RegistryKey publisherKey; publisherKey = softwareKey.OpenSubKey(objProgramInfo.Publisher, true); if (publisherKey == null) { publisherKey = softwareKey.CreateSubKey(objProgramInfo.Publisher); } RegistryKey appKey; appKey = publisherKey.OpenSubKey(objProgramInfo.DisplayName, true); if (appKey == null) { appKey = publisherKey.CreateSubKey(objProgramInfo.DisplayName); } appKey.SetValue("InstallDir", strInstallRoot); if (appKey != null) { appKey.Close(); } if (publisherKey != null) { publisherKey.Close(); } } else { Globals.Logger.LogWarn("Program publisher was not set in the install config. Cannot create /software registry key."); } if (softwareKey != null) { softwareKey.Close(); } }
private void ExecuteUninstall() { InstallerFileTable objTable = null; InstallerBinary objBinary = null; InstallOptions objOptions = null; InstallState = Installer.InstallState.Uninstalling; //TODO: uninstaller has to store options AND uninstall table. try { objBinary = new InstallerBinary(); objBinary.OpenStream(); objOptions = new InstallOptions(); objOptions.Deserialize(objBinary); objTable = new InstallerFileTable(this); objTable.Deserialize(objBinary); objBinary.CloseStream(); ProgramInfo objInfo = new ProgramInfo(objOptions); string strInstallRoot = objOptions.GetOptionValueOrDefault(InstallOption.UninstallFolderRoot_Uninstaller_Only); if (!System.IO.Directory.Exists(strInstallRoot)) { Globals.Logger.LogError("Fatal Error: The original install directory '" + strInstallRoot + "' does not exist, or was not packed in the uninstaller binary.", true, true); } RollbackOrUninstall(objTable, strInstallRoot, 0.0); RemoveRegistryKeys(objInfo); InstallState = Installer.InstallState.Successful; } catch (Exception ex) { InstallState = Installer.InstallState.Canceled; InstallErrors.Add("Error: " + ex.ToString()); Globals.Logger.LogError(ex.ToString(), false, true); } finally { EndUninstall(); } }
private void WriteUninstallRegistryKeyValues(ProgramInfo objProgramInfo, RegistryKey key, string strUninstallExePath, string installLocation) { //**Note: if you modify this to add keys make sure to modify the RemoveInstallerRegistryKeys if (!String.IsNullOrEmpty(objProgramInfo.DisplayName)) { key.SetValue("DisplayName", objProgramInfo.DisplayName); } else { Globals.Logger.LogWarn("DisplayName not set in installer configuration."); key.SetValue("DisplayName", "Spark Program"); } key.SetValue("InstallLocation", installLocation); key.SetValue("ApplicationVersion", objProgramInfo.ApplicationVersion); key.SetValue("DisplayVersion", objProgramInfo.DisplayVersion); if (!String.IsNullOrEmpty(objProgramInfo.Publisher)) { key.SetValue("Publisher", objProgramInfo.Publisher); } // Icon.ExtractAssociatedIcon(Application.ExecutablePath); key.SetValue("DisplayIcon", strUninstallExePath); if (!string.IsNullOrEmpty(objProgramInfo.URLInfoAbout)) { key.SetValue("URLInfoAbout", objProgramInfo.URLInfoAbout); } if (!string.IsNullOrEmpty(objProgramInfo.Contact)) { key.SetValue("Contact", objProgramInfo.Contact); } if (!string.IsNullOrEmpty(objProgramInfo.Comments)) { key.SetValue("Comments", objProgramInfo.Comments); } key.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd")); key.SetValue("UninstallString", strUninstallExePath + " " + SparkFlags.Uninstall); }
private void RemoveInstallerRegistryKeys(ProgramInfo objProgramInfo) { RegistryKey softwareKey; string guidText = objProgramInfo.GetUninstallerGuidAsString(); softwareKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", true); if (softwareKey == null) { Globals.Logger.LogError("HKLM\\Software registry key not found."); return; } softwareKey.DeleteSubKeyTree(guidText, false); if (softwareKey != null) { softwareKey.Close(); } }
public static bool ApplicationIsInstalled(ProgramInfo objProgramInfo) { bool blnValue = true; RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software", true); if (softwareKey == null) { blnValue = false; } else { RegistryKey publisherKey; publisherKey = softwareKey.OpenSubKey(objProgramInfo.Publisher, true); if (publisherKey == null) { blnValue = false; } else { RegistryKey appKey; appKey = publisherKey.OpenSubKey(objProgramInfo.DisplayName, true); if (appKey == null) { blnValue = false; } else { appKey.Close(); } publisherKey.Close(); } softwareKey.Close(); } return(blnValue); }
private void RemoveRegistryKeys(ProgramInfo objProgramInfo) { RemoveAppRegistryKeys(objProgramInfo); RemoveInstallerRegistryKeys(objProgramInfo); }
private void ExecuteInstallation() { DisplayMsg("Beginning Installation"); InstallState = InstallState.Installing; InstallerFileTable objTable = null; string strInstallRoot = CreateInstallRoot(); if (string.IsNullOrEmpty(strInstallRoot)) { return; // error } double dblProgressBeforeCopy = 0; try { DisplayMsg("Creating install dir " + strInstallRoot); if (!System.IO.Directory.Exists(strInstallRoot)) { System.IO.Directory.CreateDirectory(strInstallRoot); } // - Do work InstallerBinary objBinary; DisplayMsg("Creating binary"); objBinary = new InstallerBinary(); objBinary.OpenStream(); //**Read past the install options section. Note this // is NOT used DisplayMsg("Reading Dummy Options"); InstallOptions dummy = new InstallOptions(); dummy.Deserialize(objBinary); //Validate appliation GUID for uninstall. InstallOption guidOpt = GetOption(InstallOption.AppGuid); if (guidOpt == null) { Globals.Throw("Could not install. Appliation GUID was not specified in install options."); } else { ProgramInfo.TryParseGuidToUninstallGuid(guidOpt.Value); } DisplayMsg("Creating Program Info"); ProgramInfo objInfo = new ProgramInfo(_objOptions); DisplayMsg("Reading File Table"); objTable = new InstallerFileTable(this); objTable.Deserialize(objBinary); _dblProgress = dblProgressBeforeCopy = 0.5; DisplayMsg("Unpacking Files"); objTable.UnpackFiles( objBinary, strInstallRoot, ref _dblProgress, _installerCancellationToken.Token, ref _strCurrentFile ); objBinary.CloseStream(); CreateAppRegistryKeys(objInfo, strInstallRoot); CreateUninstaller(objInfo, objBinary, objTable, strInstallRoot); } catch (Exception ex) { InstallState = Installer.InstallState.Canceled; InstallErrors.Add("Error: " + ex.ToString()); Globals.Logger.LogError(ex.ToString(), false, true); RollbackOrUninstall(objTable, strInstallRoot, dblProgressBeforeCopy); } finally { EndInstallation(); } }