Get ApplyReleases building

This commit is contained in:
Paul Betts
2014-08-08 12:58:18 +02:00
parent 9c50cbc7f4
commit 0763761c57
2 changed files with 77 additions and 49 deletions

View File

@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NuGet;
using Splat;
namespace Squirrel
@@ -11,6 +15,16 @@ namespace Squirrel
{
class ApplyReleases : IEnableLogger
{
// TODO: Kill this entire concept
readonly FrameworkVersion appFrameworkVersion = FrameworkVersion.Net45;
readonly string rootAppDirectory;
public ApplyReleases(string rootAppDirectory)
{
this.rootAppDirectory = rootAppDirectory;
}
public async Task ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null)
{
progress = progress ?? (_ => { });
@@ -28,6 +42,25 @@ namespace Squirrel
progress(100);
}
public async Task FullUninstall(Version version = null)
{
version = version ?? new Version(255, 255, 255, 255);
this.Log().Info("Uninstalling version '{0}'", version);
// find all the old releases (and this one)
var directoriesToDelete = getOldReleases(version)
.Concat(new [] { getDirectoryForRelease(version) })
.Where(d => d.Exists)
.Select(d => d.FullName);
await directoriesToDelete.ForEachAsync(x => Utility.DeleteDirectoryWithFallbackToNextReboot(x));
if (!getReleases().Any()) {
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
}
}
async Task installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release)
{
var pkg = new ZipPackage(Path.Combine(updateInfo.PackageDirectory, release.Filename));
@@ -278,7 +311,34 @@ namespace Squirrel
async Task updateLocalReleasesFile()
{
await Task.Run(() => ReleaseEntry.BuildReleasesFile(PackageDirectory));
await Task.Run(() => ReleaseEntry.BuildReleasesFile(Utility.PackageDirectoryForAppDir(rootAppDirectory)));
}
IEnumerable<DirectoryInfo> getReleases()
{
var rootDirectory = new DirectoryInfo(rootAppDirectory);
if (!rootDirectory.Exists) return Enumerable.Empty<DirectoryInfo>();
return rootDirectory.GetDirectories()
.Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase));
}
IEnumerable<DirectoryInfo> getOldReleases(Version version)
{
return getReleases()
.Where(x => x.Name.ToVersion() < version)
.ToArray();
}
static string getLocalAppDataDirectory()
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
DirectoryInfo getDirectoryForRelease(Version releaseVersion)
{
return new DirectoryInfo(Path.Combine(rootAppDirectory, "app-" + releaseVersion));
}
}
}

View File

@@ -41,63 +41,36 @@ namespace Squirrel
this.urlDownloader = urlDownloader ?? new FileDownloader();
}
public Task<UpdateInfo> CheckForUpdate(bool ignoreDeltaUpdates, Action<int> progress = null)
public async Task<UpdateInfo> CheckForUpdate(bool ignoreDeltaUpdates, Action<int> progress = null)
{
var checkForUpdate = new CheckForUpdates(rootAppDirectory);
return checkForUpdate.CheckForUpdate(Utility.LocalReleaseFileForAppDir(rootAppDirectory), updateUrlOrPath, ignoreDeltaUpdates, progress, urlDownloader);
await acquireUpdateLock();
return await checkForUpdate.CheckForUpdate(Utility.LocalReleaseFileForAppDir(rootAppDirectory), updateUrlOrPath, ignoreDeltaUpdates, progress, urlDownloader);
}
public Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null)
public async Task DownloadReleases(IEnumerable<ReleaseEntry> releasesToDownload, Action<int> progress = null)
{
var downloadReleases = new DownloadReleases(rootAppDirectory);
return downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader);
await acquireUpdateLock();
await downloadReleases.DownloadReleases(updateUrlOrPath, releasesToDownload, progress, urlDownloader);
}
public Task ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null)
public async Task ApplyReleases(UpdateInfo updateInfo, Action<int> progress = null)
{
throw new NotImplementedException();
var applyReleases = new ApplyReleases(rootAppDirectory);
await acquireUpdateLock();
await applyReleases.ApplyReleases(updateInfo, progress);
}
public async Task FullUninstall()
{
var applyReleases = new ApplyReleases(rootAppDirectory);
await acquireUpdateLock();
await fullUninstall();
}
IEnumerable<DirectoryInfo> getReleases()
{
var rootDirectory = new DirectoryInfo(rootAppDirectory);
if (!rootDirectory.Exists) return Enumerable.Empty<DirectoryInfo>();
return rootDirectory.GetDirectories()
.Where(x => x.Name.StartsWith("app-", StringComparison.InvariantCultureIgnoreCase));
}
IEnumerable<DirectoryInfo> getOldReleases(Version version)
{
return getReleases()
.Where(x => x.Name.ToVersion() < version)
.ToArray();
}
async Task fullUninstall(Version version = null)
{
version = version ?? new Version(255, 255, 255, 255);
this.Log().Info("Uninstalling version '{0}'", version);
// find all the old releases (and this one)
var directoriesToDelete = getOldReleases(version)
.Concat(new [] { getDirectoryForRelease(version) })
.Where(d => d.Exists)
.Select(d => d.FullName);
await directoriesToDelete.ForEachAsync(x => Utility.DeleteDirectoryWithFallbackToNextReboot(x));
if (!getReleases().Any()) {
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
}
await applyReleases.FullUninstall();
}
public void Dispose()
@@ -148,10 +121,5 @@ namespace Squirrel
{
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
}
DirectoryInfo getDirectoryForRelease(Version releaseVersion)
{
return new DirectoryInfo(Path.Combine(rootAppDirectory, "app-" + releaseVersion));
}
}
}