Start updater during start of prusaslicer.
Don't search the directory if only verifying that a file exists
is sufficient.
This commit is contained in:
Vojtech Bubnik 2021-11-19 15:48:03 +01:00
parent 56f409921c
commit 6ebee079c9

View File

@ -431,52 +431,46 @@ bool static check_old_linux_datadir(const wxString& app_name) {
static bool run_updater_win() static bool run_updater_win()
{ {
// find updater exe // find updater exe
boost::filesystem::path path_to_binary = boost::dll::program_location(); boost::filesystem::path path_updater = boost::dll::program_location().parent_path() / "prusaslicer-updater.exe";
for (const auto& dir_entry : boost::filesystem::directory_iterator(path_to_binary.parent_path())) { if (boost::filesystem::exists(path_updater)) {
if (dir_entry.path().filename() == "prusaslicer-updater.exe") { // run updater. Original args: /silent -restartapp prusa-slicer.exe -startappfirst
// run updater. Original args: /silent -restartapp prusa-slicer.exe -startappfirst
// Using quoted string as mentioned in CreateProcessW docs. // Using quoted string as mentioned in CreateProcessW docs, silent execution parameter.
std::wstring wcmd = L"\"" + dir_entry.path().wstring() + L"\""; std::wstring wcmd = L"\"" + path_updater.wstring() + L"\" /silent";
wcmd += L" /silent";
// additional information // additional information
STARTUPINFOW si; STARTUPINFOW si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
// set the size of the structures // set the size of the structures
ZeroMemory(&si, sizeof(si)); ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si); si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi)); ZeroMemory(&pi, sizeof(pi));
// start the program up // start the program up
if (CreateProcessW(NULL, // the path if (CreateProcessW(NULL, // the path
wcmd.data(), // Command line wcmd.data(), // Command line
NULL, // Process handle not inheritable NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE FALSE, // Set handle inheritance to FALSE
0, // No creation flags 0, // No creation flags
NULL, // Use parent's environment block NULL, // Use parent's environment block
NULL, // Use parent's starting directory NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure &si, // Pointer to STARTUPINFO structure
&pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses) &pi // Pointer to PROCESS_INFORMATION structure (removed extra parentheses)
)) { )) {
// Close process and thread handles. // Close process and thread handles.
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
return true; return true;
} else { } else {
BOOST_LOG_TRIVIAL(error) << "Failed to start prusaslicer-updater.exe with command " << wcmd; BOOST_LOG_TRIVIAL(error) << "Failed to start prusaslicer-updater.exe with command " << wcmd;
}
break;
} }
} }
return false; return false;
} }
#endif //_WIN32 #endif //_WIN32
wxString file_wildcards(FileType file_type, const std::string &custom_extension) wxString file_wildcards(FileType file_type, const std::string &custom_extension)
{ {
static const std::string defaults[FT_SIZE] = { static const std::string defaults[FT_SIZE] = {
@ -738,14 +732,11 @@ void GUI_App::post_init()
// sees something else than "we want something" on the first start. // sees something else than "we want something" on the first start.
show_send_system_info_dialog_if_needed(); show_send_system_info_dialog_if_needed();
} }
bool updater_running =
#ifdef _WIN32 #ifdef _WIN32
// Run external updater on Windows. // Run external updater on Windows.
run_updater_win(); if (! run_updater_win())
#else // "prusaslicer-updater.exe" was not started, run our own update check.
false;
#endif // _WIN32 #endif // _WIN32
if (!updater_running)
this->preset_updater->slic3r_update_notify(); this->preset_updater->slic3r_update_notify();
}); });
} }