From b8f94c7a7ea6cfa82f8783d5e85b5af171bba929 Mon Sep 17 00:00:00 2001 From: israpps <57065102+israpps@users.noreply.github.com> Date: Fri, 24 May 2024 10:56:19 -0300 Subject: [PATCH] forbid multiple instances of program creating file `multi_instance.opt` can be used to block this feature. yet its not intended for normal users. --- HDL-Batch-installer-SRC/HDL_Batch_installerApp.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/HDL-Batch-installer-SRC/HDL_Batch_installerApp.cpp b/HDL-Batch-installer-SRC/HDL_Batch_installerApp.cpp index 12ff4cb..57e03a2 100644 --- a/HDL-Batch-installer-SRC/HDL_Batch_installerApp.cpp +++ b/HDL-Batch-installer-SRC/HDL_Batch_installerApp.cpp @@ -8,6 +8,8 @@ **************************************************************/ #include "HDL_Batch_installerApp.h" #include "flags.h" +#include + //(*AppHeaders #include "HDL_Batch_installerMain.h" #include @@ -19,6 +21,17 @@ IMPLEMENT_APP(HDL_Batch_installerApp); wxString Get_env(wxString ENV); bool HDL_Batch_installerApp::OnInit() { + + wxSingleInstanceChecker* instance_chk = new wxSingleInstanceChecker; + if (instance_chk->IsAnotherRunning() && (!wxFileExists("Common\\multi_instance.opt")) ) + { + wxLogError(_("Another program instance is already running, aborting.")); + + delete instance_chk; // OnExit() won't be called if we return false + instance_chk = nullptr; + + return false; + } bool first_time = false; const wxString DOWNLOAD_COMMAND = "Common\\wget -q --show-progress https://github.com/israpps/HDL-Batch-installer/raw/main/svr/_ICN.7z -O Common\\_ICN.7z", EXTRACTION_COMMAND = "Common\\7z.exe x -oCommon -bso0 -pPDPA -y Common\\_ICN.7z";