Windows: Fix deleting tempfile for winsparkle dll.

Trying to delete the temp file for the winsparkle dll after unloading
the dll would still produce an access denied error, presumably because
for whatever reason not all resources used by the dll were freed.

Instead of trying to immediately delete the file, start an asynchronous
cmd.exe process to sleep for 2 seconds and delete the file. This gives
the app time to exit, after which the file can be deleted.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2020-02-24 13:17:32 +00:00
parent 89d378eb71
commit 0e8e46f0b7
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,7 @@
#include <string>
#include <stdexcept>
#include <wx/utils.h>
#include "wxvbam.h"
#include "winsparkle-wrapper.h"
#include "wx/msw/private.h"
@ -47,7 +49,17 @@ WinSparkleDllWrapper::~WinSparkleDllWrapper()
{
delete winsparkle_dll;
wxRemoveFile(temp_file_name);
// Wait for the program to exit and release the DLL before deleting the temp file, otherwise access is denied.
const auto shell_cmd = std::string("ping -n 3 127.0.0.1 > nul&set _file=") + temp_file_name + "&call del %^_file%";
const char* cmd[]{
"cmd.exe",
"/c",
shell_cmd.c_str(),
NULL
};
wxExecute(cmd, wxEXEC_ASYNC | wxEXEC_HIDE_CONSOLE);
}
void win_sparkle_init()