本文整理匯總了C++中CFURLCopyFileSystemPath函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFURLCopyFileSystemPath函數的具體用法?C++ CFURLCopyFileSystemPath怎麽用?C++ CFURLCopyFileSystemPath使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFURLCopyFileSystemPath函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: GetBinaryPath
std::string GetBinaryPath()
{
#ifdef linux
std::string path(GetBinaryFile());
size_t pathlength = path.find_last_of('/');
if (pathlength != std::string::npos)
return path.substr(0, pathlength);
else
return path;
#elif WIN32
TCHAR currentDir[MAX_PATH+1];
int ret = ::GetModuleFileName(0, currentDir, sizeof(currentDir));
if (ret == 0 || ret == sizeof(currentDir))
return "";
char drive[MAX_PATH], dir[MAX_PATH], file[MAX_PATH], ext[MAX_PATH];
_splitpath(currentDir, drive, dir, file, ext);
_makepath(currentDir, drive, dir, NULL, NULL);
return std::string(currentDir);
#elif MACOSX_BUNDLE
char cPath[1024];
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
CFURLRef binaryPathURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault , mainBundleURL);
CFStringRef cfStringRef = CFURLCopyFileSystemPath(binaryPathURL, kCFURLPOSIXPathStyle);
CFStringGetCString(cfStringRef, cPath, 1024, kCFStringEncodingASCII);
CFRelease(mainBundleURL);
CFRelease(binaryPathURL);
CFRelease(cfStringRef);
return std::string(cPath);
#else
return "";
#endif
}
示例2: macBundlePath
/**
* returns the path of the .app bundle on MacOS X
*
* this is needed to handle resource locations and config file pathes
* propperly on Mac OS X.
*/
std::string macBundlePath()
{
char path[1024];
CFBundleRef mainBundle = CFBundleGetMainBundle();
assert(mainBundle);
CFURLRef mainBundleURL = CFBundleCopyBundleURL(mainBundle);
assert(mainBundleURL);
CFStringRef cfStringRef = CFURLCopyFileSystemPath(
mainBundleURL, kCFURLPOSIXPathStyle);
assert(cfStringRef);
CFStringGetCString(cfStringRef, path, 1024, kCFStringEncodingASCII);
CFRelease(mainBundleURL);
CFRelease(cfStringRef);
return std::string(path);
}
示例3: CFBundleCopyBundleURL
QString Uploader::sam7Path( )
{
QString uploaderName;
#ifdef Q_OS_MAC // get the path within the app bundle
CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
QDir appBundle( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()) );
uploaderName = appBundle.filePath( "Contents/Resources/sam7" );
#elif defined (Q_OS_WIN)
QDir d = QDir::current();
if(!d.exists("sam7.exe")) // in dev mode, we're one dir down in 'bin'
d.cdUp();
uploaderName = d.filePath("sam7.exe");
#else
QSettings settings;
QDir dir( settings.value("sam7_path", DEFAULT_SAM7_PATH).toString() );
uploaderName = dir.filePath("sam7");
#endif
return uploaderName;
}
示例4: SetVMPathFromApplicationDirectory
OSStatus SetVMPathFromApplicationDirectory() {
CFBundleRef mainBundle;
CFURLRef bundleURL,bundleURLPrefix;
CFStringRef filePath;
CFMutableStringRef vmPathString;
mainBundle = CFBundleGetMainBundle();
bundleURL = CFBundleCopyBundleURL(mainBundle);
bundleURLPrefix = CFURLCreateCopyDeletingLastPathComponent(NULL,bundleURL);
CFRelease(bundleURL);
filePath = CFURLCopyFileSystemPath (bundleURLPrefix, kCFURLPOSIXPathStyle);
CFRelease(bundleURLPrefix);
vmPathString = CFStringCreateMutableCopy(NULL, 0, filePath);
CFStringAppendCString(vmPathString, "/", kCFStringEncodingMacRoman);
SetVMPathFromCFString(vmPathString);
CFRelease(filePath);
CFRelease(vmPathString);
return 0;
}
示例5: switch_to_game_directory
int switch_to_game_directory()
{
log_message("finding the bundle directory");
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef url = NULL;
if(bundle)
url = CFBundleCopyBundleURL(bundle);
if(!url)
{
log_message("no bundle found");
return 0;
}
CFStringRef str = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
CFRelease(url);
int size = CFStringGetLength(str) + 1;
char *dir = (char *)malloc(size);
int success = CFStringGetCString(str, dir, size, kCFURLPOSIXPathStyle);
CFRelease(str);
if(success)
{
int success = chdir(dir);
if(success == 0)
log_messagef("changed directory to '%s'", dir);
else
log_messagef("failed changing directory to '%s'", dir);
// there must be a better way to tell if we're bundled :/
if(chdir("Contents/Resources") == 0)
log_message("running as an app bundle, changed to resources directory");
else
log_message("running unbundled");
}
free(dir);
return success;
}
示例6: getIconFromApplication
Image JUCE_API getIconFromApplication (const String& applicationPath, const int size)
{
Image hostIcon;
if (CFStringRef pathCFString = CFStringCreateWithCString (kCFAllocatorDefault, applicationPath.toRawUTF8(), kCFStringEncodingUTF8))
{
if (CFURLRef url = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, pathCFString, kCFURLPOSIXPathStyle, 1))
{
if (CFBundleRef appBundle = CFBundleCreate (kCFAllocatorDefault, url))
{
if (CFTypeRef infoValue = CFBundleGetValueForInfoDictionaryKey (appBundle, CFSTR("CFBundleIconFile")))
{
if (CFGetTypeID (infoValue) == CFStringGetTypeID())
{
CFStringRef iconFilename = reinterpret_cast<CFStringRef> (infoValue);
CFStringRef resourceURLSuffix = CFStringHasSuffix (iconFilename, CFSTR(".icns")) ? nullptr : CFSTR("icns");
if (CFURLRef iconURL = CFBundleCopyResourceURL (appBundle, iconFilename, resourceURLSuffix, nullptr))
{
if (CFStringRef iconPath = CFURLCopyFileSystemPath (iconURL, kCFURLPOSIXPathStyle))
{
File icnsFile (CFStringGetCStringPtr (iconPath, CFStringGetSystemEncoding()));
hostIcon = getIconFromIcnsFile (icnsFile, size);
CFRelease (iconPath);
}
CFRelease (iconURL);
}
}
}
CFRelease (appBundle);
}
CFRelease (url);
}
CFRelease (pathCFString);
}
return hostIcon;
}
示例7: NavGetDefaultDialogCreationOptions
char *Sys_PathFromOpenMenu(void) {
/* present an open file dialog and return the file's path */
OSStatus res;
NavDialogCreationOptions options;
NavDialogRef dialog;
NavReplyRecord reply;
NavUserAction action;
FSRef fileRef;
CFURLRef cfUrl;
CFStringRef cfString;
res = NavGetDefaultDialogCreationOptions(&options);
options.modality = kWindowModalityAppModal;
res = NavCreateGetFileDialog(&options, NULL, NULL, NULL, NULL, NULL, &dialog);
NavDialogRun(dialog);
action = NavDialogGetUserAction(dialog);
if (action == kNavUserActionNone || action == kNavUserActionCancel)
return NULL;
res = NavDialogGetReply(dialog, &reply);
if (res != noErr)
return NULL;
res = AEGetNthPtr(&reply.selection, 1, typeFSRef, NULL, NULL, &fileRef,
sizeof(FSRef), NULL);
cfUrl = CFURLCreateFromFSRef(NULL, &fileRef);
cfString = NULL;
if (cfUrl) {
cfString = CFURLCopyFileSystemPath(cfUrl, kCFURLPOSIXPathStyle);
CFRelease(cfUrl);
}
memset(g_OpenFileName, 0, PATH_MAX);
CFStringGetCString(cfString, g_OpenFileName, PATH_MAX, kCFStringEncodingMacRoman);
return g_OpenFileName;
}
示例8: CFURLCopyFileSystemPath
CF::String URL::GetFileSystemPath( CFURLPathStyle style )
{
CF::String str;
CFStringRef cfStr;
if( this->_cfObject == NULL )
{
return str;
}
cfStr = CFURLCopyFileSystemPath( this->_cfObject, style );
if( cfStr != NULL )
{
str = cfStr;
CFRelease( cfStr );
}
return str;
}
示例9: getBundleRoot
char* getBundleRoot(){
// Adjust the path to the folder containing .app file:
CFBundleRef br;
CFURLRef ur;
CFStringRef sr;
br = CFBundleGetMainBundle();
if (br) {
long i;
ur = CFBundleCopyBundleURL(br);
sr = CFURLCopyFileSystemPath(ur, kCFURLPOSIXPathStyle);
i = switches_count++;
switches = realloc(switches,switches_count*sizeof(char*));
switches[i] = malloc(FILENAME_MAX);
CFStringGetCString(sr,switches[i],FILENAME_MAX,kCFStringEncodingASCII);
CFRelease(ur);
CFRelease(sr);
return switches[i];
}
return 0;
};
示例10: getexecutablepath
void getexecutablepath(char* buffer, size_t bufferLen)
{
#if defined( OS_MACOSX )
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef executableUrl = CFBundleCopyExecutableURL(mainBundle);
CFStringRef executableString = CFURLCopyFileSystemPath(executableUrl, kCFURLPOSIXPathStyle);
CFMutableStringRef normalizedString = CFStringCreateMutableCopy(NULL, 0, executableString);
CFStringGetCString(normalizedString, buffer, bufferLen - 1, kCFStringEncodingUTF8);
CFRelease(executableUrl);
CFRelease(executableString);
CFRelease(normalizedString);
#elif defined(__FreeBSD__)
sysctl_get_pathname(buffer, bufferLen);
#else
if (readlink("/proc/self/exe", buffer, bufferLen) != -1)
{
return;
}
*buffer = 0;
#endif
}
示例11: MoreAEOCreateObjSpecifierFromCFURLRef
pascal OSStatus MoreAEOCreateObjSpecifierFromCFURLRef(const CFURLRef pCFURLRef,AEDesc *pObjSpecifier)
{
OSErr anErr = paramErr;
if (NULL != pCFURLRef)
{
CFStringRef tCFStringRef = CFURLCopyFileSystemPath(pCFURLRef,kCFURLHFSPathStyle);
anErr = coreFoundationUnknownErr;
if (NULL != tCFStringRef)
{
Boolean isDirectory = CFURLHasDirectoryPath(pCFURLRef);
AEDesc containerDesc = {typeNull, NULL};
AEDesc nameDesc = {typeNull, NULL};
Size bufSize = (CFStringGetLength(tCFStringRef) + (isDirectory ? 1 : 0)) * sizeof(UniChar);
UniCharPtr buf = (UniCharPtr) NewPtr(bufSize);
if ((anErr = MemError()) == noErr)
{
CFStringGetCharacters(tCFStringRef, CFRangeMake(0,bufSize/2), buf);
if (isDirectory) (buf)[(bufSize-1)/2] = (UniChar) 0x003A;
}
if (anErr == noErr)
anErr = AECreateDesc(typeUnicodeText, buf, GetPtrSize((Ptr) buf), &nameDesc);
if (anErr == noErr)
{
if (isDirectory) // we use cObject here since this might be a package (and we have no way to tell)
anErr = CreateObjSpecifier(cObject, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
else
anErr = CreateObjSpecifier(cFile, &containerDesc, formName, &nameDesc, false, pObjSpecifier);
}
MoreAEDisposeDesc(&nameDesc);
if (buf)
DisposePtr((Ptr)buf);
}
}
return anErr;
}//end MoreAEOCreateObjSpecifierFromCFURLRef
示例12: ios_open_from_bundle
static FILE* ios_open_from_bundle(const char path[], const char* perm) {
// Get a reference to the main bundle
CFBundleRef mainBundle = CFBundleGetMainBundle();
// Get a reference to the file's URL
CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL);
if (!imageURL) {
return nullptr;
}
// Convert the URL reference into a string reference
CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle);
// Get the system encoding method
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
// Convert the string reference into a C string
const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod);
return fopen(finalPath, perm);
}
示例13: GetTempFolderPath
static void GetTempFolderPath( uint16 *tempPath, size_t destMaxLength)
{
//Find the Temp directory
#if MSWindows
wchar_t tempFolderPath[4096];
GetTempPathW(4096,tempFolderPath);
StringCopy3D(tempPath,tempFolderPath, 4096);
#else
FSRef folderRef;
OSErr err = FSFindFolder( kOnSystemDisk, kTemporaryFolderType, true, &folderRef );
if ( err != noErr )
{
err = FSFindFolder( kOnAppropriateDisk, kTemporaryFolderType, true, &folderRef );
}
if(err != noErr)
{
wchar_t tempFolderPath[]=L"/tmp/";
StringCopy3D(tempPath,tempFolderPath, destMaxLength);
}
else
{
CFURLRef url = CFURLCreateFromFSRef( kCFAllocatorDefault, &folderRef );
CFStringRef cfString = NULL;
if ( url != NULL )
{
cfString = CFURLCopyFileSystemPath( url, kCFURLPOSIXPathStyle );
CFStringGetCString(cfString,(char*)tempPath,2048,kCFStringEncodingUnicode);
int32 len=CFStringGetLength(cfString);
CFRelease( url );
tempPath[len]='/';
tempPath[len+1]=0;
}
}
#endif
}
示例14: bundle_path
void Cinderactor::init(const std::string & ini_file )
{
// Get a reference to the main bundle
#ifdef _WIN32
std::string bundle_path(".\\resources\\");
#else
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle );
CFRelease(resourcesURL);
char path[PATH_MAX];
CFStringGetCString( str, path, FILENAME_MAX, kCFStringEncodingASCII );
CFRelease(str);
std::string bundle_path(path);
bundle_path= bundle_path+"/Contents/Resources/";
#endif
std::cout << ">>>>>>>>>>>> BUNDLE : bundle_path " << bundle_path << std::endl;
gestoos::nui::Interactor::set_resources_path(bundle_path);
gestoos::nui::Interactor::init( ini_file );
init_ok = true;
}
示例15: CFURLCreateFromFSRef
/**
* Get the location for global or user-local support files.
* @return NULL if it could not be determined
*/
char *Bgetsupportdir(int global)
{
char *dir = NULL;
#ifdef __APPLE__
FSRef ref;
CFStringRef str;
CFURLRef base;
const char *s;
if (FSFindFolder(global ? kLocalDomain : kUserDomain,
kApplicationSupportFolderType,
kDontCreateFolder, &ref) < 0) return NULL;
base = CFURLCreateFromFSRef(NULL, &ref);
if (!base) {
return NULL;
}
str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
CFRelease(base);
if (!str) {
return NULL;
}
s = CFStringGetCStringPtr(str, CFStringGetSystemEncoding());
if (s) {
dir = strdup(s);
}
CFRelease(str);
#else
if (!global) {
dir = Bgethomedir();
}
#endif
return dir;
}