Skip to content

Commit

Permalink
shell execute wait for process termination
Browse files Browse the repository at this point in the history
  • Loading branch information
krizzdewizz committed May 2, 2019
1 parent 9be1677 commit 2fe8a89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ This will create a system property named `myprop` with the value `myvalue`.
A previously defined property with the same name will be overwritten.
## Build
- Download Apache Ant
- In `build.xml`, Change paths to mingw and jre to match your environment
- In a shell, call `ant dist` (running Ant task from inside Eclipse did not work)
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- set here the properties specific to the release -->

<property name="VERSION" value="0.9.12"/>
<property name="VERSION" value="0.9.13"/>

<!-- You don't need to modify the properties below -->

Expand Down
25 changes: 23 additions & 2 deletions skeletons/autodownload/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void loadLanguage(string jreMinVersion) {
MSG_ERROR_NO_JAVA = "Java Laufzeit Umgebung konnte nicht gefunden werden. Bitte wenden sie sich an ihren System Administrator.";
MSG_DOWNLOADING_JAVA = "Java runterladen";
MSG_DOWNLOADING_JAVA_WAIT = "Java wird runtergeladen...";
MSG_ERROR_NO_JAVA_FIRST = "Java Laufzeit Umgebung " + jreMinVersion + " oder grösser konnte nicht gefunden werden. Drücken sie OK um mit der Installation zu beginnen.";
MSG_ERROR_NO_JAVA_FIRST = "Java Laufzeit Umgebung " + jreMinVersion + " oder gr�sser konnte nicht gefunden werden. Dr�cken sie OK um mit der Installation zu beginnen.";
APP_TITLE = "Java Laufzeit Umgebung installieren";
}
else {
Expand Down Expand Up @@ -116,6 +116,27 @@ void _debugWaitKey()
DEBUGCONSOLE->waitKey();
}

void execWait(const std::string& file, const std::string& params) {
SHELLEXECUTEINFO lpExecInfo;
lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
lpExecInfo.lpFile = file.c_str();
lpExecInfo.lpVerb = "open";
lpExecInfo.lpParameters = params.c_str();
lpExecInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS;
lpExecInfo.hwnd = NULL;
lpExecInfo.lpDirectory = NULL;
lpExecInfo.nShow = SW_SHOW;
lpExecInfo.hInstApp = (HINSTANCE)SE_ERR_DDEFAIL;
ShellExecuteEx(&lpExecInfo);

// wait until process terminates
if (lpExecInfo.hProcess != NULL)
{
::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
::CloseHandle(lpExecInfo.hProcess);
}
}

string doDownload(string url, string &outParams) {

string firstPrioRedirect = FileUtils::getExecutablePath() + "autodownload.redirect";
Expand Down Expand Up @@ -315,7 +336,7 @@ int WINAPI WinMain(HINSTANCE hThisInstance,
}
else // anything else, we try to open it like a document
{
ShellExecute(0, "open", file.c_str(), adParams.c_str(), "", 0);
execWait(file, adParams);
}
}

Expand Down

0 comments on commit 2fe8a89

Please sign in to comment.