From f3ae451b32236dc66994408f9b5719681be6dd7c Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Mon, 25 Nov 2013 02:20:44 +0100 Subject: [PATCH] Make sure the TEMP path is *not* replaced when running the web-update tool, as this will prevent the updater from working correctly. --- src/Config.h | 2 +- src/Dialog_Update.cpp | 3 ++- src/Global.h | 2 +- src/Global_Utils.cpp | 45 +++++++++++++++++++++++++------------------ 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/Config.h b/src/Config.h index 893420ef..d64ae536 100644 --- a/src/Config.h +++ b/src/Config.h @@ -35,7 +35,7 @@ #define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 8 -#define VER_LAMEXP_BUILD 1472 +#define VER_LAMEXP_BUILD 1473 #define VER_LAMEXP_CONFG 1348 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index 312c4a27..05f48499 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -387,7 +387,7 @@ void UpdateDialog::applyUpdate(void) QStringList args; QEventLoop loop; - lamexp_init_process(process, QFileInfo(m_binaryUpdater).absolutePath()); + lamexp_init_process(process, QFileInfo(m_binaryUpdater).absolutePath(), false); connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit())); connect(&process, SIGNAL(finished(int,QProcess::ExitStatus)), &loop, SLOT(quit())); @@ -409,6 +409,7 @@ void UpdateDialog::applyUpdate(void) m_updaterProcess = lamexp_process_id(&process); loop.exec(QEventLoop::ExcludeUserInputEvents); } + m_updaterProcess = NULL; QApplication::restoreOverrideCursor(); diff --git a/src/Global.h b/src/Global.h index b271e8bb..b1e4bd4c 100644 --- a/src/Global.h +++ b/src/Global.h @@ -175,7 +175,7 @@ const lamexp_os_version_t &lamexp_get_os_version(void); void lamexp_init_console(const QStringList &argv); void lamexp_init_error_handlers(void); int lamexp_init_ipc(void); -void lamexp_init_process(QProcess &process, const QString &wokringDir); +void lamexp_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true); bool lamexp_init_qt(int argc, char* argv[]); bool lamexp_install_translator(const QString &language); bool lamexp_install_translator_from_file(const QString &qmFile); diff --git a/src/Global_Utils.cpp b/src/Global_Utils.cpp index 499f9149..b38b0b12 100644 --- a/src/Global_Utils.cpp +++ b/src/Global_Utils.cpp @@ -192,38 +192,45 @@ void lamexp_temp_folder_clear(void) /* * Setup QPorcess object */ -void lamexp_init_process(QProcess &process, const QString &wokringDir) +void lamexp_init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir) { //Environment variable names - static const char *const s_envvar_names[] = + static const char *const s_envvar_names_temp[] = + { + "TEMP", "TMP", "TMPDIR", "HOME", "USERPROFILE", "HOMEPATH", NULL + }; + static const char *const s_envvar_names_remove[] = { "WGETRC", "SYSTEM_WGETRC", "HTTP_PROXY", "FTP_PROXY", "NO_PROXY", "GNUPGHOME", "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MESSAGES", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LANG", NULL }; - const QString tempDir = QDir::toNativeSeparators(lamexp_temp_folder2()); - + //Initialize environment QProcessEnvironment env = process.processEnvironment(); if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment(); - //Setup TEMP directory - env.insert("TEMP", tempDir); - env.insert("TMP", tempDir); - env.insert("TMPDIR", tempDir); - env.insert("HOME", tempDir); - env.insert("USERPROFILE", tempDir); - env.insert("HOMEPATH", tempDir); + //Clean a number of enviroment variables that might affect our tools + for(size_t i = 0; s_envvar_names_remove[i]; i++) + { + env.remove(QString::fromLatin1(s_envvar_names_remove[i])); + env.remove(QString::fromLatin1(s_envvar_names_remove[i]).toLower()); + } + + const QString tempDir = QDir::toNativeSeparators(lamexp_temp_folder2()); + + //Replace TEMP directory in environment + if(bReplaceTempDir) + { + for(size_t i = 0; s_envvar_names_temp[i]; i++) + { + env.insert(s_envvar_names_temp[i], tempDir); + } + } //Setup PATH variable - const QString path = env.value("PATH", QString()); + const QString path = env.value("PATH", QString()).trimmed(); env.insert("PATH", path.isEmpty() ? tempDir : QString("%1;%2").arg(tempDir, path)); - - //Clean a number of enviroment variables that might affect our tools - for(size_t i = 0; s_envvar_names[i]; i++) - { - env.remove(QString::fromLatin1(s_envvar_names[i])); - env.remove(QString::fromLatin1(s_envvar_names[i]).toLower()); - } + //Setup QPorcess object process.setWorkingDirectory(wokringDir); process.setProcessChannelMode(QProcess::MergedChannels); process.setReadChannel(QProcess::StandardOutput);