From 8b43f9100e3a12a5d100a264b893deebb5c9cacf Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Wed, 17 Oct 2001 19:38:58 +0000 Subject: [PATCH] reverting to the old way to get windows directories since the function I am using does not work on windows systems without IE4. a=nhotta@netscape.com --- xpcom/io/nsSpecialSystemDirectory.cpp | 42 ++++++++++++++++++++------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/xpcom/io/nsSpecialSystemDirectory.cpp b/xpcom/io/nsSpecialSystemDirectory.cpp index b0db25f127c8..71358fe9b20f 100644 --- a/xpcom/io/nsSpecialSystemDirectory.cpp +++ b/xpcom/io/nsSpecialSystemDirectory.cpp @@ -174,23 +174,43 @@ static char* MakeUpperCase(char* aPath) static void GetWindowsFolder(int folder, nsFileSpec& outDirectory) //---------------------------------------------------------------------------------------- { - TCHAR path[MAX_PATH+1]; - HRESULT result = SHGetSpecialFolderPath(NULL, path, folder, true); - - if (!SUCCEEDED(result)) + LPMALLOC pMalloc = NULL; + LPSTR pBuffer = NULL; + LPITEMIDLIST pItemIDList = NULL; + int len; + + // Get the shell's allocator. + if (!SUCCEEDED(SHGetMalloc(&pMalloc))) return; + // Allocate a buffer + if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL) + return; + + // Get the PIDL for the folder. + if (!SUCCEEDED(SHGetSpecialFolderLocation( + NULL, folder, &pItemIDList))) + goto Clean; + + if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer))) + goto Clean; + // Append the trailing slash - int len = PL_strlen(path); - if (len>1 && path[len-1] != '\\') - { - path[len] = '\\'; - path[len + 1] = '\0'; - } + len = PL_strlen(pBuffer); + pBuffer[len] = '\\'; + pBuffer[len + 1] = '\0'; // Assign the directory - outDirectory = path; + outDirectory = pBuffer; +Clean: + // Clean up. + if (pItemIDList) + pMalloc->Free(pItemIDList); + if (pBuffer) + pMalloc->Free(pBuffer); + + pMalloc->Release(); } // GetWindowsFolder #endif // XP_WIN