diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:23:48 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:23:48 +0200 |
commit | ee1c8c5c25d25dfa42120125a8a45dc9831ee412 (patch) | |
tree | 67aa287157db954e0cadeee05b4aad331eb2ecf2 /wx+/shell_execute.h | |
parent | 5.13 (diff) | |
download | FreeFileSync-ee1c8c5c25d25dfa42120125a8a45dc9831ee412.tar.gz FreeFileSync-ee1c8c5c25d25dfa42120125a8a45dc9831ee412.tar.bz2 FreeFileSync-ee1c8c5c25d25dfa42120125a8a45dc9831ee412.zip |
5.14
Diffstat (limited to 'wx+/shell_execute.h')
-rw-r--r-- | wx+/shell_execute.h | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/wx+/shell_execute.h b/wx+/shell_execute.h index a07f40cb..acf84794 100644 --- a/wx+/shell_execute.h +++ b/wx+/shell_execute.h @@ -8,19 +8,21 @@ #define EXECUTE_HEADER_23482134578134134 #include <zen/zstring.h> +#include <zen/scope_guard.h> +#include <zen/i18n.h> +#include <zen/utf.h> #include <wx/msgdlg.h> #ifdef FFS_WIN #include <zen/last_error.h> -#include <zen/string_tools.h> -#include <zen/i18n.h> +//#include <zen/string_tools.h> #include <zen/win.h> //includes "windows.h" -//#include <zen/scope_guard.h> #elif defined FFS_LINUX || defined FFS_MAC -#include <stdlib.h> -#include <wx/utils.h> -#include <wx/log.h> +#include <zen/thread.h> +#include <stdlib.h> //::system() +//#include <wx/utils.h> +//#include <wx/log.h> #endif @@ -28,14 +30,14 @@ namespace zen { //launch commandline and report errors via popup dialog //windows: COM needs to be initialized before calling this function! -namespace -{ enum ExecutionType { EXEC_TYPE_SYNC, EXEC_TYPE_ASYNC }; +namespace +{ void shellExecute(const Zstring& command, ExecutionType type = EXEC_TYPE_ASYNC) { #ifdef FFS_WIN @@ -78,32 +80,30 @@ void shellExecute(const Zstring& command, ExecutionType type = EXEC_TYPE_ASYNC) if (execInfo.hProcess) { + ZEN_ON_SCOPE_EXIT(::CloseHandle(execInfo.hProcess)); + if (type == EXEC_TYPE_SYNC) ::WaitForSingleObject(execInfo.hProcess, INFINITE); - ::CloseHandle(execInfo.hProcess); } #elif defined FFS_LINUX || defined FFS_MAC + /* + we cannot use wxExecute due to various issues: + - screws up encoding on OS X for non-ASCII characters + - does not provide any reasonable error information + - uses a zero-sized dummy window as a hack to keep focus which leaves a useless empty icon in ALT-TAB list + */ + if (type == EXEC_TYPE_SYNC) { //Posix::system - execute a shell command int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect... if (rv == -1 || WEXITSTATUS(rv) == 127) //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)" - { wxMessageBox(_("Invalid command line:") + L"\n" + utfCvrtTo<wxString>(command)); - return; - } } else - { - // ! unfortunately it seems there is no way on Linux to get a failure notification for calling an invalid command line asynchronously ! - - //by default wxExecute uses a zero sized dummy window as a hack to keep focus which leaves a useless empty icon in ALT-TAB list - //=> use wxEXEC_NODISABLE and roll our own window disabler! (see comment in app.cpp: void *wxGUIAppTraits::BeforeChildWaitLoop()) - wxWindowDisabler dummy; //disables all top level windows - wxExecute(utfCvrtTo<wxString>(command), wxEXEC_ASYNC | wxEXEC_NODISABLE); - wxLog::FlushActive(); //show wxWidgets error messages (if any) - } + async([=] { /*int rv = */ ::system(command.c_str()); }); + //unfortunately we are not allowed to show a wxMessageBox from a worker thread #endif } } |