/// <summary> /// Installs the newest SUAG or SUAC executable. This does not update an app package /// </summary> public static void InstallNewest() { string tmpFile = Path.GetTempFileName(); //Download the newest version using (var wc = new WebClient()) { wc.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; wc.DownloadFile(ThisApp.SourceExe, tmpFile); } try { File.Delete(Path2.SelfUpdatingExe); } catch { } File.Move(tmpFile, Path2.SelfUpdatingExe); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { RegistryEntries.RegisterSUAInfo(); } else { Process.Start("chmod", $"+x \"{Path2.SelfUpdatingExe}\""); } }
public static async Task UninstallAsync(string id, IProgress <ProgressData> progress = null) { if (Debugger.IsAttached) { return; } #if DEBUG return; #endif if (Environment.OSVersion.Platform == PlatformID.Win32NT) { progress?.Report(new ProgressData("Deleting registry entries")); RegistryEntries.UnregisterUninstallInfo(id); //Delete the desktop shortcut try { XmlData data = await XmlData.ReadAsync(Path2.LocalManifest(id)).ConfigureAwait(false); progress?.Report(new ProgressData("Deleting shortcuts")); string shortcut = Path2.DesktopLinkPath(data.Name); if (File.Exists(shortcut)) { File.Delete(shortcut); } //Delete the Pinned To Taskbar shortcut shortcut = Path2.TaskBarShortcutPath(data.Name); if (File.Exists(shortcut)) { File.Delete(shortcut); } //Delete the Pinned To Start Menu shortcut //Delete Start Menu Shortcut } catch { } } await Task.Run(() => { //Delete files DirectoryInfo rootDir = new DirectoryInfo(Path2.InstalledDirectory(id)); if (rootDir.Exists) { var files = new List <FileSystemInfo>(rootDir.GetFileSystemInfos("*", SearchOption.AllDirectories)); files.Sort((x, y) => x.FullName.CompareTo(y.FullName)); files.Reverse(); double total = files.Count; double cur = 0; int lastPerc = 0; progress?.Report(new ProgressData("Deleting files", 0)); foreach (var file in files) { try { file.Delete(); } catch { NativeMethods.DeleteAfterReboot(file.FullName); } int perc = Math.Min(99, (int)Math.Floor((++cur / total) * 100)); if (perc != lastPerc) { lastPerc = perc; progress?.Report(new ProgressData("Deleting files", perc)); } } } string xmlPath = Path2.LocalManifest(id); if (File.Exists(xmlPath)) { File.Delete(xmlPath); } }); progress?.Report(new ProgressData("Uninstall Complete", 100, true)); }
internal static async Task <InstallResult> InstallAsync(string url, IProgress <ProgressData> progress, bool createShortcuts) { InstallResult ret = new InstallResult { Success = true }; if (Debugger.IsAttached) { return(ret); } #if DEBUG return(ret); #endif try { //Read the package progress?.Report(new ProgressData("Reading package")); XmlData serverData = await XmlData.ReadAsync(url).ConfigureAwait(false); ret.Id = serverData.Id; ret.Version = serverData.Version; //If installed, check installed version try { var localVersion = GetInstalledVersion(ret.Id); if (localVersion >= serverData.Version) { return(ret); } } catch { } //Install! progress?.Report(new ProgressData($"Preparing to install v{serverData.Version}")); //Unzip from the web string status = $"Installing v{serverData.Version}"; string zipSrc = Path2.DepoPackage(serverData); if (StreamHelper.IsWebUrl(zipSrc)) { using var response = await StreamHelper.GetWebResponseAsync(zipSrc).ConfigureAwait(false); using var source = response.GetResponseStream(); await UnzipPackage(source, Path2.InstalledDirectory(serverData.Id), status, progress).ConfigureAwait(false); } else { using var source = StreamHelper.OpenAsyncRead(zipSrc); await UnzipPackage(source, Path2.InstalledDirectory(serverData.Id), status, progress).ConfigureAwait(false); } if (Environment.OSVersion.Platform == PlatformID.Win32NT) { RegistryEntries.RegisterUninstallInfo(serverData); //Create desktop shortcut string shortcutFile = Path2.DesktopLinkPath(serverData.Name); if (createShortcuts || File.Exists(shortcutFile)) { Shortcut.Create(shortcutFile, Path2.InstalledExe(serverData)); } } else { Process.Start("chmod", $"+x \"{Path2.InstalledExe(serverData)}\""); } //Success serverData.Save(Path2.LocalManifest(serverData.Id)); progress?.Report(new ProgressData("Done", 100, true)); } catch (Exception ex) { ret.Success = false; ret.Error = ex; } return(ret); }