Bug 308073. Adding Download folder to directory service. r=timeless
This commit is contained in:
Родитель
0e0c5ab354
Коммит
afe5d8312f
|
@ -124,9 +124,15 @@ typedef BOOL (WINAPI * nsGetSpecialFolderPathA) (HWND hwndOwner,
|
|||
BOOL fCreate);
|
||||
|
||||
|
||||
typedef HRESULT (WINAPI* nsGetKnownFolderPath)(GUID& rfid,
|
||||
DWORD dwFlags,
|
||||
HANDLE hToken,
|
||||
PWSTR *ppszPath);
|
||||
|
||||
static GetSpecialPathProc gGetSpecialPathProc = NULL;
|
||||
static nsGetSpecialFolderPathA gGetSpecialFolderPathA = NULL;
|
||||
static nsGetSpecialFolderPathW gGetSpecialFolderPath = NULL;
|
||||
static nsGetKnownFolderPath gGetKnownFolderPath = NULL;
|
||||
|
||||
static HINSTANCE gShell32DLLInst = NULL;
|
||||
|
||||
|
@ -159,6 +165,9 @@ NS_COM void StartupSpecialSystemDirectory()
|
|||
if (gGetSpecialFolderPathA)
|
||||
gGetSpecialFolderPath = NS_GetSpecialFolderPath;
|
||||
}
|
||||
|
||||
gGetKnownFolderPath = (nsGetKnownFolderPath)
|
||||
GetProcAddress(gShell32DLLInst, "SHGetKnownFolderPath");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -171,12 +180,32 @@ NS_COM void ShutdownSpecialSystemDirectory()
|
|||
FreeLibrary(gShell32DLLInst);
|
||||
gShell32DLLInst = NULL;
|
||||
gGetSpecialFolderPath = NULL;
|
||||
gGetKnownFolderPath = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined (XP_WIN)
|
||||
|
||||
static nsresult GetKnownFolder(GUID* guid, nsILocalFile** aFile)
|
||||
{
|
||||
if (!guid || !gGetKnownFolderPath)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PWSTR path = NULL;
|
||||
gGetKnownFolderPath(*guid, 0, NULL, &path);
|
||||
|
||||
if (!path)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsresult rv = NS_NewLocalFile(nsDependentString(path),
|
||||
PR_TRUE,
|
||||
aFile);
|
||||
|
||||
CoTaskMemFree(path);
|
||||
return rv;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
static nsresult GetWindowsFolder(int folder, nsILocalFile** aFile)
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -525,6 +554,14 @@ GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
|
|||
{
|
||||
return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
|
||||
}
|
||||
|
||||
case Win_Downloads:
|
||||
{
|
||||
// Defined in KnownFolders.h.
|
||||
GUID folderid_downloads = {0x374de290, 0x123f, 0x4565, {0x91, 0x64, 0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b}};
|
||||
return GetKnownFolder(&folderid_downloads, aFile);
|
||||
}
|
||||
|
||||
case Win_Controls:
|
||||
{
|
||||
return GetWindowsFolder(CSIDL_CONTROLS, aFile);
|
||||
|
|
|
@ -109,6 +109,7 @@ enum SystemDirectories {
|
|||
Win_Cookies = 227,
|
||||
Win_LocalAppdata = 228,
|
||||
Win_ProgramFiles = 229,
|
||||
Win_Downloads = 230,
|
||||
|
||||
Unix_LocalDirectory = 301,
|
||||
Unix_LibDirectory = 302,
|
||||
|
|
|
@ -395,6 +395,7 @@ nsIAtom* nsDirectoryService::sAppdata = nsnull;
|
|||
nsIAtom* nsDirectoryService::sLocalAppdata = nsnull;
|
||||
nsIAtom* nsDirectoryService::sPrinthood = nsnull;
|
||||
nsIAtom* nsDirectoryService::sWinCookiesDirectory = nsnull;
|
||||
nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull;
|
||||
#elif defined (XP_UNIX)
|
||||
nsIAtom* nsDirectoryService::sLocalDirectory = nsnull;
|
||||
nsIAtom* nsDirectoryService::sLibDirectory = nsnull;
|
||||
|
@ -501,6 +502,7 @@ static const nsStaticAtom directory_atoms[] = {
|
|||
{ NS_WIN_LOCAL_APPDATA_DIR, &nsDirectoryService::sLocalAppdata },
|
||||
{ NS_WIN_PRINTHOOD, &nsDirectoryService::sPrinthood },
|
||||
{ NS_WIN_COOKIES_DIR, &nsDirectoryService::sWinCookiesDirectory },
|
||||
{ NS_WIN_DEFAULT_DOWNLOAD_DIR, &nsDirectoryService::sDefaultDownloadDirectory },
|
||||
#elif defined (XP_UNIX)
|
||||
{ NS_UNIX_LOCAL_DIR, &nsDirectoryService::sLocalDirectory },
|
||||
{ NS_UNIX_LIB_DIR, &nsDirectoryService::sLibDirectory },
|
||||
|
@ -1163,6 +1165,10 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret
|
|||
{
|
||||
rv = GetSpecialSystemDirectory(Win_Cookies, getter_AddRefs(localFile));
|
||||
}
|
||||
else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory)
|
||||
{
|
||||
rv = GetSpecialSystemDirectory(Win_Downloads, getter_AddRefs(localFile));
|
||||
}
|
||||
#elif defined (XP_UNIX)
|
||||
|
||||
else if (inAtom == nsDirectoryService::sLocalDirectory)
|
||||
|
|
|
@ -156,6 +156,7 @@ public:
|
|||
static nsIAtom *sLocalAppdata;
|
||||
static nsIAtom *sPrinthood;
|
||||
static nsIAtom *sWinCookiesDirectory;
|
||||
static nsIAtom *sDefaultDownloadDirectory;
|
||||
#elif defined (XP_UNIX)
|
||||
static nsIAtom *sLocalDirectory;
|
||||
static nsIAtom *sLibDirectory;
|
||||
|
|
|
@ -181,6 +181,7 @@
|
|||
#define NS_WIN_LOCAL_APPDATA_DIR "LocalAppData"
|
||||
#define NS_WIN_PRINTHOOD "PrntHd"
|
||||
#define NS_WIN_COOKIES_DIR "CookD"
|
||||
#define NS_WIN_DEFAULT_DOWNLOAD_DIR "DfltDwnld"
|
||||
#elif defined (XP_UNIX)
|
||||
#define NS_UNIX_LOCAL_DIR "Locl"
|
||||
#define NS_UNIX_LIB_DIR "LibD"
|
||||
|
|
Загрузка…
Ссылка в новой задаче