Adding a way to provide storage card location information for devices. npodb

This commit is contained in:
dougt%meer.net 2006-05-25 17:47:46 +00:00
Родитель 431f4a7635
Коммит 240fcda37d
1 изменённых файлов: 132 добавлений и 1 удалений

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

@ -43,6 +43,20 @@
#include "nsIPrefBranch.h" #include "nsIPrefBranch.h"
#include "nsIPrefService.h" #include "nsIPrefService.h"
#include "nsIDirectoryService.h"
#include "nsIFile.h"
#include "nsILocalFile.h"
#include "nsISimpleEnumerator.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsCategoryManagerUtils.h"
#include "nsCOMArray.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsArrayEnumerator.h"
#include "string.h" #include "string.h"
#include "nsMemory.h" #include "nsMemory.h"
@ -231,10 +245,117 @@ NS_IMETHODIMP nsDeviceSupport::SetShouldCheckDefaultBrowser(PRBool aShouldCheckD
return NS_OK; return NS_OK;
} }
class nsStorageCardDirectoryProvider : public nsIDirectoryServiceProvider2
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDIRECTORYSERVICEPROVIDER
NS_DECL_NSIDIRECTORYSERVICEPROVIDER2
};
NS_IMPL_ISUPPORTS2(nsStorageCardDirectoryProvider,
nsIDirectoryServiceProvider,
nsIDirectoryServiceProvider2)
NS_IMETHODIMP
nsStorageCardDirectoryProvider::GetFile(const char *aKey, PRBool *aPersist, nsIFile* *aResult)
{
*aResult = nsnull;
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsStorageCardDirectoryProvider::GetFiles(const char *aKey, nsISimpleEnumerator* *aResult)
{
nsresult rv;
#ifdef WINCE
#define CF_CARDS_FLAGS (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_TEMPORARY)
if (!strcmp(aKey, "SCDirList"))
{
nsCOMArray<nsIFile> directories;
WIN32_FIND_DATA fd;
HANDLE hCF = FindFirstFileA("\\*",&fd);
if (INVALID_HANDLE_VALUE == hCF) return 0;
do
{
if ((fd.dwFileAttributes & CF_CARDS_FLAGS) == CF_CARDS_FLAGS)
{
nsCOMPtr<nsILocalFile> dir = do_CreateInstance("@mozilla.org/file/local;1", &rv);
dir->InitWithNativePath(NS_LITERAL_CSTRING("\\"));
dir->AppendNative(nsDependentCString(fd.cFileName));
directories.AppendObject(dir);
}
} while (FindNextFileA(hCF,&fd));
FindClose(hCF);
return NS_NewArrayEnumerator(aResult, directories);
}
#endif
return NS_ERROR_FAILURE;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// XPCOM REGISTRATION BELOW // XPCOM REGISTRATION BELOW
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static char const kDirectoryProviderContractID[] = "@mozilla.org/device/directory-provider;1";
static NS_METHOD
RegisterDirectoryProvider(nsIComponentManager* aCompMgr,
nsIFile* aPath, const char *aLoaderStr,
const char *aType,
const nsModuleComponentInfo *aInfo)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID);
if (!catMan)
return NS_ERROR_FAILURE;
rv = catMan->AddCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
"device-directory-provider",
kDirectoryProviderContractID,
PR_TRUE, PR_TRUE, nsnull);
return rv;
}
static NS_METHOD
UnregisterDirectoryProvider(nsIComponentManager* aCompMgr,
nsIFile* aPath, const char *aLoaderStr,
const nsModuleComponentInfo *aInfo)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catMan
(do_GetService(NS_CATEGORYMANAGER_CONTRACTID));
if (!catMan)
return NS_ERROR_FAILURE;
rv = catMan->DeleteCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY,
"device-directory-provider",
PR_TRUE);
return rv;
}
#define NS_STORAGECARDDIRECTORYPROVIDER_CID \
{ 0x268b9c42, 0x86c4, 0x4ab3, { 0x92, 0xbe, 0xfe, 0x3d, 0x5f, 0x23, 0x08, 0x0a } }
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageCardDirectoryProvider)
#define DeviceSupport_CID \ #define DeviceSupport_CID \
{ 0x6b60b326, 0x483e, 0x47d6, {0x82, 0x87, 0x88, 0x1a, 0xd9, 0x51, 0x0c, 0x8f} } { 0x6b60b326, 0x483e, 0x47d6, {0x82, 0x87, 0x88, 0x1a, 0xd9, 0x51, 0x0c, 0x8f} }
@ -248,7 +369,17 @@ static const nsModuleComponentInfo components[] =
DeviceSupport_CID, DeviceSupport_CID,
DeviceSupport_ContractID, DeviceSupport_ContractID,
nsDeviceSupportConstructor, nsDeviceSupportConstructor,
} },
{
"nsStorageCardDirectoryProvider",
NS_STORAGECARDDIRECTORYPROVIDER_CID,
kDirectoryProviderContractID,
nsStorageCardDirectoryProviderConstructor,
// RegisterDirectoryProvider,
// UnregisterDirectoryProvider
}
}; };
NS_IMPL_NSGETMODULE(DeviceSupportModule, components) NS_IMPL_NSGETMODULE(DeviceSupportModule, components)