From 6895e0fde132f672d4a5981faff0f16b373597b3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 3 Nov 2021 11:00:20 +0100 Subject: [PATCH] External updater is only run in GUI mode --- src/PrusaSlicer.cpp | 43 ------------------------------ src/slic3r/GUI/GUI_App.cpp | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 43 deletions(-) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 2b4209576..41d5231f1 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -677,49 +677,6 @@ bool CLI::setup(int argc, char **argv) set_local_dir((path_resources / "localization").string()); set_sys_shapes_dir((path_resources / "shapes").string()); -#ifdef _WIN32 - // find updater exe - for (const auto& dir_entry : boost::filesystem::directory_iterator(path_to_binary.parent_path())) { - if (dir_entry.path().filename() == "prusaslicer-updater.exe") { - // run updater. Original args: /silent -restartapp prusa-slicer.exe -startappfirst - - // Using quoted string as mentioned in CreateProcessW docs. - std::wstring wcmd = L"\"" + dir_entry.path().wstring() + L"\""; - wcmd += L" /silent"; - - - - // additional information - STARTUPINFOW si; - PROCESS_INFORMATION pi; - - // set the size of the structures - ZeroMemory(&si, sizeof(si)); - si.cb = sizeof(si); - ZeroMemory(&pi, sizeof(pi)); - - // start the program up - if (CreateProcessW(NULL, // the path - wcmd.data(), // Command line - NULL, // Process handle not inheritable - NULL, // Thread handle not inheritable - FALSE, // Set handle inheritance to FALSE - 0, // No creation flags - NULL, // Use parent's environment block - NULL, // Use parent's starting directory - &si, // Pointer to STARTUPINFO structure - &pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses) - )) { - // Close process and thread handles. - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - } - break; - } - } -#endif //_WIN32 - - // Parse all command line options into a DynamicConfig. // If any option is unsupported, print usage and abort immediately. t_config_option_keys opt_order; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9e92f1ac9..aae61e8b5 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -83,6 +83,9 @@ #include #endif // _MSW_DARK_MODE #endif +#ifdef _WIN32 +#include +#endif #if ENABLE_THUMBNAIL_GENERATOR_DEBUG #include @@ -424,6 +427,53 @@ bool static check_old_linux_datadir(const wxString& app_name) { #endif +#ifdef _WIN32 +static void run_updater_win() +{ + // find updater exe + boost::filesystem::path path_to_binary = boost::dll::program_location(); + for (const auto& dir_entry : boost::filesystem::directory_iterator(path_to_binary.parent_path())) { + if (dir_entry.path().filename() == "prusaslicer-updater.exe") { + // run updater. Original args: /silent -restartapp prusa-slicer.exe -startappfirst + + // Using quoted string as mentioned in CreateProcessW docs. + std::wstring wcmd = L"\"" + dir_entry.path().wstring() + L"\""; + wcmd += L" /silent"; + + // additional information + STARTUPINFOW si; + PROCESS_INFORMATION pi; + + // set the size of the structures + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + ZeroMemory(&pi, sizeof(pi)); + + // start the program up + if (CreateProcessW(NULL, // the path + wcmd.data(), // Command line + NULL, // Process handle not inheritable + NULL, // Thread handle not inheritable + FALSE, // Set handle inheritance to FALSE + 0, // No creation flags + NULL, // Use parent's environment block + NULL, // Use parent's starting directory + &si, // Pointer to STARTUPINFO structure + &pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses) + )) { + // Close process and thread handles. + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + break; + } + } + return; +} +#endif //_WIN32 + + + wxString file_wildcards(FileType file_type, const std::string &custom_extension) { static const std::string defaults[FT_SIZE] = { @@ -686,6 +736,10 @@ void GUI_App::post_init() // sees something else than "we want something" on the first start. show_send_system_info_dialog_if_needed(); } + #ifdef _WIN32 + // Run external updater on Windows. + run_updater_win(); + #endif // _WIN32 }); }