nsDirectoryService
出典: MDC
目次 |
[編集] 要約
XPCOM ディレクトリサービス。このサービスは、OS 固有のマナーで "よく知られた" ディレクトリの場所を返します。例えば、システムの一時ディレクトリやデスクトップディレクトリ、現在の作業ディレクトリなどのパスを提供します。
- ClassID
-
f00152d0-b40b-11d3-8c9c-000064657374 - ContractID
-
@mozilla.org/file/directory_service;1
[編集] サポートされたインタフェース
nsIProperties,
nsIDirectoryService
[編集] コメント
このコンポーネントは、単独で使用するか、XPCOM サービスマネージャを通してアクセスします。
[編集] コード例
#include "nsXPCOM.h"
#include "nsCOMPtr.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIServiceManager.h"
#include "nsIProperties.h"
/**
* Get the location of the system's "temp" directory.
*/
nsresult GetTempDir(nsIFile **aResult)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> svcMgr;
rv = NS_GetServiceManager(getter_AddRefs(svcMgr));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIProperties> directory;
rv = svcMgr->GetServiceByContractID("@mozilla.org/file/directory_service;1",
NS_GET_IID(nsIProperties),
getter_AddRefs(directory));
if (NS_FAILED(rv))
return rv;
rv = directory->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), aResult);
return rv;
}
NS_OS_TEMP_DIR は、他の多くの Directory Service キーと共に、nsDirectoryServiceDefs.h で定義されているので注意してください。
[編集] 参考
Using nsIDirectoryService, nsIProperties::get, nsIDirectoryServiceProvider