protected override void OnExit(object sender, EventArgs e) { var app = Application as InstanceAwareApplication; if ((app != null && app.IsFirstInstance)) { _log.Info("Exiting application."); // make sure to save one final time the application wide settings. Properties.Settings.Default.Save(); var client = IoC.Get <IBigStashClient>(); if (client.IsLogged()) { _log.Info("Saving preferences.json at \"" + Properties.Settings.Default.SettingsFilePath + "\"."); // Reset the api endpoint to the default 'ServerBaseAddress' before saving the preferences file // for the last time. this.ResetDebugServerBaseAddress(client); // Save preferences file. LocalStorage.WriteJson(Properties.Settings.Default.SettingsFilePath, client.Settings, Encoding.UTF8, true); } if (Properties.Settings.Default.SettingsUpgradeRequired) { SquirrelHelper.CopyMigrationUserConfig(); } } base.OnExit(sender, e); }
/// <summary> /// Get the root app directory using the Squirrel manager. /// </summary> /// <returns></returns> private static string GetRootAppDirectory() { var appName = SquirrelHelper.GetAppName(); var updateLocation = SquirrelHelper.GetUpdateLocation(); using (var mgr = new UpdateManager(updateLocation, appName, FrameworkVersion.Net45)) { return(mgr.RootAppDirectory); } }
/// <summary> /// Call SquirrelHelper.CopyMigrationUserConfig() to copy settings for migrating on the next run. /// </summary> /// <returns></returns> private string ConfigureSettingsMigration() { try { // Copy current user settings to migrate to. var migrationUserConfigPath = SquirrelHelper.CopyMigrationUserConfig(); return(migrationUserConfigPath); } catch (Exception) { _log.Error("Settings migration failed. Default settings will be used if the next instance is an update."); return(null); } }
/// <summary> /// Restarts the app. /// </summary> public void RestartApplicationAfterUpdate() { // Call Update.exe to run the new executable. // It will wait until this instance is closed before it executes the new instance. SquirrelHelper.RunUpdatedExe(); Properties.Settings.Default.RestartAfterUpdate = true; Properties.Settings.Default.Save(); _log.Debug("Sending a graceful restart message."); // Let's send a RestartAppMessage with DoGracefulRestart = true; var restartAppMessage = IoC.Get <IRestartAppMessage>(); restartAppMessage.DoGracefulRestart = true; restartAppMessage.ConfigureSettingsMigration = true; this._eventAggregator.BeginPublishOnUIThread(restartAppMessage); }
private void FlipRunOnStartup() { using (var registryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) { var curAssembly = Assembly.GetExecutingAssembly(); var installDirName = SquirrelHelper.GetRootAppDirectoryName(); if (this.RunOnStartup) { registryKey.SetValue(installDirName, curAssembly.Location + " -m"); } else { registryKey.DeleteValue(installDirName, false); } } }
/// <summary> /// This code has to exist in order for Squirrel to work its magic. /// What it does, is hook methods to the install/uninstall events. /// Basic functionality includes: Create and remove shortcut upon install/uninstall, /// as well as when updating. /// </summary> public static void CustomSquirrelSetup() { var appName = SquirrelHelper.GetAppName(); var updateLocation = SquirrelHelper.GetUpdateLocation(); using (var mgr = new UpdateManager(updateLocation, appName, FrameworkVersion.Net45)) { SquirrelAwareApp.HandleEvents( onInitialInstall: v => { _log.Warn(Utilities.GetCallerName() + ": Installation in progress."); CreateOrUpdateCustomRegistryEntries(mgr.RootAppDirectory); RegisterShellExtension(mgr.RootAppDirectory); mgr.CreateShortcutForThisExe(); }, onAppUpdate: v => { _log.Warn(Utilities.GetCallerName() + ": Update in progress."); mgr.CreateShortcutForThisExe(); CreateOrUpdateCustomRegistryEntries(mgr.RootAppDirectory, v.ToString()); RegisterShellExtension(mgr.RootAppDirectory); }, onAppUninstall: v => { _log.Warn(Utilities.GetCallerName() + ": Uninstall in progress."); UnregisterShellExtension(mgr.RootAppDirectory); RemoveCustomRegistryEntries(mgr.RootAppDirectory); mgr.RemoveShortcutForThisExe(); StopBigStashOnUninstall(); CallBatchDelete(mgr.RootAppDirectory); }); } }
public async Task CheckForUpdate() { this.ErrorMessage = null; bool isDebug = false; #if DEBUG isDebug = true; #endif // when debugging do nothing. if (isDebug) { return; } // No need to check for update when already checking and/or installing one. // The same holds for when a restart is needed because of a previously installed update, // while still running the same application instance. if (this.IsBusy || this.RestartNeeded) { return; } if (!this._deepfreezeClient.IsInternetConnected) { this.ErrorMessage = Properties.Resources.ErrorCheckingForUpdateWithoutInternetGenericText; return; } IsUpToDate = false; this.IsBusy = true; // set UI message to checking for update this.UpdateMessage = Properties.Resources.CheckingForUpdateText; try { // Verify that old ClickOnce deployments are removed. await SquirrelHelper.TryRemoveClickOnceAncestor(); // check for update var updateInfo = await SquirrelHelper.CheckForUpdateAsync(); var hasUpdates = updateInfo.ReleasesToApply.Count > 0; // Check if older releases were fetched for installing. // This is happens when the running instance has a more recent version // than the one reported in the remote RELEASES file. // If this is the case, then we remove the older entries from ReleasesToApply // and continue with installing only if the list is not empty (it contains newer versions). if (hasUpdates) { var installedVersion = SquirrelHelper.GetCurrentlyInstalledVersion(); var releasesToRemove = new List <Squirrel.ReleaseEntry>(); foreach (var release in updateInfo.ReleasesToApply.ToList()) { if (release.Version <= installedVersion) { releasesToRemove.Add(release); } } foreach (var releaseToRemove in releasesToRemove) { updateInfo.ReleasesToApply.Remove(releaseToRemove); } hasUpdates = updateInfo.ReleasesToApply.Count > 0; releasesToRemove.Clear(); releasesToRemove = null; } if (!hasUpdates) { // no updates found, update the UI and return this.IsBusy = false; this.IsUpToDate = true; this.RestartNeeded = false; this.UpdateFound = false; this.UpdateMessage = Properties.Resources.UpToDateText; return; } // Update found, continue with download this.UpdateMessage = Properties.Resources.DowloadingUpdateText; await SquirrelHelper.DownloadReleasesAsync(updateInfo.ReleasesToApply).ConfigureAwait(false); // Update donwload finished, continue with install this.UpdateMessage = Properties.Resources.InstallingUpdateText; var applyResult = await SquirrelHelper.ApplyReleasesAsync(updateInfo).ConfigureAwait(false); Properties.Settings.Default.SettingsUpgradeRequired = true; Properties.Settings.Default.Save(); // update the UI to show that a restart is needed. this.RestartNeeded = true; this.UpdateMessage = Properties.Resources.RestartNeededText; // send a message using the event aggregator to inform the shellviewmodel that a restart is needed. var restartMessage = IoC.Get <IRestartNeededMessage>(); restartMessage.RestartNeeded = true; this._eventAggregator.PublishOnUIThread(restartMessage); } catch (Exception e) { // if RELEASES is not found, don't display an error, just write it in the log and show that the app is up to date. if (e.Message.Contains("RELEASES") && e.Message.Contains("does not exist")) { _log.Warn(Utilities.GetCallerName() + " error, thrown " + e.GetType().ToString() + " with message \"" + e.Message + "\"."); this.UpdateMessage = Properties.Resources.NoUpdatesFoundText; } else { _log.Error(Utilities.GetCallerName() + " error, thrown " + e.GetType().ToString() + " with message \"" + e.Message + "\".", e); this.UpdateMessage = null; this.ErrorMessage = Properties.Resources.ErrorCheckingForUpdateGenericText; } } finally { this.IsBusy = false; } }
protected override async void OnStartup(object sender, StartupEventArgs e) { // check if this is the first instance running // or a newer with the first instance already running. // if this is the case, the newer instance shuts down. var app = Application.Current as InstanceAwareApplication; if (!(app == null || app.IsFirstInstance)) { app.Shutdown(); } else { // Else go on with normal startup. // Try migrating old settings after an update. // migrate.user.config must exist in AppData\BigStash\ TryMigratingOldUserConfig(); // Upgrade settings from previous squirrel installation. //if (Properties.Settings.Default.SettingsUpgradeRequired) //{ // Properties.Settings.Default.Upgrade(); // Properties.Settings.Default.SettingsUpgradeRequired = false; // Properties.Settings.Default.Save(); // Properties.Settings.Default.Reload(); //} // Change default ClickOnce icon in Programs and Features entry, // if it's not already set. // SetAddRemoveProgramsIcon(); SquirrelHelper.TryRenameOldNameShortcut(); log4net.Config.XmlConfigurator.Configure(new FileInfo("Log4Net.config")); //#if DEBUG // ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).Root.Level = log4net.Core.Level.Debug; // ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty); // Properties.Settings.Default.VerboseDebugLogging = true; //#endif #if DEBUG if (!String.IsNullOrEmpty(Properties.Settings.Default.AWSEndpointDefinition)) { ConfigurationManager.AppSettings["AWSEndpointDefinition"] = Properties.Settings.Default.AWSEndpointDefinition; } #endif var currentVersion = SquirrelHelper.GetCurrentlyInstalledVersionString(); this.SetVersionForUserAgent(currentVersion); _log.Info("Starting up a new instance of " + Properties.Settings.Default.ApplicationFullName + " " + currentVersion + "."); _log.Info("*****************************************************"); _log.Info("*****************************************************"); _log.Info("********* **********"); _log.Info("********* BigStash **********"); _log.Info("********* **********"); _log.Info("*****************************************************"); _log.Info("*****************************************************"); #if DEBUG _log.Debug("DEBUG MODE ON"); #endif CheckAndEnableVerboseDebugLogging(); // Set Application local app data folder and file paths // in Application.Properties for use in this application instance. SetApplicationPathsProperties(); // if LOCALAPPDATA\BigStash doesn't exist, create it. CreateLocalApplicationDataDirectory(); // Try migrating data from old deepfreeze folder to BigStash folder. bool didBigStashMigration = await TryMigrateDeepfreezeData(); DisplayRootViewFor <IShell>(); // after showing the main window, if migration took place then show the bigstash update message. if (didBigStashMigration) { if (!Properties.Settings.Default.BigStashUpdateMessageShown) { await ShowBigStashUpdateMessage(); } } else { // this is a clean install of BigStash, just mark the update message as shown. Properties.Settings.Default.BigStashUpdateMessageShown = true; Properties.Settings.Default.Save(); } // Catch with args and forward a message with them if (e.Args.Length > 0) { this.CatchAndForwardArgs(e.Args); } base.OnStartup(sender, e); } }
public MefBootstrapper() { Initialize(); SquirrelHelper.CustomSquirrelSetup(); }