diff --git a/src/Squirrel/UpdateManager.ApplyReleases.cs b/src/Squirrel/UpdateManager.ApplyReleases.cs index 43e51c2e0..6649a40bc 100644 --- a/src/Squirrel/UpdateManager.ApplyReleases.cs +++ b/src/Squirrel/UpdateManager.ApplyReleases.cs @@ -308,6 +308,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), @@ -315,6 +319,11 @@ await ReleasePackage.ExtractZipForInstall( rootAppDirectory, progressCallback); + // 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 6299dec57..93100fdfa 100644 --- a/src/StubExecutable/StubExecutable.cpp +++ b/src/StubExecutable/StubExecutable.cpp @@ -8,6 +8,11 @@ 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 +72,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;