diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2018-06-04 10:25:12 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2018-06-04 10:25:12 +0300 |
commit | 56f0c8fe934b4b750a7c64ac3e827bd44f300538 (patch) | |
tree | 789d43bc2b2e08930e9857a1a284402cc9808d8e /xs/src/slic3r/GUI/GUI.cpp | |
parent | dab2652cb522bd53c5786c259c94983bde9ded89 (diff) | |
parent | 4df0b94b7949c05d372bee215655521b51361eca (diff) |
Merge branch 'master' of https://github.com/prusa3d/Slic3r
Diffstat (limited to 'xs/src/slic3r/GUI/GUI.cpp')
-rw-r--r-- | xs/src/slic3r/GUI/GUI.cpp | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 7e274354d..d42fd3538 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -443,8 +443,13 @@ void config_wizard(int reason) if (! check_unsaved_changes()) return; - ConfigWizard wizard(nullptr, static_cast<ConfigWizard::RunReason>(reason)); - wizard.run(g_PresetBundle, g_PresetUpdater); + try { + ConfigWizard wizard(nullptr, static_cast<ConfigWizard::RunReason>(reason)); + wizard.run(g_PresetBundle, g_PresetUpdater); + } + catch (const std::exception &e) { + show_error(nullptr, e.what()); + } // Load the currently selected preset into the GUI, update the preset selection box. for (Tab *tab : g_tabs_list) @@ -929,34 +934,51 @@ void about() } void desktop_open_datadir_folder() -{ +{ // Execute command to open a file explorer, platform dependent. - std::string cmd = + // FIXME: The const_casts aren't needed in wxWidgets 3.1, remove them when we upgrade. + + const auto path = data_dir(); #ifdef _WIN32 - "explorer " + const auto widepath = wxString::FromUTF8(path.data()); + const wchar_t *argv[] = { L"explorer", widepath.GetData(), nullptr }; + ::wxExecute(const_cast<wchar_t**>(argv), wxEXEC_ASYNC, nullptr); #elif __APPLE__ - "open " + const char *argv[] = { "open", path.data(), nullptr }; + ::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr); #else - "xdg-open " -#endif - ; - // Escape the path, platform dependent. - std::string path = data_dir(); -#ifdef _WIN32 - // Enclose the path into double quotes on Windows. A quote character is forbidden in file names, - // therefore it does not need to be escaped. - cmd += '"'; - cmd += path; - cmd += '"'; -#else - // Enclose the path into single quotes on Unix / OSX. All single quote characters need to be escaped - // inside a file name. - cmd += '\''; - boost::replace_all(path, "'", "\\'"); - cmd += path; - cmd += '\''; + const char *argv[] = { "xdg-open", path.data(), nullptr }; + + // Check if we're running in an AppImage container, if so, we need to remove AppImage's env vars, + // because they may mess up the environment expected by the file manager. + // Mostly this is about LD_LIBRARY_PATH, but we remove a few more too for good measure. + if (wxGetEnv("APPIMAGE", nullptr)) { + // We're running from AppImage + wxEnvVariableHashMap env_vars; + wxGetEnvMap(&env_vars); + + env_vars.erase("APPIMAGE"); + env_vars.erase("APPDIR"); + env_vars.erase("LD_LIBRARY_PATH"); + env_vars.erase("LD_PRELOAD"); + env_vars.erase("UNION_PRELOAD"); + + wxExecuteEnv exec_env; + exec_env.env = std::move(env_vars); + + wxString owd; + if (wxGetEnv("OWD", &owd)) { + // This is the original work directory from which the AppImage image was run, + // set it as CWD for the child process: + exec_env.cwd = std::move(owd); + } + + ::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, &exec_env); + } else { + // Looks like we're NOT running from AppImage, we'll make no changes to the environment. + ::wxExecute(const_cast<char**>(argv), wxEXEC_ASYNC, nullptr, nullptr); + } #endif - ::wxExecute(wxString::FromUTF8(cmd.c_str()), wxEXEC_ASYNC, nullptr); } } } |