本文整理汇总了C++中nsCOMPtr::GetLeafName方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCOMPtr::GetLeafName方法的具体用法?C++ nsCOMPtr::GetLeafName怎么用?C++ nsCOMPtr::GetLeafName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCOMPtr
的用法示例。
在下文中一共展示了nsCOMPtr::GetLeafName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FindAddressBooks
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFile *pLoc, nsISupportsArray **ppArray)
{
NS_PRECONDITION(pLoc != nsnull, "null ptr");
NS_PRECONDITION(ppArray != nsnull, "null ptr");
if (!pLoc || !ppArray)
return NS_ERROR_NULL_POINTER;
ClearSampleFile();
*ppArray = nsnull;
bool exists = false;
nsresult rv = pLoc->Exists(&exists);
if (NS_FAILED(rv) || !exists)
return NS_ERROR_FAILURE;
bool isFile = false;
rv = pLoc->IsFile(&isFile);
if (NS_FAILED(rv) || !isFile)
return NS_ERROR_FAILURE;
rv = m_text.DetermineDelim(pLoc);
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Error determining delimitter\n");
return rv;
}
m_haveDelim = true;
m_delim = m_text.GetDelim();
m_fileLoc = do_QueryInterface(pLoc);
/* Build an address book descriptor based on the file passed in! */
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
if (NS_FAILED(rv)) {
IMPORT_LOG0("FAILED to allocate the nsISupportsArray\n");
return rv;
}
nsString name;
m_fileLoc->GetLeafName(name);
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Failed getting leaf name of file\n");
return rv;
}
PRInt32 idx = name.RFindChar('.');
if ((idx != -1) && (idx > 0) && ((name.Length() - idx - 1) < 5)) {
name.SetLength(idx);
}
nsCOMPtr<nsIImportABDescriptor> desc;
nsISupports * pInterface;
nsCOMPtr<nsIImportService> impSvc(do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Failed to obtain the import service\n");
return rv;
}
rv = impSvc->CreateNewABDescriptor(getter_AddRefs(desc));
if (NS_SUCCEEDED(rv)) {
PRInt64 sz = 0;
pLoc->GetFileSize(&sz);
desc->SetPreferredName(name);
desc->SetSize((PRUint32) sz);
desc->SetAbFile(m_fileLoc);
rv = desc->QueryInterface(kISupportsIID, (void **) &pInterface);
array->AppendElement(pInterface);
pInterface->Release();
}
if (NS_FAILED(rv)) {
IMPORT_LOG0("*** Error creating address book descriptor for text import\n");
}
else {
rv = array->QueryInterface(NS_GET_IID(nsISupportsArray), (void **) ppArray);
}
return rv;
}
示例2: while
// Iterates over the files in the "path" directory, and adds subfolders to
// parent for each mailbox file found.
nsresult
nsMsgBrkMBoxStore::AddSubFolders(nsIMsgFolder *parent, nsCOMPtr<nsIFile> &path,
bool deep)
{
nsresult rv;
nsCOMPtr<nsIFile> tmp; // at top level so we can safely assign to path
bool isDirectory;
path->IsDirectory(&isDirectory);
if (!isDirectory)
{
rv = path->Clone(getter_AddRefs(tmp));
path = tmp;
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString leafName;
path->GetLeafName(leafName);
leafName.AppendLiteral(".sbd");
path->SetLeafName(leafName);
path->IsDirectory(&isDirectory);
}
if (!isDirectory)
return NS_OK;
// first find out all the current subfolders and files, before using them
// while creating new subfolders; we don't want to modify and iterate the same
// directory at once.
nsCOMArray<nsIFile> currentDirEntries;
nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator));
NS_ENSURE_SUCCESS(rv, rv);
bool hasMore;
while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) &&
hasMore)
{
nsCOMPtr<nsISupports> aSupport;
directoryEnumerator->GetNext(getter_AddRefs(aSupport));
nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv));
if (currentFile)
currentDirEntries.AppendObject(currentFile);
}
// add the folders
int32_t count = currentDirEntries.Count();
for (int32_t i = 0; i < count; ++i)
{
nsCOMPtr<nsIFile> currentFile(currentDirEntries[i]);
nsAutoString leafName;
currentFile->GetLeafName(leafName);
directoryEnumerator->HasMoreElements(&hasMore);
// here we should handle the case where the current file is a .sbd directory
// w/o a matching folder file, or a directory w/o the name .sbd
if (nsShouldIgnoreFile(leafName))
continue;
nsCOMPtr<nsIMsgFolder> child;
rv = parent->AddSubfolder(leafName, getter_AddRefs(child));
if (child)
{
nsString folderName;
child->GetName(folderName); // try to get it from cache/db
if (folderName.IsEmpty())
child->SetPrettyName(leafName);
if (deep)
{
nsCOMPtr<nsIFile> path;
rv = child->GetFilePath(getter_AddRefs(path));
AddSubFolders(child, path, true);
}
}
}
return rv == NS_MSG_FOLDER_EXISTS ? NS_OK : rv;
}