From 2ea5e07d6edfdf2aa75eb6404fa2248310ead237 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sat, 20 Nov 2010 03:11:12 +0100 Subject: [PATCH] More carefully check TEMP directory + fix fatal application exit. --- etc/Deployment/_build.bat | 6 ++---- src/Config.h | 2 +- src/Global.cpp | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/etc/Deployment/_build.bat b/etc/Deployment/_build.bat index 2344d19f..757b61eb 100644 --- a/etc/Deployment/_build.bat +++ b/etc/Deployment/_build.bat @@ -16,9 +16,7 @@ if not "%ERRORLEVEL%"=="0" GOTO:EOF echo ---------------------------------------------------------------- set "LAMEXP_ERROR=1" msbuild.exe /property:Configuration=%2 /property:Platform=Win32 /target:Rebuild /verbosity:detailed %1 -if not "%ERRORLEVEL%"=="0" ( - msbuild.exe /property:Configuration=%2 /property:Platform=Win32 /target:Build /verbosity:detailed %1 - if not "%ERRORLEVEL%"=="0" GOTO:EOF -) +msbuild.exe /property:Configuration=%2 /property:Platform=Win32 /target:Build /verbosity:detailed %1 +if not "%ERRORLEVEL%"=="0" GOTO:EOF echo ---------------------------------------------------------------- set "LAMEXP_ERROR=0" diff --git a/src/Config.h b/src/Config.h index 79305c6a..6efa68d8 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 49 +#define VER_LAMEXP_BUILD 50 #define VER_LAMEXP_SUFFIX TechPreview /* diff --git a/src/Global.cpp b/src/Global.cpp index 05a028c4..04e3542c 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -201,7 +201,7 @@ void lamexp_message_handler(QtMsgType type, const char *msg) fflush(stderr); SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_INTENSITY); fprintf(stderr, "\nCRITICAL ERROR !!!\n%s\n\n", msg); - MessageBoxA(NULL, msg, "LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL); + MessageBoxW(NULL, (wchar_t*) QString::fromUtf8(msg).utf16(), L"LameXP - CRITICAL ERROR", MB_ICONERROR | MB_TOPMOST | MB_TASKMODAL); break; case QtWarningMsg: SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY); @@ -219,6 +219,7 @@ void lamexp_message_handler(QtMsgType type, const char *msg) if(type == QtCriticalMsg || type == QtFatalMsg) { + lock.unlock(); FatalAppExit(0, L"The application has encountered a critical error and will exit now!"); TerminateProcess(GetCurrentProcess(), -1); } @@ -538,18 +539,41 @@ const QString &lamexp_temp_folder(void) { if(g_lamexp_temp_folder.isEmpty()) { - QDir tempFolder(QDir::tempPath()); + QDir temp = QDir::temp(); + + if(!temp.exists()) + { + temp.mkpath("."); + if(!temp.exists()) + { + qFatal("The system's temporary directory does not exist:\n%s", temp.canonicalPath().toUtf8().constData()); + return g_lamexp_temp_folder; + } + } + QString uuid = QUuid::createUuid().toString(); - tempFolder.mkdir(uuid); - - if(tempFolder.cd(uuid)) + if(!temp.mkdir(uuid)) { - g_lamexp_temp_folder = tempFolder.canonicalPath(); + qFatal("Temporary directory could not be created:\n%s", QString("%1/%2").arg(temp.canonicalPath(), uuid).toUtf8().constData()); + return g_lamexp_temp_folder; } - else + if(!temp.cd(uuid)) + { + qFatal("Temporary directory could not be entered:\n%s", QString("%1/%2").arg(temp.canonicalPath(), uuid).toUtf8().constData()); + return g_lamexp_temp_folder; + } + + QFile testFile(QString("%1/~test.txt").arg(temp.canonicalPath())); + if(!testFile.open(QIODevice::ReadWrite) || testFile.write("LAMEXP_TEST\n") < 12) { - g_lamexp_temp_folder = QDir::tempPath(); + qFatal("Write access to temporary directory has been denied:\n%s", temp.canonicalPath().toUtf8().constData()); + return g_lamexp_temp_folder; } + + testFile.close(); + QFile::remove(testFile.fileName()); + + g_lamexp_temp_folder = temp.canonicalPath(); } return g_lamexp_temp_folder; -- 2.11.0