From 9994e0bcbc14fdfbd46f57d3b04d5aad087f8c36 Mon Sep 17 00:00:00 2001
From: David Kocik <kocikdav@gmail.com>
Date: Mon, 1 Nov 2021 12:18:17 +0100
Subject: [PATCH] Start updater during start of prusaslicer.

---
 src/PrusaSlicer.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp
index 41d5231f1..17a59d04a 100644
--- a/src/PrusaSlicer.cpp
+++ b/src/PrusaSlicer.cpp
@@ -677,6 +677,45 @@ 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 (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
+           std::string args = dir_entry.path().string();
+           args += " /silent";
+
+           // additional information
+           STARTUPINFOA 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
+           CreateProcessA(NULL,   // the path
+               const_cast<char*>(args.c_str()),  // 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;