public async Task FirstStepRemovesClickOnceShortcut() { using (IntegrationTestHelper.WithClickOnceApp()) { var clickOnceInfo = UninstallInfo.Find(IntegrationTestHelper.ClickOnceAppName); Assert.True(File.Exists(clickOnceInfo.GetShortcutPath())); string rootDir; using (IntegrationTestHelper.WithTempDirectory(out rootDir)) { using (var updateManager = IntegrationTestHelper.GetSquirrelUpdateManager(rootDir)) { using (IntegrationTestHelper.CleanupSquirrel(updateManager)) { var migrator = new InClickOnceAppMigrator(updateManager, IntegrationTestHelper.ClickOnceAppName); await migrator.Execute(); Assert.False(File.Exists(clickOnceInfo.GetShortcutPath())); } } } } }
public async Task FirstStepRemovesPinnedTaskbarIcon() { string roamingFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string taskbarFolder = Path.Combine(roamingFolder, @"Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"); using (IntegrationTestHelper.WithClickOnceApp()) { var clickOnceInfo = UninstallInfo.Find(IntegrationTestHelper.ClickOnceAppName); string shortcutPath = clickOnceInfo.GetShortcutPath(); TaskbarHelper.PinToTaskbar(shortcutPath); string rootDir; using (IntegrationTestHelper.WithTempDirectory(out rootDir)) { using (var updateManager = IntegrationTestHelper.GetSquirrelUpdateManager(rootDir)) { using (IntegrationTestHelper.CleanupSquirrel(updateManager)) { var migrator = new InClickOnceAppMigrator(updateManager, IntegrationTestHelper.ClickOnceAppName); await migrator.Execute(); Assert.False(File.Exists(Path.Combine(taskbarFolder, IntegrationTestHelper.ClickOnceAppName + ".appref-ms"))); } } } } }
private void bgwUninstall_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; int progress = 0; UninstallInfo info = Helper.Deserialize <UninstallInfo>(uninst); UnRegOcx(info.DestDir); DirectoryInfo di = new DirectoryInfo(info.DestDir); int total = di.GetFiles().Length + info.Manifest.Count(); worker.ReportProgress(progress, total); foreach (var fi in di.GetFiles()) { try { fi.Delete(); } catch (Exception ex) { Console.WriteLine(ex.Message); } Thread.Sleep(10); progress++; worker.ReportProgress(progress, progress); } foreach (InstalledFiles file in info.Manifest) { if (File.Exists(file.FullPath)) { File.Delete(file.FullPath); } Thread.Sleep(10); progress++; worker.ReportProgress(progress, progress); } worker.ReportProgress(total, total); try { Directory.Delete(info.DestDir, true); } catch { } e.Result = true; }
public async Task InSquirrelAppMigratorUninstallsClickOnceApp() { using (IntegrationTestHelper.WithClickOnceApp()) { var migrator = new InSquirrelAppMigrator(IntegrationTestHelper.ClickOnceAppName); await migrator.Execute(); var installInfo = UninstallInfo.Find(IntegrationTestHelper.ClickOnceAppName); Assert.Null(installInfo); } }
public UninstallInfo[] getDesktopApplications() { using (RegistryKey key = RegistryHelper.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")) { string[] names = key.GetSubKeyNames(); UninstallInfo[] info = new UninstallInfo[names.Length]; for (int i = 0; i < names.Length; i++) { info[i] = new UninstallInfo(key.OpenSubKey(names[i])); } return(info); } }
public async Task UninstallsClickOnceApp() { var installer = new ClickOnceInstaller(); await installer.InstallClickOnceApp(new Uri(IntegrationTestHelper.ClickOnceTestAppPath)); UninstallInfo theApp = UninstallInfo.Find(IntegrationTestHelper.ClickOnceAppName); Assert.NotNull(theApp); var uninstaller = new Uninstaller(); uninstaller.Uninstall(theApp); UninstallInfo shouldBeNull = UninstallInfo.Find(IntegrationTestHelper.ClickOnceAppName); Assert.Null(shouldBeNull); }
public static IDisposable WithClickOnceApp() { string clickOnceApp = Path.Combine(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName, "ClickOnceApp/ClickOnceApp.application"); // omg var installer = new ClickOnceInstaller(); installer.InstallClickOnceApp(new Uri(clickOnceApp)).Wait(); return(Disposable.Create(() => { UninstallInfo theApp = UninstallInfo.Find(ClickOnceAppName); if (theApp == null) { return; } var uninstaller = new Uninstaller(); uninstaller.Uninstall(theApp); })); }
async Task CheckForUpdates() { try { if (Config.Default.settings.update.isDisabled) { Trace.TraceInformation("The software update check is disabled by the user; skipping check"); return; } // Remove any old ClickOnce installs try { var uninstallInfo = UninstallInfo.Find("IPFilter Updater"); if (uninstallInfo != null) { Trace.TraceWarning("Old ClickOnce app installed! Trying to remove..."); var uninstaller = new Uninstaller(); uninstaller.Uninstall(uninstallInfo); Trace.TraceInformation("Successfully removed ClickOnce app"); } } catch (Exception ex) { Trace.TraceError("Failed to remove old ClickOnce app: " + ex); } var applicationDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "IPFilter"); var installerDir = new DirectoryInfo(Path.Combine(applicationDirectory, "installer")); // Detect the current running version. The ProductVersion contains the informational, semantic version e.g. "3.0.0-beta" var versionInfo = Process.GetCurrentProcess().MainModule.FileVersionInfo; var currentVersion = new SemanticVersion(versionInfo.ProductVersion); // Remove any old installers try { if (!installerDir.Exists) { installerDir.Create(); } else if (!Config.Default.settings.update.isCleanupDisabled) { // Don't delete the MSI for the current installed version var currentMsiName = "IPFilter." + currentVersion.ToNormalizedString() + ".msi"; // Scan the directory for all installers foreach (var fileInfo in installerDir.GetFiles("IPFilter.*.msi")) { // Don't remove the installer for the installed version if (fileInfo.Name.Equals(currentMsiName, StringComparison.OrdinalIgnoreCase)) { continue; } Trace.TraceInformation("Removing cached installer: " + fileInfo.Name); fileInfo.SafeDelete(); } } } catch (Exception ex) { Trace.TraceError("Couldn't clean up old installers: " + ex); } Trace.TraceInformation("Checking for software updates..."); progress.Report(new ProgressModel(UpdateState.Downloading, "Checking for software updates...", -1)); var updater = new Updater(); var result = await updater.CheckForUpdateAsync(Config.Default.settings.update.isPreReleaseEnabled); if (result == null) { return; } var latestVersion = new SemanticVersion(result.Version); Update.IsUpdateAvailable = latestVersion > currentVersion; if (Update.IsUpdateAvailable) { Update.AvailableVersion = latestVersion; Update.IsUpdateRequired = true; Update.MinimumRequiredVersion = latestVersion; Update.UpdateSizeBytes = 2000000; } Trace.TraceInformation("Current version: {0}", Update.CurrentVersion); Trace.TraceInformation("Available version: {0}", Update.AvailableVersion?.ToString() ?? "<no updates>"); if (!Update.IsUpdateAvailable) { return; } if (MessageBoxHelper.Show(dispatcher, "Update Available", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes, "An update to version {0} is available. Would you like to update now?", Update.AvailableVersion) != MessageBoxResult.Yes) { return; } Trace.TraceInformation("Starting application update..."); // If we're not "installed", then don't check for updates. This is so the // executable can be stand-alone. Stand-alone self-update to come later. using (var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\IPFilter")) { var installPath = (string)key?.GetValue("InstallPath"); if (installPath == null) { using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("https://www.ipfilter.app/") { UseShellExecute = true }; process.Start(); return; } } } // Download the MSI to the installer directory var msiPath = Path.Combine(installerDir.FullName, "IPFilter." + Update.AvailableVersion + ".msi"); // Download the installer using (var handler = new WebRequestHandler()) { handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; var uri = new Uri($"{result.Uri}?{DateTime.Now.ToString("yyyyMMddHHmmss")}"); using (var httpClient = new HttpClient(handler)) using (var response = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Token)) { if (cancellationToken.IsCancellationRequested) { progress.Report(new ProgressModel(UpdateState.Ready, "Update cancelled. Ready.", 100)); Update.IsUpdating = false; return; } var length = response.Content.Headers.ContentLength; double lengthInMb = !length.HasValue ? -1 : (double)length.Value / 1024 / 1024; double bytesDownloaded = 0; using (var stream = await response.Content.ReadAsStreamAsync()) using (var msi = File.Open(msiPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { var buffer = new byte[65535 * 4]; int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken.Token); while (bytesRead != 0) { await msi.WriteAsync(buffer, 0, bytesRead, cancellationToken.Token); bytesDownloaded += bytesRead; if (length.HasValue) { double downloadedMegs = bytesDownloaded / 1024 / 1024; var percent = (int)Math.Floor((bytesDownloaded / length.Value) * 100); var status = string.Format(CultureInfo.CurrentUICulture, "Downloaded {0:F2} MB of {1:F2} MB", downloadedMegs, lengthInMb); Update.IsUpdating = true; Update.DownloadPercentage = percent; progress.Report(new ProgressModel(UpdateState.Downloading, status, percent)); } if (cancellationToken.IsCancellationRequested) { progress.Report(new ProgressModel(UpdateState.Ready, "Update cancelled. Ready.", 100)); Update.IsUpdating = false; return; } bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken.Token); } } } } progress.Report(new ProgressModel(UpdateState.Ready, "Launching update...", 100)); Update.IsUpdating = false; // Now run the installer var sb = new StringBuilder("msiexec.exe "); // Enable logging for the installer var installLog = Path.Combine(applicationDirectory, "install.log"); sb.AppendFormat(" /l*v \"{0}\"", installLog); sb.AppendFormat(" /i \"{0}\"", msiPath); //sb.Append(" /passive"); ProcessInformation processInformation = new ProcessInformation(); StartupInfo startupInfo = new StartupInfo(); SecurityAttributes processSecurity = new SecurityAttributes(); SecurityAttributes threadSecurity = new SecurityAttributes(); processSecurity.nLength = Marshal.SizeOf(processSecurity); threadSecurity.nLength = Marshal.SizeOf(threadSecurity); const int NormalPriorityClass = 0x0020; if (!ProcessManager.CreateProcess(null, sb, processSecurity, threadSecurity, false, NormalPriorityClass, IntPtr.Zero, null, startupInfo, processInformation)) { throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); } try { //dispatcher.Invoke(DispatcherPriority.Normal, new Action(Application.Current.Shutdown)); Application.Current.Shutdown(); } catch (Exception ex) { Trace.TraceError("Exception when shutting down app for update: " + ex); Update.ErrorMessage = "Couldn't shutdown the app to apply update."; } } catch (Exception ex) { Trace.TraceWarning("Application update check failed: " + ex); } finally { progress.Report(new ProgressModel(UpdateState.Ready, "Ready", 0)); } }
async Task CheckForUpdates() { try { // Remove any old ClickOnce installs try { var uninstallInfo = UninstallInfo.Find("IPFilter Updater"); if (uninstallInfo != null) { Trace.TraceWarning("Old ClickOnce app installed! Trying to remove..."); var uninstaller = new Uninstaller(); uninstaller.Uninstall(uninstallInfo); Trace.TraceInformation("Successfully removed ClickOnce app"); } } catch (Exception ex) { Trace.TraceError("Failed to remove old ClickOnce app: " + ex); telemetryClient?.TrackException(ex); } Trace.TraceInformation("Checking for software updates..."); progress.Report(new ProgressModel(UpdateState.Downloading, "Checking for software updates...", -1)); var updater = new Updater(); var result = await updater.CheckForUpdateAsync(); var currentVersion = new Version(Process.GetCurrentProcess().MainModule.FileVersionInfo.FileVersion); var latestVersion = new Version(result.Version); Update.IsUpdateAvailable = latestVersion > currentVersion; if (Update.IsUpdateAvailable) { Update.AvailableVersion = latestVersion; Update.IsUpdateRequired = true; Update.MinimumRequiredVersion = latestVersion; Update.UpdateSizeBytes = 2000000; } Trace.TraceInformation("Current version: {0}", Update.CurrentVersion); Trace.TraceInformation("Available version: {0}", Update.AvailableVersion?.ToString() ?? "<no updates>"); if (!Update.IsUpdateAvailable) { return; } if (MessageBoxHelper.Show(dispatcher, "Update Available", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes, "An update to version {0} is available. Would you like to update now?", Update.AvailableVersion) != MessageBoxResult.Yes) { return; } Trace.TraceInformation("Starting application update..."); // If we're not "installed", then don't check for updates. This is so the // executable can be stand-alone. Stand-alone self-update to come later. using (var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\IPFilter")) { var installPath = (string)key?.GetValue("InstallPath"); if (installPath == null) { using (var process = new Process()) { process.StartInfo = new ProcessStartInfo("https://davidmoore.github.io/ipfilter/") { UseShellExecute = true }; process.Start(); return; } } } var msiPath = Path.Combine(Path.GetTempPath(), "IPFilter.msi"); // Download the installer using (var handler = new WebRequestHandler()) { handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; var uri = new Uri($"{result.Uri}?{DateTime.Now.ToString("yyyyMMddHHmmss")}"); using (var httpClient = new HttpClient(handler)) using (var response = await httpClient.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, cancellationToken.Token)) { if (cancellationToken.IsCancellationRequested) { progress.Report(new ProgressModel(UpdateState.Ready, "Update cancelled. Ready.", 100)); Update.IsUpdating = false; return; } var length = response.Content.Headers.ContentLength; double lengthInMb = !length.HasValue ? -1 : (double)length.Value / 1024 / 1024; double bytesDownloaded = 0; using (var stream = await response.Content.ReadAsStreamAsync()) using (var msi = File.Open(msiPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { var buffer = new byte[65535 * 4]; int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken.Token); while (bytesRead != 0) { await msi.WriteAsync(buffer, 0, bytesRead, cancellationToken.Token); bytesDownloaded += bytesRead; if (length.HasValue) { double downloadedMegs = bytesDownloaded / 1024 / 1024; var percent = (int)Math.Floor((bytesDownloaded / length.Value) * 100); var status = string.Format(CultureInfo.CurrentUICulture, "Downloaded {0:F2} MB of {1:F2} MB", downloadedMegs, lengthInMb); Update.IsUpdating = true; Update.DownloadPercentage = percent; progress.Report(new ProgressModel(UpdateState.Downloading, status, percent)); } if (cancellationToken.IsCancellationRequested) { progress.Report(new ProgressModel(UpdateState.Ready, "Update cancelled. Ready.", 100)); Update.IsUpdating = false; return; } bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken.Token); } } } } progress.Report(new ProgressModel(UpdateState.Ready, "Launching update...", 100)); Update.IsUpdating = false; // Now run the installer var sb = new StringBuilder("msiexec.exe "); // Enable logging for the installer sb.AppendFormat(" /l*v \"{0}\"", Path.Combine(Path.GetTempPath(), "IPFilter.log")); sb.AppendFormat(" /i \"{0}\"", msiPath); //sb.Append(" /passive"); ProcessInformation processInformation = new ProcessInformation(); StartupInfo startupInfo = new StartupInfo(); SecurityAttributes processSecurity = new SecurityAttributes(); SecurityAttributes threadSecurity = new SecurityAttributes(); processSecurity.nLength = Marshal.SizeOf(processSecurity); threadSecurity.nLength = Marshal.SizeOf(threadSecurity); const int NormalPriorityClass = 0x0020; if (!ProcessManager.CreateProcess(null, sb, processSecurity, threadSecurity, false, NormalPriorityClass, IntPtr.Zero, null, startupInfo, processInformation)) { throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); } try { //dispatcher.Invoke(DispatcherPriority.Normal, new Action(Application.Current.Shutdown)); Application.Current.Shutdown(); } catch (Exception ex) { Trace.TraceError("Exception when shutting down app for update: " + ex); Update.ErrorMessage = "Couldn't shutdown the app to apply update."; telemetryClient?.TrackException(ex); } } catch (Exception ex) { Trace.TraceWarning("Application update check failed: " + ex); telemetryClient?.TrackException(ex); telemetryClient?.Flush(); } finally { progress.Report(new ProgressModel(UpdateState.Ready, "Ready", 0)); } }
static void Main(string[] args) { if (args == null) { return; } else if (args.Count() < 3) { return; } else { string sDestDirectory = args[0]; string sFileName = args[1]; string sSeparator = args[2]; //uninstall var uninstallInfo = UninstallInfo.Find("IliasSync2Folder"); if (uninstallInfo != null) { Console.WriteLine("Uninstalling current ILIAS Sync2Folder version..."); Uninstaller uninstaller = new Uninstaller(); uninstaller.Uninstall(uninstallInfo); Console.WriteLine("Uninstalling done."); } //launch new version's installer Console.WriteLine("Launching new installer..."); var installer = Process.Start(sDestDirectory + sSeparator + "setup.exe"); installer.WaitForExit(milliseconds: 20000); Process[] processes = Process.GetProcessesByName("dfsvc"); if (processes.Length != 0) { Console.WriteLine("ClickOnce found running"); Console.WriteLine("Waiting for the installer to close..."); processes[0].WaitForExit(milliseconds: 20000); Console.WriteLine("Installer exited."); } else { Console.WriteLine("ClickOnce not running"); } //cleanup Console.WriteLine("Removing temporary install files..."); if (File.Exists(Path.GetTempPath() + sFileName)) { File.Delete(Path.GetTempPath() + sFileName); } if (Directory.Exists(sDestDirectory)) { Directory.Delete(sDestDirectory, recursive: true); } Console.WriteLine("Done."); } }