Checkin based on patches submitted by Michael Lowe - #5473. Adds support for a large number of special windows directories.

This commit is contained in:
mcmullen%netscape.com 1999-04-26 22:20:23 +00:00
Родитель d2d0194c11
Коммит 6d0c689cd2
5 изменённых файлов: 424 добавлений и 35 удалений

Просмотреть файл

@ -60,7 +60,32 @@ class NS_BASE nsSpecialSystemDirectory : public nsFileSpec
, Win_SystemDirectory = 201
, Win_WindowsDirectory = 202
, Win_HomeDirectory = 203
, Win_Desktop = 204
, Win_Programs = 205
, Win_Controls = 206
, Win_Printers = 207
, Win_Personal = 208
, Win_Favorites = 209
, Win_Startup = 210
, Win_Recent = 211
, Win_Sendto = 212
, Win_Bitbucket = 213
, Win_Startmenu = 214
, Win_Desktopdirectory = 215
, Win_Drives = 216
, Win_Network = 217
, Win_Nethood = 218
, Win_Fonts = 219
, Win_Templates = 220
, Win_Common_Startmenu = 221
, Win_Common_Programs = 222
, Win_Common_Startup = 223
, Win_Common_Desktopdirectory = 224
, Win_Appdata = 225
, Win_Printhood = 226
, Unix_LocalDirectory = 301
, Unix_LibDirectory = 302
, Unix_HomeDirectory = 303

Просмотреть файл

@ -117,7 +117,8 @@ LCFLAGS = \
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR)
shell32.lib \
$(LIBNSPR)
!if "$(MOZ_BITS)"=="32" && defined(MOZ_DEBUG) && defined(GLOWCODE)
LLIBS=$(LLIBS) $(GLOWDIR)\glowcode.lib
!endif

Просмотреть файл

@ -32,6 +32,7 @@
#include <Processes.h>
#elif defined(XP_PC)
#include <windows.h>
#include <shlobj.h>
#include <stdlib.h>
#include <stdio.h>
#elif defined(XP_UNIX)
@ -56,8 +57,48 @@ static char* MakeUpperCase(char* aPath)
return aPath;
}
#endif
//----------------------------------------------------------------------------------------
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)))
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';
// Assign the directory
outDirectory = MakeUpperCase(pBuffer);
Clean:
// Clean up.
if (pItemIDList)
pMalloc->Free(pItemIDList);
if (pBuffer)
pMalloc->Free(pBuffer);
} // GetWindowsFolder
#endif // XP_PC
//----------------------------------------------------------------------------------------
static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
@ -65,7 +106,7 @@ static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
{
aFileSpec = ".";
return;
}
} // GetCurrentWorkingDirectory
//----------------------------------------------------------------------------------------
static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
@ -156,7 +197,7 @@ static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
#endif
NS_ERROR("unable to get current process directory");
}
} // GetCurrentProcessDirectory()
//nsSpecialSystemDirectory::nsSpecialSystemDirectory()
//: nsFileSpec(nsnull)
@ -209,20 +250,11 @@ void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirect
case OS_TemporaryDirectory:
#ifdef XP_PC
{
char path[_MAX_PATH];
if ( GetEnvironmentVariable(TEXT("TMP"), path, _MAX_PATH) == 0 )
if (GetEnvironmentVariable(TEXT("TEMP"), path, _MAX_PATH))
{
// still not set!
PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
if (len)
{
strcat( path, "temp" );
}
}
strcat( path, "\\" );
DWORD len = GetTempPath(_MAX_PATH, path);
*this = MakeUpperCase(path);
}
#elif defined(XP_MAC)
*this = kTemporaryFolderType;
@ -318,7 +350,144 @@ void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirect
break;
}
#endif
case Win_HomeDirectory:
{
char path[_MAX_PATH];
if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) >= 0)
{
char temp[_MAX_PATH];
if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
PL_strcatn(path, _MAX_PATH, temp);
PRInt32 len = PL_strlen(path);
// Need enough space to add the trailing backslash
if (len > _MAX_PATH - 2)
break;
path[len] = '\\';
path[len+1] = '\0';
}
*this = MakeUpperCase(path);
break;
}
case Win_Desktop:
{
GetWindowsFolder(CSIDL_DESKTOP, *this);
break;
}
case Win_Programs:
{
GetWindowsFolder(CSIDL_PROGRAMS, *this);
break;
}
case Win_Controls:
{
GetWindowsFolder(CSIDL_CONTROLS, *this);
break;
}
case Win_Printers:
{
GetWindowsFolder(CSIDL_PRINTERS, *this);
break;
}
case Win_Personal:
{
GetWindowsFolder(CSIDL_PERSONAL, *this);
break;
}
case Win_Favorites:
{
GetWindowsFolder(CSIDL_FAVORITES, *this);
break;
}
case Win_Startup:
{
GetWindowsFolder(CSIDL_STARTUP, *this);
break;
}
case Win_Recent:
{
GetWindowsFolder(CSIDL_RECENT, *this);
break;
}
case Win_Sendto:
{
GetWindowsFolder(CSIDL_SENDTO, *this);
break;
}
case Win_Bitbucket:
{
GetWindowsFolder(CSIDL_BITBUCKET, *this);
break;
}
case Win_Startmenu:
{
GetWindowsFolder(CSIDL_STARTMENU, *this);
break;
}
case Win_Desktopdirectory:
{
GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, *this);
break;
}
case Win_Drives:
{
GetWindowsFolder(CSIDL_DRIVES, *this);
break;
}
case Win_Network:
{
GetWindowsFolder(CSIDL_NETWORK, *this);
break;
}
case Win_Nethood:
{
GetWindowsFolder(CSIDL_NETHOOD, *this);
break;
}
case Win_Fonts:
{
GetWindowsFolder(CSIDL_FONTS, *this);
break;
}
case Win_Templates:
{
GetWindowsFolder(CSIDL_TEMPLATES, *this);
break;
}
case Win_Common_Startmenu:
{
GetWindowsFolder(CSIDL_COMMON_STARTMENU, *this);
break;
}
case Win_Common_Programs:
{
GetWindowsFolder(CSIDL_COMMON_PROGRAMS, *this);
break;
}
case Win_Common_Startup:
{
GetWindowsFolder(CSIDL_COMMON_STARTUP, *this);
break;
}
case Win_Common_Desktopdirectory:
{
GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, *this);
break;
}
case Win_Appdata:
{
GetWindowsFolder(CSIDL_APPDATA, *this);
break;
}
case Win_Printhood:
{
GetWindowsFolder(CSIDL_PRINTHOOD, *this);
break;
}
#endif // XP_PC
#ifdef XP_UNIX
case Unix_LocalDirectory:

Просмотреть файл

@ -32,6 +32,7 @@
#include <Processes.h>
#elif defined(XP_PC)
#include <windows.h>
#include <shlobj.h>
#include <stdlib.h>
#include <stdio.h>
#elif defined(XP_UNIX)
@ -56,8 +57,48 @@ static char* MakeUpperCase(char* aPath)
return aPath;
}
#endif
//----------------------------------------------------------------------------------------
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)))
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';
// Assign the directory
outDirectory = MakeUpperCase(pBuffer);
Clean:
// Clean up.
if (pItemIDList)
pMalloc->Free(pItemIDList);
if (pBuffer)
pMalloc->Free(pBuffer);
} // GetWindowsFolder
#endif // XP_PC
//----------------------------------------------------------------------------------------
static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
@ -65,7 +106,7 @@ static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
{
aFileSpec = ".";
return;
}
} // GetCurrentWorkingDirectory
//----------------------------------------------------------------------------------------
static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
@ -156,7 +197,7 @@ static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
#endif
NS_ERROR("unable to get current process directory");
}
} // GetCurrentProcessDirectory()
//nsSpecialSystemDirectory::nsSpecialSystemDirectory()
//: nsFileSpec(nsnull)
@ -209,20 +250,11 @@ void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirect
case OS_TemporaryDirectory:
#ifdef XP_PC
{
char path[_MAX_PATH];
if ( GetEnvironmentVariable(TEXT("TMP"), path, _MAX_PATH) == 0 )
if (GetEnvironmentVariable(TEXT("TEMP"), path, _MAX_PATH))
{
// still not set!
PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
if (len)
{
strcat( path, "temp" );
}
}
strcat( path, "\\" );
DWORD len = GetTempPath(_MAX_PATH, path);
*this = MakeUpperCase(path);
}
#elif defined(XP_MAC)
*this = kTemporaryFolderType;
@ -318,7 +350,144 @@ void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirect
break;
}
#endif
case Win_HomeDirectory:
{
char path[_MAX_PATH];
if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) >= 0)
{
char temp[_MAX_PATH];
if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
PL_strcatn(path, _MAX_PATH, temp);
PRInt32 len = PL_strlen(path);
// Need enough space to add the trailing backslash
if (len > _MAX_PATH - 2)
break;
path[len] = '\\';
path[len+1] = '\0';
}
*this = MakeUpperCase(path);
break;
}
case Win_Desktop:
{
GetWindowsFolder(CSIDL_DESKTOP, *this);
break;
}
case Win_Programs:
{
GetWindowsFolder(CSIDL_PROGRAMS, *this);
break;
}
case Win_Controls:
{
GetWindowsFolder(CSIDL_CONTROLS, *this);
break;
}
case Win_Printers:
{
GetWindowsFolder(CSIDL_PRINTERS, *this);
break;
}
case Win_Personal:
{
GetWindowsFolder(CSIDL_PERSONAL, *this);
break;
}
case Win_Favorites:
{
GetWindowsFolder(CSIDL_FAVORITES, *this);
break;
}
case Win_Startup:
{
GetWindowsFolder(CSIDL_STARTUP, *this);
break;
}
case Win_Recent:
{
GetWindowsFolder(CSIDL_RECENT, *this);
break;
}
case Win_Sendto:
{
GetWindowsFolder(CSIDL_SENDTO, *this);
break;
}
case Win_Bitbucket:
{
GetWindowsFolder(CSIDL_BITBUCKET, *this);
break;
}
case Win_Startmenu:
{
GetWindowsFolder(CSIDL_STARTMENU, *this);
break;
}
case Win_Desktopdirectory:
{
GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, *this);
break;
}
case Win_Drives:
{
GetWindowsFolder(CSIDL_DRIVES, *this);
break;
}
case Win_Network:
{
GetWindowsFolder(CSIDL_NETWORK, *this);
break;
}
case Win_Nethood:
{
GetWindowsFolder(CSIDL_NETHOOD, *this);
break;
}
case Win_Fonts:
{
GetWindowsFolder(CSIDL_FONTS, *this);
break;
}
case Win_Templates:
{
GetWindowsFolder(CSIDL_TEMPLATES, *this);
break;
}
case Win_Common_Startmenu:
{
GetWindowsFolder(CSIDL_COMMON_STARTMENU, *this);
break;
}
case Win_Common_Programs:
{
GetWindowsFolder(CSIDL_COMMON_PROGRAMS, *this);
break;
}
case Win_Common_Startup:
{
GetWindowsFolder(CSIDL_COMMON_STARTUP, *this);
break;
}
case Win_Common_Desktopdirectory:
{
GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, *this);
break;
}
case Win_Appdata:
{
GetWindowsFolder(CSIDL_APPDATA, *this);
break;
}
case Win_Printhood:
{
GetWindowsFolder(CSIDL_PRINTHOOD, *this);
break;
}
#endif // XP_PC
#ifdef XP_UNIX
case Unix_LocalDirectory:

Просмотреть файл

@ -60,7 +60,32 @@ class NS_BASE nsSpecialSystemDirectory : public nsFileSpec
, Win_SystemDirectory = 201
, Win_WindowsDirectory = 202
, Win_HomeDirectory = 203
, Win_Desktop = 204
, Win_Programs = 205
, Win_Controls = 206
, Win_Printers = 207
, Win_Personal = 208
, Win_Favorites = 209
, Win_Startup = 210
, Win_Recent = 211
, Win_Sendto = 212
, Win_Bitbucket = 213
, Win_Startmenu = 214
, Win_Desktopdirectory = 215
, Win_Drives = 216
, Win_Network = 217
, Win_Nethood = 218
, Win_Fonts = 219
, Win_Templates = 220
, Win_Common_Startmenu = 221
, Win_Common_Programs = 222
, Win_Common_Startup = 223
, Win_Common_Desktopdirectory = 224
, Win_Appdata = 225
, Win_Printhood = 226
, Unix_LocalDirectory = 301
, Unix_LibDirectory = 302
, Unix_HomeDirectory = 303