MUTILS_API const QString& temp_folder(void);
//Process Utils
- MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true);
+ MUTILS_API void init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir = true, const QString &extraPath = QString());
//Random
MUTILS_API void seed_rand(void);
MUTILS_API bool wow64fsredir_disable(void *oldValue);
MUTILS_API bool wow64fsredir_revert (void *oldValue);
+ //Environment variables
+ MUTILS_API QString get_envvar(const QString &name);
+ MUTILS_API bool set_envvar(const QString &name, const QString &value);
+
//Check if debugger is present
MUTILS_API void check_debugger(void);
// PROCESS UTILS
///////////////////////////////////////////////////////////////////////////////
-void MUtils::init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir)
+static void prependToPath(QProcessEnvironment &env, const QString &value)
+{
+ const QLatin1String PATH = QLatin1String("PATH");
+ const QString path = env.value(PATH, QString()).trimmed();
+ env.insert(PATH, path.isEmpty() ? value : QString("%1;%2").arg(value, path));
+}
+
+void MUtils::init_process(QProcess &process, const QString &wokringDir, const bool bReplaceTempDir, const QString &extraPath)
{
//Environment variable names
static const char *const s_envvar_names_temp[] =
}
//Setup PATH variable
- const QString path = env.value("PATH", QString()).trimmed();
- env.insert("PATH", path.isEmpty() ? tempDir : QString("%1;%2").arg(tempDir, path));
+ prependToPath(env, tempDir);
+ if (!extraPath.isEmpty())
+ {
+ prependToPath(env, QDir::toNativeSeparators(extraPath));
+ }
//Setup QPorcess object
process.setWorkingDirectory(wokringDir);
// DEBUGGER CHECK
///////////////////////////////////////////////////////////////////////////////
+QString MUtils::OS::get_envvar(const QString &name)
+{
+ wchar_t *buffer = NULL;
+ size_t requiredSize = 0, buffSize = 0;
+ QString result;
+
+ forever
+ {
+ //Adjust the buffer size as required first!
+ if (buffSize < requiredSize)
+ {
+ if (buffer)
+ {
+ _freea(buffer);
+ }
+ if (!(buffer = (wchar_t*)_malloca(sizeof(wchar_t) * requiredSize)))
+ {
+ break; /*out of memory error!*/
+ }
+ buffSize = requiredSize;
+ }
+
+ //Try to fetch the environment variable now
+ const errno_t error = _wgetenv_s(&requiredSize, buffer, buffSize, MUTILS_WCHR(name));
+ if(!error)
+ {
+ if (requiredSize > 0)
+ {
+ result = MUTILS_QSTR(buffer);
+ }
+ break; /*done*/
+ }
+ else if (error != ERANGE)
+ {
+ break; /*somethging else went wrong!*/
+ }
+ }
+
+ if (buffer)
+ {
+ _freea(buffer);
+ buffSize = 0;
+ buffer = NULL;
+ }
+
+ return result;
+}
+
+bool MUtils::OS::set_envvar(const QString &name, const QString &value)
+{
+ if (!_wputenv_s(MUTILS_WCHR(name), MUTILS_WCHR(value)))
+ {
+ return true;
+ }
+ return false;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// DEBUGGER CHECK
+///////////////////////////////////////////////////////////////////////////////
+
#if (!(MUTILS_DEBUG))
static __forceinline bool is_debugger_present(void)
{