diff --git a/src/Squirrel/UpdateManager.ApplyReleases.cs b/src/Squirrel/UpdateManager.ApplyReleases.cs index 72a3649a3..84d790a3d 100644 --- a/src/Squirrel/UpdateManager.ApplyReleases.cs +++ b/src/Squirrel/UpdateManager.ApplyReleases.cs @@ -299,6 +299,10 @@ Task installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release, target.Create(); + // Create the .not-finished file before extraction is started + var notFinishedFilePath = Path.Combine(target.FullName, ".not-finished"); + File.WriteAllText(notFinishedFilePath, ""); + this.Log().Info("Writing files to app directory: {0}", target.FullName); await ReleasePackage.ExtractZipForInstall( Path.Combine(updateInfo.PackageDirectory, release.Filename), @@ -306,6 +310,11 @@ await ReleasePackage.ExtractZipForInstall( rootAppDirectory, progressCallback).ConfigureAwait(false); + // Delete the .not-finished file after extraction is completed + this.ErrorIfThrows(() => { + File.Delete(notFinishedFilePath); + }, "Couldn't delete file: " + notFinishedFilePath); + return target.FullName; }); } diff --git a/src/StubExecutable/StubExecutable.cpp b/src/StubExecutable/StubExecutable.cpp index a0042646b..64489812e 100644 --- a/src/StubExecutable/StubExecutable.cpp +++ b/src/StubExecutable/StubExecutable.cpp @@ -6,6 +6,12 @@ using namespace std; +bool FileExists(const std::wstring& filePath) +{ + DWORD fileAttributes = GetFileAttributes(filePath.c_str()); + return (fileAttributes != INVALID_FILE_ATTRIBUTES) && !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY); +} + wchar_t* FindRootAppDir() { wchar_t* ourDirectory = new wchar_t[MAX_PATH]; @@ -67,6 +73,13 @@ std::wstring FindLatestAppDir() version::Semver200_version thisVer(s); + // Skip the directory which contains a .not-finished file + std::wstring appFolder = fileInfo.cFileName; + std::wstring dirPath = ourDir.substr(0, ourDir.size() - 5) + appFolder; + if (FileExists(dirPath + L"\\.not-finished")) { + continue; + } + if (thisVer > acc) { acc = thisVer; acc_s = appVer; diff --git a/src/Update/Program.cs b/src/Update/Program.cs index 5413f0aa4..0bc21be89 100644 --- a/src/Update/Program.cs +++ b/src/Update/Program.cs @@ -486,7 +486,7 @@ static void ProcessStart(string exeName, string arguments, bool shouldWait) Utility.AppDirForRelease(appDir, x), Utility.AppDirForVersion(appDir, new SemanticVersion(x.Version.Version.Major, x.Version.Version.Minor, x.Version.Version.Build, "")) }) - .FirstOrDefault(x => Directory.Exists(x)); + .FirstOrDefault(x => Directory.Exists(x) && !File.Exists(Path.Combine(x, ".not-finished"))); // Check for the EXE name they want var targetExe = new FileInfo(Path.Combine(latestAppDir, exeName.Replace("%20", " ")));