Exemplo n.º 1
0
bool _execUpdater(bool update = true) {
    static const int MaxLen = 65536, MaxArgsCount = 128;

    char path[MaxLen] = {0};
    QByteArray data(QFile::encodeName(cExeDir() + "Updater"));
    memcpy(path, data.constData(), data.size());

    char *args[MaxArgsCount] = {0}, p_noupdate[] = "-noupdate", p_autostart[] = "-autostart", p_debug[] = "-debug", p_tosettings[] = "-tosettings", p_key[] = "-key", p_path[] = "-workpath", p_startintray[] = "-startintray", p_testmode[] = "-testmode";
    char p_datafile[MaxLen] = {0}, p_pathbuf[MaxLen] = {0};
    int argIndex = 0;
    args[argIndex++] = path;
    if (!update) {
        args[argIndex++] = p_noupdate;
        args[argIndex++] = p_tosettings;
    }
    if (cFromAutoStart()) args[argIndex++] = p_autostart;
    if (cDebug()) args[argIndex++] = p_debug;
	if (cStartInTray()) args[argIndex++] = p_startintray;
	if (cTestMode()) args[argIndex++] = p_testmode;
    if (cDataFile() != qsl("data")) {
        QByteArray dataf = QFile::encodeName(cDataFile());
        if (dataf.size() < MaxLen) {
            memcpy(p_datafile, dataf.constData(), dataf.size());
            args[argIndex++] = p_key;
            args[argIndex++] = p_datafile;
        }
    }
    QByteArray pathf = cWorkingDir().toUtf8();
    if (pathf.size() < MaxLen) {
        memcpy(p_pathbuf, pathf.constData(), pathf.size());
        args[argIndex++] = p_path;
        args[argIndex++] = p_pathbuf;
    }

    pid_t pid = fork();
    switch (pid) {
    case -1: return false;
    case 0: execv(path, args); return false;
    }
    return true;
}
Exemplo n.º 2
0
bool Launcher::launchUpdater(UpdaterLaunch action) {
	if (cExeName().isEmpty()) {
		return false;
	}

	const auto operation = (action == UpdaterLaunch::JustRelaunch)
		? QString()
		: (cWriteProtected()
			? qsl("runas")
			: QString());
	const auto binaryPath = (action == UpdaterLaunch::JustRelaunch)
		? (cExeDir() + cExeName())
		: (cWriteProtected()
			? (cWorkingDir() + qsl("tupdates/temp/Updater.exe"))
			: (cExeDir() + qsl("Updater.exe")));

	auto argumentsList = QStringList();
	const auto pushArgument = [&](const QString &argument) {
		argumentsList.push_back(argument.trimmed());
	};
	if (cLaunchMode() == LaunchModeAutoStart) {
		pushArgument(qsl("-autostart"));
	}
	if (Logs::DebugEnabled()) {
		pushArgument(qsl("-debug"));
	}
	if (cStartInTray()) {
		pushArgument(qsl("-startintray"));
	}
	if (cTestMode()) {
		pushArgument(qsl("-testmode"));
	}
#ifndef TDESKTOP_DISABLE_AUTOUPDATE
	if (Core::UpdaterDisabled()) {
		pushArgument(qsl("-externalupdater"));
	}
#endif // !TDESKTOP_DISABLE_AUTOUPDATE
	if (customWorkingDir()) {
		pushArgument(qsl("-workdir"));
		pushArgument('"' + cWorkingDir() + '"');
	}
	if (cDataFile() != qsl("data")) {
		pushArgument(qsl("-key"));
		pushArgument('"' + cDataFile() + '"');
	}

	if (action == UpdaterLaunch::JustRelaunch) {
		pushArgument(qsl("-noupdate"));
		if (cRestartingToSettings()) {
			pushArgument(qsl("-tosettings"));
		}
	} else {
		pushArgument(qsl("-update"));
		pushArgument(qsl("-exename"));
		pushArgument('"' + cExeName() + '"');
		if (cWriteProtected()) {
			pushArgument(qsl("-writeprotected"));
			pushArgument('"' + cExeDir() + '"');
		}
	}
	return launch(operation, binaryPath, argumentsList);
}