diff options
Diffstat (limited to 'lib/common/TemporaryDirectory.h')
-rwxr-xr-x | lib/common/TemporaryDirectory.h | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/lib/common/TemporaryDirectory.h b/lib/common/TemporaryDirectory.h index e683863b..9d52ecd9 100755 --- a/lib/common/TemporaryDirectory.h +++ b/lib/common/TemporaryDirectory.h @@ -12,15 +12,35 @@ #include <string> -#ifdef TEMP_DIRECTORY_NAME - // Prefix name with Box to avoid clashing with OS API names - inline std::string BoxGetTemporaryDirectoryName() +#ifdef WIN32 + #include <windows.h> +#endif + +// Prefix name with Box to avoid clashing with OS API names +std::string BoxGetTemporaryDirectoryName() +{ +#ifdef WIN32 + // http://msdn.microsoft.com/library/default.asp? + // url=/library/en-us/fileio/fs/creating_and_using_a_temporary_file.asp + + DWORD dwRetVal; + char lpPathBuffer[1024]; + DWORD dwBufSize = sizeof(lpPathBuffer); + + // Get the temp path. + dwRetVal = GetTempPath(dwBufSize, // length of the buffer + lpPathBuffer); // buffer for path + if (dwRetVal > dwBufSize) { - return std::string(TEMP_DIRECTORY_NAME); + THROW_EXCEPTION(CommonException, TempDirPathTooLong) } -#else - non-static temporary directory names not supported yet + + return std::string(lpPathBuffer); +#elif defined TEMP_DIRECTORY_NAME + return std::string(TEMP_DIRECTORY_NAME); +#else + #error non-static temporary directory names not supported yet #endif +} #endif // TEMPORARYDIRECTORY__H - |