Skip to content

Commit

Permalink
KDESKTOP-1130 - Run installer using WinApi function
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementKunz committed Oct 22, 2024
1 parent f255061 commit e29772c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
31 changes: 31 additions & 0 deletions src/libcommonserver/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,37 @@ bool Utility::longPath(const SyncPath &shortPathIn, SyncPath &longPathOut, bool

return true;
}

bool Utility::runDetachedProcess(std::wstring cmd) {
PROCESS_INFORMATION pinfo;
STARTUPINFOW startupInfo = {sizeof(STARTUPINFO),
0,
0,
0,
(ulong) CW_USEDEFAULT,
(ulong) CW_USEDEFAULT,
(ulong) CW_USEDEFAULT,
(ulong) CW_USEDEFAULT,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0};
bool success = success = CreateProcess(0, cmd.data(), 0, 0, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_CONSOLE, 0, 0,
&startupInfo, &pinfo);

if (success) {
CloseHandle(pinfo.hThread);
CloseHandle(pinfo.hProcess);
}
return success;
}

#endif


Expand Down
1 change: 1 addition & 0 deletions src/libcommonserver/utility/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ struct COMMONSERVER_EXPORT Utility {
#ifdef _WIN32
static bool fileExists(DWORD dwordError) noexcept;
static bool longPath(const SyncPath &shortPathIn, SyncPath &longPathOut, bool &notFound);
static bool runDetachedProcess(std::wstring cmd);
#endif
static bool checkIfDirEntryIsManaged(std::filesystem::recursive_directory_iterator &dirIt, bool &isManaged, bool &isLink,
IoError &ioError);
Expand Down
10 changes: 3 additions & 7 deletions src/server/updater/windowsupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <QProcess>
#include "windowsupdater.h"
#include "log/log.h"
#include "jobs/network/directdownloadjob.h"
Expand Down Expand Up @@ -48,14 +49,9 @@ void WindowsUpdater::startInstaller() {
setState(UpdateState::DownloadError);
return;
}

LOGW_INFO(Log::instance()->getLogger(), L"Starting updater " << Utility::formatSyncPath(filepath));

auto *updaterThread = new std::jthread([filepath] {
const auto cmd = filepath.string() + " /S /launch";
std::system(cmd.c_str());
});
updaterThread->detach();
auto cmd = filepath.wstring() + L" /S /launch";
Utility::runDetachedProcess(cmd);
}

void WindowsUpdater::downloadUpdate() noexcept {
Expand Down

0 comments on commit e29772c

Please sign in to comment.