Implement FullUninstall

This commit is contained in:
Paul Betts
2014-08-19 12:44:42 -07:00
parent 1948c51a86
commit b384f4bdb1
2 changed files with 28 additions and 12 deletions

View File

@@ -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)

View File

@@ -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);