private static void SelfCleanUp(string tempFolder) { // Delete the updater EXE and the temp folder Log("Removing updater and temp folder... {0}", tempFolder); try { if (PlatformCheck.CurrentlyRunningInWindows()) { var info = new ProcessStartInfo { UseShellExecute = false, Arguments = string.Format(@"/C ping 1.1.1.1 -n 1 -w 3000 > Nul & echo Y|del ""{0}\*.*"" & rmdir ""{0}""", tempFolder), WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, FileName = "cmd.exe" }; ExtendendStartProcess.Start(info); } else { var info = new ProcessStartInfo { UseShellExecute = false, Arguments = string.Format(@"-c ""sleep 5s && rm -rf {0}""", tempFolder), WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true, FileName = "bash" }; Process.Start(info); } } catch { /* ignore exceptions thrown while trying to clean up */ } }
/// <summary> /// Defaut ctor /// </summary> private UpdateManager() { IsWorking = false; State = UpdateProcessState.NotChecked; UpdatesToApply = new List <IUpdateTask>(); ApplicationPath = Process.GetCurrentProcess().MainModule.FileName; UpdateFeedReader = new NauXmlFeedReader(); Logger = new Logger(); if (PlatformCheck.CurrentlyRunningInWindows()) { Config = new NauConfigurations { TempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()), UpdateProcessName = "NAppUpdateProcess", UpdateExecutableName = "foo.exe", // Naming it updater.exe seem to trigger the UAC, and we don't want that }; } else { Config = new NauConfigurations { TempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()), UpdateProcessName = "NAppUpdateProcess", UpdateExecutableName = "foo", // Naming it updater.exe seem to trigger the UAC, and we don't want that }; } // Need to do this manually here because the BackupFolder property is protected using the static instance, which we are // in the middle of creating string backupPath = Path.Combine(Path.GetDirectoryName(ApplicationPath) ?? string.Empty, "Backup" + DateTime.Now.Ticks); backupPath = backupPath.TrimEnd(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); Config._backupFolder = Path.IsPathRooted(backupPath) ? backupPath : Path.Combine(Config.TempFolder, backupPath); }