mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Log way more stuff
This commit is contained in:
@@ -51,6 +51,9 @@ namespace Squirrel
|
||||
var baseTempInfo = new DirectoryInfo(baseTempPath);
|
||||
var tempInfo = new DirectoryInfo(tempPath);
|
||||
|
||||
this.Log().Info("Extracting {0} and {1} into {2}",
|
||||
basePackage.ReleasePackageFile, newPackage.ReleasePackageFile, tempPath);
|
||||
|
||||
using (var zf = new ZipFile(basePackage.ReleasePackageFile)) {
|
||||
zf.ExtractAll(baseTempInfo.FullName);
|
||||
}
|
||||
@@ -133,6 +136,7 @@ namespace Squirrel
|
||||
});
|
||||
|
||||
using (var zf = new ZipFile(outputFile)) {
|
||||
this.Log().Info("Repacking into full package: {0}", outputFile);
|
||||
zf.AddDirectory(workingPath);
|
||||
zf.Save();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Splat;
|
||||
|
||||
namespace Squirrel
|
||||
{
|
||||
@@ -13,18 +14,26 @@ namespace Squirrel
|
||||
Task<byte[]> DownloadUrl(string url);
|
||||
}
|
||||
|
||||
class FileDownloader : IFileDownloader
|
||||
class FileDownloader : IFileDownloader, IEnableLogger
|
||||
{
|
||||
public async Task DownloadFile(string url, string targetFile)
|
||||
public Task DownloadFile(string url, string targetFile)
|
||||
{
|
||||
var wc = new WebClient();
|
||||
await wc.DownloadFileTaskAsync(url, targetFile);
|
||||
|
||||
this.Log().Info("Downloading file: " + url);
|
||||
|
||||
return this.WarnIfThrows(() => wc.DownloadFileTaskAsync(url, targetFile),
|
||||
"Failed downloading URL: " + url);
|
||||
}
|
||||
|
||||
public Task<byte[]> DownloadUrl(string url)
|
||||
{
|
||||
var wc = new WebClient();
|
||||
return wc.DownloadDataTaskAsync(url);
|
||||
|
||||
this.Log().Info("Downloading url: " + url);
|
||||
|
||||
return this.WarnIfThrows(() => wc.DownloadDataTaskAsync(url),
|
||||
"Failed to download url: " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
using Splat;
|
||||
|
||||
namespace Squirrel
|
||||
{
|
||||
public interface IUpdateManager : IDisposable
|
||||
public interface IUpdateManager : IDisposable, IEnableLogger
|
||||
{
|
||||
/// <summary>
|
||||
/// Fetch the remote store for updates and compare against the current
|
||||
@@ -92,9 +93,18 @@ namespace Squirrel
|
||||
{
|
||||
progress = progress ?? (_ => {});
|
||||
|
||||
var updateInfo = await This.CheckForUpdate(false, x => progress(x / 3));
|
||||
await This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33));
|
||||
await This.ApplyReleases(updateInfo, x => progress(x / 3 + 66));
|
||||
This.Log().Info("Starting automatic update");
|
||||
|
||||
var updateInfo = await This.ErrorIfThrows(() => This.CheckForUpdate(false, x => progress(x / 3)),
|
||||
"Failed to check for updates");
|
||||
|
||||
await This.ErrorIfThrows(() =>
|
||||
This.DownloadReleases(updateInfo.ReleasesToApply, x => progress(x / 3 + 33)),
|
||||
"Failed to download updates");
|
||||
|
||||
await This.ErrorIfThrows(() =>
|
||||
This.ApplyReleases(updateInfo, x => progress(x / 3 + 66)),
|
||||
"Failed to apply updates");
|
||||
|
||||
return updateInfo.ReleasesToApply.MaxBy(x => x.Version).LastOrDefault();
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace Squirrel
|
||||
|
||||
// Recursively walk the dependency tree and extract all of the
|
||||
// dependent packages into the a temporary directory
|
||||
this.Log().Info("Creating release package: {0} => {1}", InputPackageFile, outputFile);
|
||||
var dependencies = findAllDependentPackages(
|
||||
package,
|
||||
new LocalPackageRepository(packagesRootDir),
|
||||
@@ -127,10 +128,12 @@ namespace Squirrel
|
||||
zf.ExtractAll(tempPath);
|
||||
}
|
||||
|
||||
this.Log().Info("Extracting dependent packages: [{0}]", String.Join(",", dependencies.Select(x => x.Id)));
|
||||
extractDependentPackages(dependencies, tempDir, targetFramework);
|
||||
|
||||
var specPath = tempDir.GetFiles("*.nuspec").First().FullName;
|
||||
|
||||
this.Log().Info("Removing unnecessary data");
|
||||
removeDependenciesFromPackageSpec(specPath);
|
||||
removeDeveloperDocumentation(tempDir);
|
||||
|
||||
@@ -141,6 +144,7 @@ namespace Squirrel
|
||||
addDeltaFilesToContentTypes(tempDir.FullName);
|
||||
|
||||
using (var zf = new ZipFile(outputFile)) {
|
||||
this.Log().Info("Succeeeded, saving to " + outputFile);
|
||||
zf.AddDirectory(tempPath);
|
||||
zf.Save();
|
||||
}
|
||||
|
||||
@@ -34,21 +34,29 @@ namespace Squirrel
|
||||
progress(10);
|
||||
|
||||
if (release == null) {
|
||||
this.Log().Info("No release to install, running the app");
|
||||
await invokePostInstall(updateInfo.CurrentlyInstalledVersion.Version, true, true);
|
||||
return getDirectoryForRelease(updateInfo.CurrentlyInstalledVersion.Version).FullName;
|
||||
}
|
||||
|
||||
var ret = await installPackageToAppDir(updateInfo, release);
|
||||
var ret = await this.ErrorIfThrows(() => installPackageToAppDir(updateInfo, release),
|
||||
"Failed to install package to app dir");
|
||||
progress(30);
|
||||
|
||||
var currentReleases = await updateLocalReleasesFile();
|
||||
var currentReleases = await this.ErrorIfThrows(() => updateLocalReleasesFile(),
|
||||
"Failed to update local releases file");
|
||||
progress(50);
|
||||
|
||||
var newVersion = currentReleases.MaxBy(x => x.Version).First().Version;
|
||||
await invokePostInstall(newVersion, currentReleases.Count == 1 && !silentInstall, false);
|
||||
await this.ErrorIfThrows(() => invokePostInstall(newVersion, currentReleases.Count == 1 && !silentInstall, false),
|
||||
"Failed to invoke post-install");
|
||||
progress(75);
|
||||
|
||||
await cleanDeadVersions(newVersion);
|
||||
try {
|
||||
await cleanDeadVersions(newVersion);
|
||||
} catch (Exception ex) {
|
||||
this.Log().WarnException("Failed to clean dead versions, continuing anyways", ex);
|
||||
}
|
||||
progress(100);
|
||||
|
||||
return ret;
|
||||
@@ -58,14 +66,20 @@ namespace Squirrel
|
||||
{
|
||||
var currentRelease = getReleases().MaxBy(x => x.Name.ToVersion()).FirstOrDefault();
|
||||
|
||||
this.Log().Info("Starting full uninstall");
|
||||
if (currentRelease.Exists) {
|
||||
var version = currentRelease.Name.ToVersion();
|
||||
|
||||
await SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(currentRelease.FullName)
|
||||
.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, String.Format("--squirrel-uninstall {0}", version)), 1);
|
||||
try {
|
||||
await SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(currentRelease.FullName)
|
||||
.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, String.Format("--squirrel-uninstall {0}", version)), 1);
|
||||
} catch (Exception ex) {
|
||||
this.Log().WarnException("Failed to run pre-uninstall hooks, uninstalling anyways", ex);
|
||||
}
|
||||
}
|
||||
|
||||
await Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory);
|
||||
await this.ErrorIfThrows(() => Utility.DeleteDirectoryWithFallbackToNextReboot(rootAppDirectory),
|
||||
"Failed to delete app directory: " + rootAppDirectory);
|
||||
}
|
||||
|
||||
async Task<string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release)
|
||||
@@ -75,6 +89,7 @@ namespace Squirrel
|
||||
|
||||
// NB: This might happen if we got killed partially through applying the release
|
||||
if (target.Exists) {
|
||||
this.Log().Warn("Found partially applied release folder, killing it: " + target.FullName);
|
||||
await Utility.DeleteDirectory(target.FullName);
|
||||
}
|
||||
|
||||
@@ -95,20 +110,21 @@ namespace Squirrel
|
||||
// NB: Because of the above NB, we cannot use ForEachAsync here, we
|
||||
// have to copy these files in-order. Once we fix assembly resolution,
|
||||
// we can kill both of these NBs.
|
||||
await Task.Run(() => toWrite.ForEach(x => CopyFileToLocation(target, x)));
|
||||
await Task.Run(() => toWrite.ForEach(x => copyFileToLocation(target, x)));
|
||||
|
||||
await pkg.GetContentFiles().ForEachAsync(x => CopyFileToLocation(target, x));
|
||||
await pkg.GetContentFiles().ForEachAsync(x => copyFileToLocation(target, x));
|
||||
|
||||
var newCurrentVersion = updateInfo.FutureReleaseEntry.Version;
|
||||
|
||||
// Perform post-install; clean up the previous version by asking it
|
||||
// which shortcuts to install, and nuking them. Then, run the app's
|
||||
// post install and set up shortcuts.
|
||||
runPostInstallAndCleanup(newCurrentVersion, updateInfo.IsBootstrapping);
|
||||
this.ErrorIfThrows(() => runPostInstallAndCleanup(newCurrentVersion, updateInfo.IsBootstrapping));
|
||||
|
||||
return target.FullName;
|
||||
}
|
||||
|
||||
void CopyFileToLocation(FileSystemInfo target, IPackageFile x)
|
||||
void copyFileToLocation(FileSystemInfo target, IPackageFile x)
|
||||
{
|
||||
var targetPath = Path.Combine(target.FullName, x.EffectivePath);
|
||||
|
||||
@@ -118,10 +134,12 @@ namespace Squirrel
|
||||
var dir = new DirectoryInfo(Path.GetDirectoryName(targetPath));
|
||||
if (!dir.Exists) dir.Create();
|
||||
|
||||
using (var inf = x.GetStream())
|
||||
using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
|
||||
inf.CopyTo(of);
|
||||
}
|
||||
this.ErrorIfThrows(() => {
|
||||
using (var inf = x.GetStream())
|
||||
using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
|
||||
inf.CopyTo(of);
|
||||
}
|
||||
}, "Failed to write file: " + target.FullName);
|
||||
}
|
||||
|
||||
void runPostInstallAndCleanup(Version newCurrentVersion, bool isBootstrapping)
|
||||
@@ -208,6 +226,8 @@ namespace Squirrel
|
||||
|
||||
var squirrelApps = SquirrelAwareExecutableDetector.GetAllSquirrelAwareApps(targetDir.FullName);
|
||||
|
||||
this.Log().Info("Squirrel Enabled Apps: [{0}]", String.Join(",", squirrelApps));
|
||||
|
||||
// For each app, run the install command in-order and wait
|
||||
if (!firstRunOnly) await squirrelApps.ForEachAsync(exe => Utility.InvokeProcessAsync(exe, args), 1 /* at a time */);
|
||||
|
||||
@@ -378,4 +398,4 @@ namespace Squirrel
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,9 @@ namespace Squirrel.Update
|
||||
public static async Task Install(bool silentInstall, string sourceDirectory = null)
|
||||
{
|
||||
sourceDirectory = sourceDirectory ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
var releasesPath = Path.Combine(sourceDirectory, "RELEASES");
|
||||
var releasesPath = Path.Combine(sourceDirectory, "RELEASES");
|
||||
|
||||
LogHost.Default.Info("Starting install, writing to {0}", sourceDirectory);
|
||||
|
||||
if (!File.Exists(releasesPath)) {
|
||||
var nupkgs = (new DirectoryInfo(sourceDirectory)).GetFiles()
|
||||
|
||||
Reference in New Issue
Block a user