本文整理汇总了C++中nsCOMPtr::AppendNative方法的典型用法代码示例。如果您正苦于以下问题:C++ nsCOMPtr::AppendNative方法的具体用法?C++ nsCOMPtr::AppendNative怎么用?C++ nsCOMPtr::AppendNative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsCOMPtr
的用法示例。
在下文中一共展示了nsCOMPtr::AppendNative方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_SUCCEEDED
static PRBool
CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
nsCOMPtr<nsIFile> &updater)
{
// Copy the updater application from the GRE and the updater ini from the app
#if defined(XP_MACOSX)
if (!CopyFileIntoUpdateDir(greDir, kUpdaterApp, updateDir))
return PR_FALSE;
#else
if (!CopyFileIntoUpdateDir(greDir, kUpdaterBin, updateDir))
return PR_FALSE;
#endif
CopyFileIntoUpdateDir(appDir, kUpdaterINI, updateDir);
#if defined(XP_UNIX) && !defined(XP_MACOSX)
nsCOMPtr<nsIFile> iconDir;
appDir->Clone(getter_AddRefs(iconDir));
iconDir->AppendNative(NS_LITERAL_CSTRING("icons"));
if (!CopyFileIntoUpdateDir(iconDir, kUpdaterPNG, updateDir))
return PR_FALSE;
#endif
// Finally, return the location of the updater binary.
nsresult rv = updateDir->Clone(getter_AddRefs(updater));
if (NS_FAILED(rv))
return PR_FALSE;
#if defined(XP_MACOSX)
rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterApp));
rv |= updater->AppendNative(NS_LITERAL_CSTRING("Contents"));
rv |= updater->AppendNative(NS_LITERAL_CSTRING("MacOS"));
if (NS_FAILED(rv))
return PR_FALSE;
#endif
rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterBin));
return NS_SUCCEEDED(rv);
}
示例2: GetOutputIconPath
// (static) Obtains the ICO file for the favicon at page aFaviconPageURI
// If successful, the file path on disk is in the format:
// <ProfLDS>\jumpListCache\<hash(aFaviconPageURI)>.ico
nsresult FaviconHelper::GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
nsCOMPtr<nsIFile> &aICOFile,
bool aURLShortcut)
{
// Hash the input URI and replace any / with _
nsAutoCString inputURIHash;
nsCOMPtr<nsICryptoHash> cryptoHash;
nsresult rv = HashURI(cryptoHash, aFaviconPageURI,
inputURIHash);
NS_ENSURE_SUCCESS(rv, rv);
char* cur = inputURIHash.BeginWriting();
char* end = inputURIHash.EndWriting();
for (; cur < end; ++cur) {
if ('/' == *cur) {
*cur = '_';
}
}
// Obtain the local profile directory and construct the output icon file path
rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(aICOFile));
NS_ENSURE_SUCCESS(rv, rv);
if (!aURLShortcut)
rv = aICOFile->AppendNative(nsDependentCString(kJumpListCacheDir));
else
rv = aICOFile->AppendNative(nsDependentCString(kShortcutCacheDir));
NS_ENSURE_SUCCESS(rv, rv);
// Append the icon extension
inputURIHash.AppendLiteral(".ico");
rv = aICOFile->AppendNative(inputURIHash);
return rv;
}
示例3: GetOutputIconPath
// (static) Obtains the ICO file for the favicon at page aFaviconPageURI
// If successful, the file path on disk is in the format:
// <ProfLDS>\jumpListCache\<hash(aFaviconPageURI)>.ico
nsresult JumpListShortcut::GetOutputIconPath(nsCOMPtr<nsIURI> aFaviconPageURI,
nsCOMPtr<nsIFile> &aICOFile)
{
// Hash the input URI and replace any / with _
nsCAutoString inputURIHash;
nsCOMPtr<nsICryptoHash> cryptoHash;
nsresult rv = JumpListItem::HashURI(cryptoHash, aFaviconPageURI,
inputURIHash);
NS_ENSURE_SUCCESS(rv, rv);
char* cur = inputURIHash.BeginWriting();
char* end = inputURIHash.EndWriting();
for (; cur < end; ++cur) {
if ('/' == *cur) {
*cur = '_';
}
}
// Obtain the local profile directory and construct the output icon file path
rv = NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(aICOFile));
NS_ENSURE_SUCCESS(rv, rv);
rv = aICOFile->AppendNative(nsDependentCString(JumpListItem::kJumpListCacheDir));
NS_ENSURE_SUCCESS(rv, rv);
// Try to create the directory if it's not there yet
rv = aICOFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
if (NS_FAILED(rv) && rv != NS_ERROR_FILE_ALREADY_EXISTS) {
return rv;
}
// Append the icon extension
inputURIHash.Append(".ico");
rv = aICOFile->AppendNative(inputURIHash);
return rv;
}
示例4: leaf
static PRBool
CopyUpdaterIntoUpdateDir(nsIFile *greDir, nsIFile *appDir, nsIFile *updateDir,
nsCOMPtr<nsIFile> &updater)
{
// We have to move the updater binary and its resource file.
const char *filesToMove[] = {
#if defined(XP_MACOSX)
kUpdaterApp,
#else
kUpdaterINI,
kUpdaterBin,
#endif
nsnull
};
nsresult rv;
for (const char **leafName = filesToMove; *leafName; ++leafName) {
nsDependentCString leaf(*leafName);
nsCOMPtr<nsIFile> file;
// Make sure there is not an existing file in the target location.
rv = updateDir->Clone(getter_AddRefs(file));
if (NS_FAILED(rv))
return PR_FALSE;
rv = file->AppendNative(leaf);
if (NS_FAILED(rv))
return PR_FALSE;
file->Remove(PR_FALSE);
// Now, copy into the target location.
rv = greDir->Clone(getter_AddRefs(file));
if (NS_FAILED(rv))
return PR_FALSE;
rv = file->AppendNative(leaf);
if (NS_FAILED(rv))
return PR_FALSE;
rv = file->CopyToNative(updateDir, EmptyCString());
if (*leafName != kUpdaterINI && NS_FAILED(rv))
return PR_FALSE;
}
// Finally, return the location of the updater binary.
rv = updateDir->Clone(getter_AddRefs(updater));
if (NS_FAILED(rv))
return PR_FALSE;
#if defined(XP_MACOSX)
rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterApp));
rv |= updater->AppendNative(NS_LITERAL_CSTRING("Contents"));
rv |= updater->AppendNative(NS_LITERAL_CSTRING("MacOS"));
if (NS_FAILED(rv))
return PR_FALSE;
#endif
rv = updater->AppendNative(NS_LITERAL_CSTRING(kUpdaterBin));
return NS_SUCCEEDED(rv);
}
示例5: InitEmbedding
//.........这里部分代码省略.........
{"XRE_NotifyProfile", (NSFuncPtr*)&XRE_NotifyProfile},
{"XRE_LockProfileDirectory", (NSFuncPtr*)&XRE_LockProfileDirectory},
{0, 0}
};
rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv)) {
cerr << "Could not load XUL functions." << endl;
return 4;
}
// strip the filename from xpcom so we have the dir instead
size_t lastslash = xpcomPath.find_last_of("/\\");
if (lastslash == string::npos) {
cerr << "Invalid path to xpcom:" << xpcomPath << "." << endl;
return 3;
}
string xpcomDir = xpcomPath.substr(0, lastslash);
// create nsILocalFile pointing to xpcomDir
nsCOMPtr<nsILocalFile> xuldir;
rv = NS_NewNativeLocalFile(nsCString(xpcomDir.c_str()), PR_FALSE,
getter_AddRefs(xuldir));
if (NS_FAILED(rv)) {
cerr << "Unable to create nsILocalFile for xuldir " << xpcomDir
<< "." << endl;
return 6;
}
// create nsILocalFile pointing to appdir
char self[MAX_PATH];
#ifdef WIN32
GetModuleFileNameA(GetModuleHandle(NULL), self, sizeof(self));
#else
// TODO: works on linux, need solution for unices which do not support this
ssize_t len;
if ((len = readlink("/proc/self/exe", self, sizeof(self)-1)) != -1)
self[len] = '\0';
#endif
string selfPath(self);
lastslash = selfPath.find_last_of("/\\");
if (lastslash == string::npos) {
cerr << "Invalid module filename: " << self << "." << endl;
return 7;
}
selfPath = selfPath.substr(0, lastslash);
nsCOMPtr<nsILocalFile> appdir;
rv = NS_NewNativeLocalFile(nsCString(selfPath.c_str()), PR_FALSE,
getter_AddRefs(appdir));
if (NS_FAILED(rv)) {
cerr << "Unable to create nsILocalFile for appdir." << endl;
return 8;
}
// setup profile dir
nsCString pr(aProfilePath);
if (!pr.IsEmpty()) {
rv = NS_NewNativeLocalFile(pr, PR_FALSE,
getter_AddRefs(sProfileDir));
NS_ENSURE_SUCCESS(rv, rv);
} else {
// for now use a subdir under appdir
nsCOMPtr<nsIFile> profFile;
rv = appdir->Clone(getter_AddRefs(profFile));
NS_ENSURE_SUCCESS(rv, rv);
sProfileDir = do_QueryInterface(profFile);
sProfileDir->AppendNative(NS_LITERAL_CSTRING("mozembed"));
}
// create dir if needed
PRBool dirExists;
rv = sProfileDir->Exists(&dirExists);
NS_ENSURE_SUCCESS(rv, rv);
if (!dirExists) {
sProfileDir->Create(nsIFile::DIRECTORY_TYPE, 0700);
}
// Lock profile directory
if (sProfileDir && !sProfileLock) {
rv = XRE_LockProfileDirectory(sProfileDir, &sProfileLock);
NS_ENSURE_SUCCESS(rv, rv);
}
// init embedding
rv = XRE_InitEmbedding2(xuldir, appdir,
const_cast<MozEmbedDirectoryProvider*>(&kDirectoryProvider));
if (NS_FAILED(rv)) {
cerr << "XRE_InitEmbedding2 failed." << endl;
return 9;
}
// initialize profile:
XRE_NotifyProfile();
NS_LogTerm();
return NS_OK;
}