зеркало из https://github.com/mozilla/gecko-dev.git
Improvements to GetWindowsFolder. bug 104962, r=dveditz@netscape.com, sr=darin@netscape.com
This commit is contained in:
Родитель
768a355fc3
Коммит
cf7a0ceb11
|
@ -174,43 +174,23 @@ static char* MakeUpperCase(char* aPath)
|
|||
static void GetWindowsFolder(int folder, nsFileSpec& outDirectory)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
LPMALLOC pMalloc = NULL;
|
||||
LPSTR pBuffer = NULL;
|
||||
LPITEMIDLIST pItemIDList = NULL;
|
||||
int len;
|
||||
|
||||
// Get the shell's allocator.
|
||||
if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
|
||||
TCHAR path[MAX_PATH+1];
|
||||
HRESULT result = SHGetSpecialFolderPath(NULL, path, folder, true);
|
||||
|
||||
if (!SUCCEEDED(result))
|
||||
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
|
||||
len = PL_strlen(pBuffer);
|
||||
pBuffer[len] = '\\';
|
||||
pBuffer[len + 1] = '\0';
|
||||
int len = PL_strlen(path);
|
||||
if (len>1 && path[len-1] != '\\')
|
||||
{
|
||||
path[len] = '\\';
|
||||
path[len + 1] = '\0';
|
||||
}
|
||||
|
||||
// Assign the directory
|
||||
outDirectory = pBuffer;
|
||||
outDirectory = path;
|
||||
|
||||
Clean:
|
||||
// Clean up.
|
||||
if (pItemIDList)
|
||||
pMalloc->Free(pItemIDList);
|
||||
if (pBuffer)
|
||||
pMalloc->Free(pBuffer);
|
||||
|
||||
pMalloc->Release();
|
||||
} // GetWindowsFolder
|
||||
#endif // XP_WIN
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче