From c3a7afa5093f3611d1f019aeaebc996b45421f8a Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 4 Jan 2015 19:44:25 +0100 Subject: [PATCH] Change current directory to root directory *before* trying to clean up the TEMP folder. This avoids the TEMP directory from being removed, because it is the current directory. --- src/Global.cpp | 1 + src/Startup.cpp | 38 ++++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Global.cpp b/src/Global.cpp index 613482b..fb5295a 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -157,6 +157,7 @@ static void temp_folder_cleanup_helper(const QString &tempPath) bool okay = false; for(int i = 0; i < 32; i++) { + QDir::setCurrent(QDir::rootPath()); if(MUtils::remove_directory(tempPath, true)) { okay = true; diff --git a/src/Startup.cpp b/src/Startup.cpp index 980b65f..d1bea27 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -180,6 +180,27 @@ int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entr static QMutex g_init_lock; static const char *const g_imageformats[] = {"bmp", "png", "jpg", "gif", "ico", "xpm", "svg", NULL}; +static QString getExecutableName(int &argc, char **argv) +{ + if(argc >= 1) + { + const char *argv0 = argv[0]; + if(const char *const ptr = strrchr(argv0, '/')) + { + argv0 = ptr + 1; + } + if(const char *const ptr = strrchr(argv0, '\\')) + { + argv0 = ptr + 1; + } + if(strlen(argv0) > 1) + { + QString::fromLatin1(argv0); + } + } + return QLatin1String("Program.exe"); +} + QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString &appName) { QMutexLocker lock(&g_init_lock); @@ -193,22 +214,7 @@ QApplication *MUtils::Startup::create_qt(int &argc, char **argv, const QString & } //Extract executable name from argv[] array - QString executableName = QLatin1String("LameXP.exe"); - if(arguments.count() > 0) - { - static const char *delimiters = "\\/:?"; - executableName = arguments[0].trimmed(); - for(int i = 0; delimiters[i]; i++) - { - int temp = executableName.lastIndexOf(QChar(delimiters[i])); - if(temp >= 0) executableName = executableName.mid(temp + 1); - } - executableName = executableName.trimmed(); - if(executableName.isEmpty()) - { - executableName = QLatin1String("LameXP.exe"); - } - } + const QString executableName = getExecutableName(argc, argv); //Check Qt version #ifdef QT_BUILD_KEY