mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Clean up temp directory code
This commit is contained in:
@@ -13,8 +13,6 @@ namespace Squirrel.CommandLine
|
||||
{
|
||||
static IFullLogger Log => SquirrelLocator.Current.GetService<ILogManager>().GetLogger(typeof(Program));
|
||||
|
||||
static string TempDir => Utility.GetDefaultTempDirectory(null);
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var commands = new CommandSet {
|
||||
@@ -38,7 +36,7 @@ namespace Squirrel.CommandLine
|
||||
var plistPath = Path.Combine(options.package, "Contents", PlistWriter.PlistFileName);
|
||||
NSDictionary plist = (NSDictionary) PropertyListParser.Parse(plistPath);
|
||||
|
||||
var _ = Utility.GetTempDir(TempDir, out var tmp);
|
||||
var _ = Utility.GetTempDirectory(out var tmp);
|
||||
|
||||
string getpStr(string name)
|
||||
{
|
||||
@@ -63,7 +61,7 @@ namespace Squirrel.CommandLine
|
||||
}
|
||||
|
||||
var rp = new ReleasePackageBuilder(nupkgPath);
|
||||
var newPkgPath = rp.CreateReleasePackage(TempDir, Path.Combine(options.releaseDir, rp.SuggestedReleaseFileName), contentsPostProcessHook: (pkgPath, zpkg) => {
|
||||
var newPkgPath = rp.CreateReleasePackage(Path.Combine(options.releaseDir, rp.SuggestedReleaseFileName), contentsPostProcessHook: (pkgPath, zpkg) => {
|
||||
var nuspecPath = Directory.GetFiles(pkgPath, "*.nuspec", SearchOption.TopDirectoryOnly)
|
||||
.ContextualSingle("package", "*.nuspec", "top level directory");
|
||||
var libDir = Directory.GetDirectories(Path.Combine(pkgPath, "lib"))
|
||||
@@ -82,7 +80,7 @@ namespace Squirrel.CommandLine
|
||||
if (prev != null && !options.noDelta) {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
var dp = deltaBuilder.CreateDeltaPackage(prev, rp,
|
||||
Path.Combine(di.FullName, rp.SuggestedReleaseFileName.Replace("full", "delta")), TempDir);
|
||||
Path.Combine(di.FullName, rp.SuggestedReleaseFileName.Replace("full", "delta")));
|
||||
}
|
||||
|
||||
ReleaseEntry.WriteReleaseFile(previousReleases.Concat(new[] { ReleaseEntry.GenerateFromFile(newPkgPath) }), releaseFilePath);
|
||||
|
||||
@@ -115,9 +115,9 @@ namespace Squirrel.CommandLine
|
||||
return HostWriter.IsBundle(peFile, out var offset) && offset > 0;
|
||||
}
|
||||
|
||||
public static void UpdateSingleFileBundleIcon(string rootTempDir, string sourceFile, string destinationFile, string iconPath)
|
||||
public static void UpdateSingleFileBundleIcon(string sourceFile, string destinationFile, string iconPath)
|
||||
{
|
||||
using var _ = Utility.GetTempDir(rootTempDir, out var tmpdir);
|
||||
using var _ = Utility.GetTempDirectory(out var tmpdir);
|
||||
var sourceName = Path.GetFileNameWithoutExtension(sourceFile);
|
||||
|
||||
// extract Update.exe to tmp dir
|
||||
|
||||
@@ -18,8 +18,6 @@ namespace Squirrel.CommandLine
|
||||
{
|
||||
static IFullLogger Log => SquirrelLocator.Current.GetService<ILogManager>().GetLogger(typeof(Program));
|
||||
|
||||
static string TempDir => Utility.GetDefaultTempDirectory(null);
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
var commands = new CommandSet {
|
||||
@@ -33,7 +31,7 @@ namespace Squirrel.CommandLine
|
||||
|
||||
static void Pack(PackOptions options)
|
||||
{
|
||||
using (Utility.GetTempDir(TempDir, out var tmp)) {
|
||||
using (Utility.GetTempDirectory(out var tmp)) {
|
||||
var nupkgPath = NugetConsole.CreatePackageFromMetadata(
|
||||
tmp, options.packDirectory, options.packId, options.packTitle,
|
||||
options.packAuthors, options.packVersion, options.releaseNotes, options.includePdb);
|
||||
@@ -64,13 +62,13 @@ namespace Squirrel.CommandLine
|
||||
if (requiredFrameworks.Any())
|
||||
Log.Info("Package dependencies (from '--framework' argument) resolved as: " + String.Join(", ", requiredFrameworks.Select(r => r.Id)));
|
||||
|
||||
using var ud = Utility.GetTempDir(TempDir, out var tempDir);
|
||||
using var ud = Utility.GetTempDirectory(out var tempDir);
|
||||
|
||||
// update icon for Update.exe if requested
|
||||
var bundledUpdatePath = HelperExe.UpdatePath;
|
||||
var updatePath = Path.Combine(tempDir, "Update.exe");
|
||||
if (setupIcon != null) {
|
||||
DotnetUtil.UpdateSingleFileBundleIcon(TempDir, bundledUpdatePath, updatePath, setupIcon);
|
||||
DotnetUtil.UpdateSingleFileBundleIcon(bundledUpdatePath, updatePath, setupIcon);
|
||||
} else {
|
||||
File.Copy(bundledUpdatePath, updatePath, true);
|
||||
}
|
||||
@@ -101,7 +99,7 @@ namespace Squirrel.CommandLine
|
||||
Log.Info("Creating release for package: " + file.FullName);
|
||||
|
||||
var rp = new ReleasePackageBuilder(file.FullName);
|
||||
rp.CreateReleasePackage(TempDir, Path.Combine(di.FullName, rp.SuggestedReleaseFileName), contentsPostProcessHook: (pkgPath, zpkg) => {
|
||||
rp.CreateReleasePackage(Path.Combine(di.FullName, rp.SuggestedReleaseFileName), contentsPostProcessHook: (pkgPath, zpkg) => {
|
||||
var nuspecPath = Directory.GetFiles(pkgPath, "*.nuspec", SearchOption.TopDirectoryOnly)
|
||||
.ContextualSingle("package", "*.nuspec", "top level directory");
|
||||
var libDir = Directory.GetDirectories(Path.Combine(pkgPath, "lib"))
|
||||
@@ -241,7 +239,7 @@ namespace Squirrel.CommandLine
|
||||
if (prev != null && generateDeltas) {
|
||||
var deltaBuilder = new DeltaPackageBuilder();
|
||||
var dp = deltaBuilder.CreateDeltaPackage(prev, rp,
|
||||
Path.Combine(di.FullName, rp.SuggestedReleaseFileName.Replace("full", "delta")), TempDir);
|
||||
Path.Combine(di.FullName, rp.SuggestedReleaseFileName.Replace("full", "delta")));
|
||||
processed.Insert(0, dp.InputPackageFile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Squirrel.CommandLine
|
||||
{
|
||||
internal class DeltaPackageBuilder : IEnableLogger
|
||||
{
|
||||
public ReleasePackageBuilder CreateDeltaPackage(ReleasePackageBuilder basePackage, ReleasePackageBuilder newPackage, string outputFile, string tempDirectory)
|
||||
public ReleasePackageBuilder CreateDeltaPackage(ReleasePackageBuilder basePackage, ReleasePackageBuilder newPackage, string outputFile)
|
||||
{
|
||||
Contract.Requires(basePackage != null);
|
||||
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
|
||||
@@ -37,8 +37,8 @@ namespace Squirrel.CommandLine
|
||||
throw new FileNotFoundException("The new package release does not exist", newPackage.ReleasePackageFile);
|
||||
}
|
||||
|
||||
using (Utility.GetTempDir(tempDirectory, out var baseTempPath))
|
||||
using (Utility.GetTempDir(tempDirectory, out var tempPath)) {
|
||||
using (Utility.GetTempDirectory(out var baseTempPath))
|
||||
using (Utility.GetTempDirectory(out var tempPath)) {
|
||||
var baseTempInfo = new DirectoryInfo(baseTempPath);
|
||||
var tempInfo = new DirectoryInfo(tempPath);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Squirrel.CommandLine
|
||||
|
||||
public SemanticVersion Version => ReleaseEntry.ParseEntryFileName(InputPackageFile).Version;
|
||||
|
||||
internal string CreateReleasePackage(string temporaryDirectory, string outputFile, Func<string, string> releaseNotesProcessor = null, Action<string, ZipPackage> contentsPostProcessHook = null)
|
||||
internal string CreateReleasePackage(string outputFile, Func<string, string> releaseNotesProcessor = null, Action<string, ZipPackage> contentsPostProcessHook = null)
|
||||
{
|
||||
Contract.Requires(!String.IsNullOrEmpty(outputFile));
|
||||
releaseNotesProcessor = releaseNotesProcessor ?? (x => (new Markdown()).Transform(x));
|
||||
@@ -97,7 +97,7 @@ namespace Squirrel.CommandLine
|
||||
this.Log().Info("Creating release package: {0} => {1}", InputPackageFile, outputFile);
|
||||
|
||||
|
||||
using (Utility.GetTempDir(temporaryDirectory, out var tempPath)) {
|
||||
using (Utility.GetTempDirectory(out var tempPath)) {
|
||||
var tempDir = new DirectoryInfo(tempPath);
|
||||
|
||||
extractZipWithEscaping(InputPackageFile, tempPath).Wait();
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace Squirrel
|
||||
{
|
||||
public static string RemoveByteOrderMarkerIfPresent(string content)
|
||||
{
|
||||
return string.IsNullOrEmpty(content) ?
|
||||
string.Empty : RemoveByteOrderMarkerIfPresent(Encoding.UTF8.GetBytes(content));
|
||||
return string.IsNullOrEmpty(content)
|
||||
? string.Empty
|
||||
: RemoveByteOrderMarkerIfPresent(Encoding.UTF8.GetBytes(content));
|
||||
}
|
||||
|
||||
public static string RemoveByteOrderMarkerIfPresent(byte[] content)
|
||||
@@ -59,7 +60,7 @@ namespace Squirrel
|
||||
output = content;
|
||||
}
|
||||
|
||||
done:
|
||||
done:
|
||||
if (output.Length > 0) {
|
||||
Buffer.BlockCopy(content, content.Length - output.Length, output, 0, output.Length);
|
||||
}
|
||||
@@ -74,6 +75,7 @@ namespace Squirrel
|
||||
if (success) {
|
||||
retVal = (TEnum) Enum.ToObject(typeof(TEnum), enumValue);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -227,7 +229,6 @@ namespace Squirrel
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static T GetAwaiterResult<T>(this Task<T> task)
|
||||
{
|
||||
return task.ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
@@ -254,25 +255,18 @@ namespace Squirrel
|
||||
}));
|
||||
}
|
||||
|
||||
public static string GetDefaultTempDirectory(string localAppDirectory)
|
||||
public static string GetDefaultTempBaseDirectory()
|
||||
{
|
||||
string tempDir;
|
||||
string tempDir = Environment.GetEnvironmentVariable("CLOWD_SQUIRREL_TEMP");
|
||||
|
||||
if (SquirrelRuntimeInfo.IsOSX) {
|
||||
tempDir = "/tmp/squirrel";
|
||||
} else if (SquirrelRuntimeInfo.IsWindows) {
|
||||
#if DEBUG
|
||||
const string TEMP_ENV_VAR = "CLOWD_SQUIRREL_TEMP_DEBUG";
|
||||
const string TEMP_DIR_NAME = "SquirrelClowdTempDebug";
|
||||
#else
|
||||
const string TEMP_ENV_VAR = "CLOWD_SQUIRREL_TEMP";
|
||||
const string TEMP_DIR_NAME = "SquirrelClowdTemp";
|
||||
#endif
|
||||
|
||||
tempDir = Environment.GetEnvironmentVariable(TEMP_ENV_VAR);
|
||||
tempDir = tempDir ?? Path.Combine(localAppDirectory ?? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), TEMP_DIR_NAME);
|
||||
} else {
|
||||
throw new NotSupportedException();
|
||||
if (tempDir == null) {
|
||||
if (SquirrelRuntimeInfo.IsOSX) {
|
||||
tempDir = "/tmp/squirrel";
|
||||
} else if (SquirrelRuntimeInfo.IsWindows) {
|
||||
tempDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SquirrelClowdTemp");
|
||||
} else {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
var di = new DirectoryInfo(tempDir);
|
||||
@@ -281,34 +275,68 @@ namespace Squirrel
|
||||
return di.FullName;
|
||||
}
|
||||
|
||||
private static string getNextTempName(string tempDir)
|
||||
private static string GetNextTempName(string tempDir)
|
||||
{
|
||||
for (int i = 1; i < 100; i++) {
|
||||
string name = "temp" + i;
|
||||
var target = Path.Combine(tempDir, name);
|
||||
if (!File.Exists(target) && !Directory.Exists(target)) {
|
||||
|
||||
FileSystemInfo info = null;
|
||||
if (Directory.Exists(target)) info = new DirectoryInfo(target);
|
||||
else if (File.Exists(target)) info = new FileInfo(target);
|
||||
|
||||
// this dir/file does not exist, lets use it.
|
||||
if (info == null) {
|
||||
return target;
|
||||
}
|
||||
|
||||
// this dir/file exists, but it is old, let's re-use it.
|
||||
// this shouldn't generally happen, but crashes do exist.
|
||||
if (DateTime.UtcNow - info.LastWriteTimeUtc > TimeSpan.FromDays(7)) {
|
||||
if (DeleteFileOrDirectoryHard(target, false, true)) {
|
||||
// the dir/file was deleted successfully.
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Unable to find free temp path. Has the temp directory exceeded it's maximum number of items?");
|
||||
throw new Exception(
|
||||
"Unable to find free temp path. Has the temp directory exceeded it's maximum number of items?");
|
||||
}
|
||||
|
||||
public static IDisposable GetTempDir(string tempDir, out string newTempDirectory)
|
||||
public static IDisposable GetTempDirectory(out string newTempDirectory)
|
||||
{
|
||||
var disp = GetTempFileName(tempDir, out newTempDirectory);
|
||||
return GetTempDirectory(out newTempDirectory, GetDefaultTempBaseDirectory());
|
||||
}
|
||||
|
||||
public static IDisposable GetTempDirectory(out string newTempDirectory, string rootTempDir)
|
||||
{
|
||||
var disp = GetTempFileName(out newTempDirectory, rootTempDir);
|
||||
Directory.CreateDirectory(newTempDirectory);
|
||||
return disp;
|
||||
}
|
||||
|
||||
public static IDisposable GetTempFileName(string tempDir, out string newTempFile)
|
||||
public static IDisposable GetTempFileName(out string newTempFile)
|
||||
{
|
||||
var path = getNextTempName(tempDir);
|
||||
return GetTempFileName(out newTempFile, GetDefaultTempBaseDirectory());
|
||||
}
|
||||
|
||||
public static IDisposable GetTempFileName(out string newTempFile, string rootTempDir)
|
||||
{
|
||||
var path = GetNextTempName(rootTempDir);
|
||||
newTempFile = path;
|
||||
return Disposable.Create(() => DeleteFileOrDirectoryHard(path, throwOnFailure: false));
|
||||
}
|
||||
|
||||
public static void DeleteFileOrDirectoryHard(string path, bool throwOnFailure = true, bool renameFirst = false)
|
||||
/// <summary>
|
||||
/// Repeatedly tries various methods to delete a file system object. Optionally renames the directory first.
|
||||
/// Optionally ignores errors.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file system entity to delete.</param>
|
||||
/// <param name="throwOnFailure">Whether this function should throw if the delete fails.</param>
|
||||
/// <param name="renameFirst">Try to rename this object first before deleting. Can help prevent partial delete of folders.</param>
|
||||
/// <returns>True if the file system object was deleted, false otherwise.</returns>
|
||||
public static bool DeleteFileOrDirectoryHard(string path, bool throwOnFailure = true, bool renameFirst = false)
|
||||
{
|
||||
Contract.Requires(!String.IsNullOrEmpty(path));
|
||||
Log().Debug("Starting to delete: {0}", path);
|
||||
@@ -323,15 +351,19 @@ namespace Squirrel
|
||||
Directory.Move(path, oldPath);
|
||||
path = oldPath;
|
||||
}
|
||||
|
||||
DeleteFsiTree(new DirectoryInfo(path));
|
||||
} else {
|
||||
if (throwOnFailure)
|
||||
Log().Warn($"Cannot delete '{path}' if it does not exist.");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
Log().ErrorException($"Unable to delete '{path}'", ex);
|
||||
if (throwOnFailure)
|
||||
throw;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,12 +400,13 @@ namespace Squirrel
|
||||
|
||||
// try to remove "ReadOnly" attributes
|
||||
try { fileSystemInfo.Attributes = FileAttributes.Normal; } catch { }
|
||||
|
||||
try { fileSystemInfo.Refresh(); } catch { }
|
||||
|
||||
// use this instead of fsi.Delete() because it is more resilient/aggressive
|
||||
Action deleteMe = fileSystemInfo is DirectoryInfo
|
||||
? () => Directory.Delete(fileSystemInfo.FullName, true)
|
||||
: () => File.Delete(fileSystemInfo.FullName);
|
||||
? () => Directory.Delete(fileSystemInfo.FullName, true)
|
||||
: () => File.Delete(fileSystemInfo.FullName);
|
||||
|
||||
// retry a few times. if a directory in this tree is open in Windows Explorer,
|
||||
// it might be locked for a little while WE cleans up handles
|
||||
@@ -422,7 +455,8 @@ namespace Squirrel
|
||||
|
||||
public static string GetAppUserModelId(string packageId, string exeName)
|
||||
{
|
||||
return String.Format("com.squirrel.{0}.{1}", packageId.Replace(" ", ""), exeName.Replace(".exe", "").Replace(" ", ""));
|
||||
return String.Format("com.squirrel.{0}.{1}", packageId.Replace(" ", ""),
|
||||
exeName.Replace(".exe", "").Replace(" ", ""));
|
||||
}
|
||||
|
||||
public static bool IsHttpUrl(string urlOrPath)
|
||||
@@ -466,6 +500,7 @@ namespace Squirrel
|
||||
}
|
||||
|
||||
readonly static string[] peExtensions = new[] { ".exe", ".dll", ".node" };
|
||||
|
||||
public static bool FileIsLikelyPEImage(string name)
|
||||
{
|
||||
var ext = Path.GetExtension(name);
|
||||
@@ -525,11 +560,13 @@ namespace Squirrel
|
||||
This.ErrorException(message ?? "", ex);
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<T> LogIfThrows<T>(this IFullLogger This, LogLevel level, string message, Func<Task<T>> block)
|
||||
public static async Task<T> LogIfThrows<T>(this IFullLogger This, LogLevel level, string message,
|
||||
Func<Task<T>> block)
|
||||
{
|
||||
try {
|
||||
return await block().ConfigureAwait(false);
|
||||
@@ -548,6 +585,7 @@ namespace Squirrel
|
||||
This.ErrorException(message ?? "", ex);
|
||||
break;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -624,15 +662,18 @@ namespace Squirrel
|
||||
}
|
||||
|
||||
static IFullLogger logger;
|
||||
|
||||
static IFullLogger Log()
|
||||
{
|
||||
return logger ?? (logger = SquirrelLocator.CurrentMutable.GetService<ILogManager>().GetLogger(typeof(Utility)));
|
||||
return logger ??
|
||||
(logger = SquirrelLocator.CurrentMutable.GetService<ILogManager>().GetLogger(typeof(Utility)));
|
||||
}
|
||||
|
||||
public static Guid CreateGuidFromHash(string text)
|
||||
{
|
||||
return CreateGuidFromHash(text, Utility.IsoOidNamespace);
|
||||
}
|
||||
|
||||
public static Guid CreateGuidFromHash(byte[] data)
|
||||
{
|
||||
return CreateGuidFromHash(data, Utility.IsoOidNamespace);
|
||||
@@ -715,7 +756,8 @@ namespace Squirrel
|
||||
var pids = new int[2048];
|
||||
var gch = GCHandle.Alloc(pids, GCHandleType.Pinned);
|
||||
try {
|
||||
if (!NativeMethods.EnumProcesses(gch.AddrOfPinnedObject(), sizeof(int) * pids.Length, out var bytesReturned))
|
||||
if (!NativeMethods.EnumProcesses(gch.AddrOfPinnedObject(), sizeof(int) * pids.Length,
|
||||
out var bytesReturned))
|
||||
throw new Win32Exception("Failed to enumerate processes");
|
||||
|
||||
if (bytesReturned < 1)
|
||||
@@ -747,6 +789,7 @@ namespace Squirrel
|
||||
NativeMethods.CloseHandle(hProcess);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
} finally {
|
||||
gch.Free();
|
||||
@@ -759,7 +802,8 @@ namespace Squirrel
|
||||
? EnumerateProcessesWindows()
|
||||
: Process.GetProcesses().Select(p => (p.MainModule.FileName, p.Id));
|
||||
return allRunningProcesses
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x.ProcessExePath)) // Processes we can't query will have an empty process name
|
||||
.Where(x => !String.IsNullOrWhiteSpace(x
|
||||
.ProcessExePath)) // Processes we can't query will have an empty process name
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -775,7 +819,9 @@ namespace Squirrel
|
||||
EnumerateProcessesInDirectory(directoryToKill)
|
||||
.Where(x => {
|
||||
// Never kill our own EXE
|
||||
if (SquirrelRuntimeInfo.EntryExePath != null && x.ProcessExePath.Equals(SquirrelRuntimeInfo.EntryExePath, StringComparison.OrdinalIgnoreCase)) return false;
|
||||
if (SquirrelRuntimeInfo.EntryExePath != null &&
|
||||
x.ProcessExePath.Equals(SquirrelRuntimeInfo.EntryExePath, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
|
||||
var name = Path.GetFileName(x.ProcessExePath).ToLowerInvariant();
|
||||
if (name == "squirrel.exe" || name == "update.exe") return false;
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace Squirrel
|
||||
// Write the new RELEASES file to a temp file then move it into
|
||||
// place
|
||||
var entries = entriesQueue.ToList();
|
||||
using var _ = Utility.GetTempFileName(releasePackagesDir, out var tempFile);
|
||||
using var _ = Utility.GetTempFileName(out var tempFile);
|
||||
|
||||
using (var of = File.OpenWrite(tempFile)) {
|
||||
if (entries.Count > 0) WriteReleaseFile(entries, of);
|
||||
|
||||
@@ -375,8 +375,8 @@ namespace Squirrel
|
||||
Contract.Requires(deltaPackageZip != null);
|
||||
Contract.Requires(!String.IsNullOrEmpty(outputFile) && !File.Exists(outputFile));
|
||||
|
||||
using (Utility.GetTempDir(_config.TempDir, out var deltaPath))
|
||||
using (Utility.GetTempDir(_config.TempDir, out var workingPath)) {
|
||||
using (Utility.GetTempDirectory(out var deltaPath, _config.TempDir))
|
||||
using (Utility.GetTempDirectory(out var workingPath, _config.TempDir)) {
|
||||
EasyZip.ExtractZipToDirectory(deltaPackageZip, deltaPath);
|
||||
progress(25);
|
||||
|
||||
@@ -438,7 +438,7 @@ namespace Squirrel
|
||||
var inputFile = Path.Combine(deltaPath, relativeFilePath);
|
||||
var finalTarget = Path.Combine(workingDirectory, Regex.Replace(relativeFilePath, @"\.(bs)?diff$", ""));
|
||||
|
||||
using var _d = Utility.GetTempFileName(_config.TempDir, out var tempTargetFile);
|
||||
using var _d = Utility.GetTempFileName(out var tempTargetFile, _config.TempDir);
|
||||
|
||||
// NB: Zero-length diffs indicate the file hasn't actually changed
|
||||
if (new FileInfo(inputFile).Length == 0) {
|
||||
|
||||
@@ -8,20 +8,14 @@ namespace Squirrel.Update
|
||||
{
|
||||
class SetupLogLogger : ILogger
|
||||
{
|
||||
public LogLevel Level { get; set; }
|
||||
public LogLevel Level { get; set; } = LogLevel.Info;
|
||||
|
||||
private readonly NLog.Logger _log;
|
||||
|
||||
public SetupLogLogger(string logDirectory, bool includeActionInLogName, UpdateAction action)
|
||||
public SetupLogLogger(string logDirectory)
|
||||
{
|
||||
string name, archivename;
|
||||
if (includeActionInLogName || action == UpdateAction.Unset) {
|
||||
name = "Squirrel.log";
|
||||
archivename = "Squirrel.archive{###}.log";
|
||||
} else {
|
||||
name = $"Squirrel-{action}.log";
|
||||
archivename = $"Squirrel-{action}.archive{{###}}.log";
|
||||
}
|
||||
var name = "Squirrel.log";
|
||||
var archivename = "Squirrel.archive{###}.log";
|
||||
|
||||
// https://gist.github.com/chrisortman/1092889
|
||||
SimpleConfigurator.ConfigureForTargetLogging(
|
||||
@@ -69,4 +63,4 @@ namespace Squirrel.Update
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,20 @@ namespace Squirrel.Update
|
||||
{
|
||||
class Program : IEnableLogger
|
||||
{
|
||||
static StartupOption opt;
|
||||
static StartupOption _options;
|
||||
static IFullLogger Log => SquirrelLocator.Current.GetService<ILogManager>().GetLogger(typeof(Program));
|
||||
|
||||
[STAThread]
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
try {
|
||||
var logger = new SetupLogLogger(Utility.GetDefaultTempBaseDirectory());
|
||||
SquirrelLocator.CurrentMutable.Register(() => logger, typeof(ILogger));
|
||||
_options = new StartupOption(args);
|
||||
|
||||
|
||||
return main(args);
|
||||
} catch (Exception ex) {
|
||||
// NB: Normally this is a terrible idea but we want to make
|
||||
// sure Setup.exe above us gets the nonzero error code
|
||||
Console.Error.WriteLine(ex);
|
||||
return -1;
|
||||
}
|
||||
@@ -23,10 +26,9 @@ namespace Squirrel.Update
|
||||
|
||||
static int main(string[] args)
|
||||
{
|
||||
|
||||
try {
|
||||
opt = new StartupOption(args);
|
||||
} catch (Exception ex) {
|
||||
var logp = new SetupLogLogger(Utility.GetDefaultTempDirectory(null), false, UpdateAction.Unset) { Level = LogLevel.Info };
|
||||
logp.Write($"Failed to parse command line options. {ex.Message}", LogLevel.Error);
|
||||
throw;
|
||||
}
|
||||
@@ -37,7 +39,7 @@ namespace Squirrel.Update
|
||||
|
||||
var logDir = logToTemp ? Utility.GetDefaultTempDirectory(null) : SquirrelRuntimeInfo.BaseDirectory;
|
||||
|
||||
var logger = new SetupLogLogger(logDir, !logToTemp, opt.updateAction) { Level = LogLevel.Info };
|
||||
var logger = new SetupLogLogger(logDir, !logToTemp, _options.updateAction) { Level = LogLevel.Info };
|
||||
SquirrelLocator.CurrentMutable.Register(() => logger, typeof(SimpleSplat.ILogger));
|
||||
|
||||
try {
|
||||
@@ -53,21 +55,18 @@ namespace Squirrel.Update
|
||||
Log.Info("Starting Squirrel Updater: " + String.Join(" ", args));
|
||||
Log.Info("Updater location is: " + SquirrelRuntimeInfo.EntryExePath);
|
||||
|
||||
Console.WriteLine(opt.updateCurrentApp);
|
||||
Console.WriteLine(opt.updateStagingDir);
|
||||
|
||||
if (opt.updateAction == UpdateAction.Unset) {
|
||||
opt.WriteOptionDescriptions();
|
||||
if (_options.updateAction == UpdateAction.Unset) {
|
||||
_options.WriteOptionDescriptions();
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
switch (opt.updateAction) {
|
||||
|
||||
switch (_options.updateAction) {
|
||||
case UpdateAction.ApplyLatest:
|
||||
break;
|
||||
}
|
||||
|
||||
Log.Info("Finished Squirrel Updater");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ namespace Squirrel.Update
|
||||
{
|
||||
static StartupOption opt;
|
||||
static IFullLogger Log => SquirrelLocator.Current.GetService<ILogManager>().GetLogger(typeof(Program));
|
||||
static string TempDir => Utility.GetDefaultTempDirectory(null);
|
||||
|
||||
[STAThread]
|
||||
public static int Main(string[] args)
|
||||
@@ -42,7 +41,7 @@ namespace Squirrel.Update
|
||||
try {
|
||||
opt = new StartupOption(args);
|
||||
} catch (Exception ex) {
|
||||
var logp = new SetupLogLogger(Utility.GetDefaultTempDirectory(null), false, UpdateAction.Unset) { Level = LogLevel.Info };
|
||||
var logp = new SetupLogLogger(Utility.GetDefaultTempBaseDirectory(), false, UpdateAction.Unset) { Level = LogLevel.Info };
|
||||
logp.Write($"Failed to parse command line options. {ex.Message}", LogLevel.Error);
|
||||
throw;
|
||||
}
|
||||
@@ -54,7 +53,7 @@ namespace Squirrel.Update
|
||||
opt.updateAction == UpdateAction.Setup ||
|
||||
opt.updateAction == UpdateAction.Install;
|
||||
|
||||
var logDir = logToTemp ? Utility.GetDefaultTempDirectory(null) : SquirrelRuntimeInfo.BaseDirectory;
|
||||
var logDir = logToTemp ? Utility.GetDefaultTempBaseDirectory() : SquirrelRuntimeInfo.BaseDirectory;
|
||||
|
||||
var logger = new SetupLogLogger(logDir, !logToTemp, opt.updateAction) { Level = LogLevel.Info };
|
||||
SquirrelLocator.CurrentMutable.Register(() => logger, typeof(SimpleSplat.ILogger));
|
||||
@@ -179,7 +178,7 @@ namespace Squirrel.Update
|
||||
silentInstall = true;
|
||||
}
|
||||
|
||||
using var _t = Utility.GetTempDir(TempDir, out var tempFolder);
|
||||
using var _t = Utility.GetTempDirectory(out var tempFolder);
|
||||
using ISplashWindow splash = new ComposedWindow(appname, silentInstall, zp.SetupIconBytes, zp.SetupSplashBytes);
|
||||
|
||||
// verify that this package can be installed on this cpu architecture
|
||||
@@ -486,7 +485,7 @@ namespace Squirrel.Update
|
||||
|
||||
using var splash = new ComposedWindow(manifest.ProductName, false, null, null);
|
||||
splash.Show();
|
||||
using var _ = Utility.GetTempDir(TempDir, out var tempFolder);
|
||||
using var _ = Utility.GetTempDirectory(out var tempFolder);
|
||||
var success = installMissingRuntimes(splash, missingFrameworks, false, tempFolder).Result;
|
||||
if (!success) return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user