typedef pair<CString, CString> StringPair;
typedef CList<StringPair, StringPair&> StrPairList;
BOOL getFtpEntry(StrPairList& entryList)
{
CoInitalize(NULL)
CComPtr<IMSAdminBase> pIMetaDB;
HRESULT hRes = CoCreateInstance
(
CLSID_MSAdminBase
, NULL
, CLSCTX_ALL
, IID_IMSAdminBase
, (void **)&pIMetaDB
);
if ( hRes < 0 ) {
return FALSE;
}
METADATA_HANDLE metaHandel;
hRes = pIMetaDB->OpenKey
(
METADATA_MASTER_ROOT_HANDLE
, (LPWSTR)(L"/LM/MSFTPSVC")
, METADATA_PERMISSION_READ
, e_MaxTime
, &metaHandel
);
if ( hRes < 0 ) {
return FALSE;
}
WCHAR site[METADATA_MAX_NAME_LEN], siteName[METADATA_MAX_NAME_LEN];
memset(&site, 0x0, sizeof(site));
memset(&siteName, 0x0, sizeof(siteName));
DWORD num = 0;
for (;;) {
hRes = pIMetaDB->EnumKeys(metaHandel, L"/", site, num);
if ( hRes < 0 ) {
break;
}
num++;
if (_wcsicmp(site, L"1") != 0) {
continue;
}
memset(&siteName, 0x0, sizeof(siteName));
wcscpy(siteName, L"/");
wcscat(siteName, site);
wcscat(siteName, L"/ROOT");
DWORD len = 0;
WCHAR data[METADATA_MAX_NAME_LEN];
memset(&data, 0x0, sizeof(data));
METADATA_RECORD record;
memset(&record, 0x0, sizeof(record));
record.dwMDIdentifier = MD_VR_PATH;
record.dwMDAttributes = METADATA_INHERIT;
record.dwMDUserType = IIS_MD_UT_FILE;
record.dwMDDataType = STRING_METADATA;
record.dwMDDataTag = 0;
record.dwMDDataLen = sizeof(data);
record.pbMDData = (PBYTE)data;
hRes = pIMetaDB->GetData(metaHandel, siteName, &record, &len);
if (hRes < 0) {
pIMetaDB->CloseKey(metaHandel);
return FALSE;
}
CString path(data);
StringPair pair(_T("/"), path);
entryList.insert(pair);
browseVDir(pIMetaDB, metaHandel, siteName, NULL, entryList);
}
pIMetaDB->CloseKey(metaHandel);
UnCoInitialize();
return TRUE;
}
static BOOL browseVDir(
IMSAdminBase* pIMetaDB,
METADATA_HANDLE metaHandel,
const WCHAR* subkey,
const TCHAR* dir,
StrPairList& flist
)
{
ASSERT(pIMetaDB != NULL);
DWORD index = 0;
WCHAR subdir[METADATA_MAX_NAME_LEN], fullPath[METADATA_MAX_NAME_LEN];
memset(&subdir, 0x0, sizeof(subdir));
memset(&fullPath, 0x0, sizeof(fullPath));
for (;;) {
HRESULT hRes = pIMetaDB->EnumKeys(metaHandel, subkey, subdir, index);
if ( hRes < 0) {
break;
}
memset(&fullPath, 0x0, sizeof(fullPath));
wcscpy(fullPath, subkey);
wcscat(fullPath, L"/");
wcscat(fullPath, subdir);
DWORD len = 0;
WCHAR data[METADATA_MAX_NAME_LEN];
memset(&data, 0x0, sizeof(data));
METADATA_RECORD record;
memset(&record, 0x0, sizeof(record));
record.dwMDIdentifier = MD_VR_PATH;
record.dwMDAttributes = METADATA_INHERIT;
record.dwMDUserType = IIS_MD_UT_FILE;
record.dwMDDataType = STRING_METADATA;
record.dwMDDataTag = 0;
record.dwMDDataLen = sizeof(data);
record.pbMDData = (PBYTE)data;
hRes = pIMetaDB->GetData(metaHandel, fullPath, &record, &len);
if ( hRes < 0 ) {
return FALSE;
}
CString path(data);
CString fl(subdir);
fl = CString(dir) + _T("/") + fl;
StringPair pair(fl, path);
flist.insert(pair);
browseVDir(pIMetaDB, metaHandel, fullPath, fl, flist);
index++;
}
return TRUE;
}
|