mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Implement FullUninstall
This commit is contained in:
@@ -42,22 +42,19 @@ namespace Squirrel
|
||||
progress(100);
|
||||
}
|
||||
|
||||
public async Task FullUninstall(Version version = null)
|
||||
public async Task FullUninstall()
|
||||
{
|
||||
version = version ?? new Version(255, 255, 255, 255);
|
||||
this.Log().Info("Uninstalling version '{0}'", version);
|
||||
var currentRelease = getReleases().MaxBy(x => x.Name.ToVersion()).FirstOrDefault();
|
||||
|
||||
// find all the old releases (and this one)
|
||||
var directoriesToDelete = getOldReleases(version)
|
||||
.Concat(new [] { getDirectoryForRelease(version) })
|
||||
.Where(d => d.Exists)
|
||||
.Select(d => d.FullName);
|
||||
if (currentRelease.Exists)
|
||||
{
|
||||
var version = currentRelease.Name.ToVersion();
|
||||
|
||||
await directoriesToDelete.ForEachAsync(x => Utility.DeleteDirectoryWithFallbackToNextReboot(x));
|
||||
|
||||
if (!getReleases().Any()) {
|
||||
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
|
||||
await SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(currentRelease.FullName)
|
||||
.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, String.Format("/squirrel-uninstall {0}", version)), 1);
|
||||
}
|
||||
|
||||
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
|
||||
}
|
||||
|
||||
async Task installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release)
|
||||
|
||||
@@ -14,6 +14,7 @@ using Splat;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Squirrel
|
||||
{
|
||||
@@ -98,6 +99,24 @@ namespace Squirrel
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<int> InvokeProcessAsync(string fileName, string arguments)
|
||||
{
|
||||
var psi = new ProcessStartInfo(fileName, arguments);
|
||||
psi.UseShellExecute = false;
|
||||
psi.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
psi.ErrorDialog = false;
|
||||
|
||||
return InvokeProcessAsync(psi);
|
||||
}
|
||||
|
||||
public static async Task<int> InvokeProcessAsync(ProcessStartInfo psi)
|
||||
{
|
||||
var pi = Process.Start(psi);
|
||||
|
||||
await Task.Run(() => pi.WaitForExit());
|
||||
return pi.ExitCode;
|
||||
}
|
||||
|
||||
public static Task ForEachAsync<T>(this IEnumerable<T> source, Action<T> body, int degreeOfParallelism = 4)
|
||||
{
|
||||
return ForEachAsync(source, x => Task.Run(() => body(x)), degreeOfParallelism);
|
||||
|
||||
Reference in New Issue
Block a user