コード例 #1
0
ファイル: Misc.cpp プロジェクト: DeadnightWarrior/spring
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
0
/**
 * 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
0
ファイル: Uploader.cpp プロジェクト: sanjog47/makecontroller
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
0
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
0
ファイル: minlua.c プロジェクト: nud/dokidoki-support
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
0
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
0
ファイル: apple.c プロジェクト: davidreynolds/Atlas2D
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
0
ファイル: CFPP-URL.cpp プロジェクト: siraj/CFPP
 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
0
ファイル: boot.c プロジェクト: YachaoLiu/screenweaver-hx
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
0
ファイル: fileunix.c プロジェクト: arventwei/jamplus
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
0
ファイル: MoreAEObjects.c プロジェクト: paullalonde/B
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
0
ファイル: SkOSFile_stdio.cpp プロジェクト: 03050903/skia
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
0
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
0
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
0
ファイル: compat.c プロジェクト: Hendricks266/jfbuild
/**
 * 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;
}
コード例 #16
0
QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
{
    QList<QStorageInfo> volumes;

    QCFType<CFURLEnumeratorRef> enumerator;
    enumerator = CFURLEnumeratorCreateForMountedVolumes(Q_NULLPTR,
                                                        kCFURLEnumeratorSkipInvisibles,
                                                        Q_NULLPTR);

    CFURLEnumeratorResult result = kCFURLEnumeratorSuccess;
    do {
        CFURLRef url;
        CFErrorRef error;
        result = CFURLEnumeratorGetNextURL(enumerator, &url, &error);
        if (result == kCFURLEnumeratorSuccess) {
            const QCFString urlString = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
            volumes.append(QStorageInfo(urlString));
        }
    } while (result != kCFURLEnumeratorEnd);

    return volumes;
}
コード例 #17
0
CFIndex addCTFontDescriptor(CTFontDescriptorRef fd, JNIEnv *env, jobjectArray result, CFIndex index)
{
    if (fd) {
        CFStringRef name = CTFontDescriptorCopyAttribute(fd, kCTFontDisplayNameAttribute);
        CFStringRef family = CTFontDescriptorCopyAttribute(fd, kCTFontFamilyNameAttribute);
        CFURLRef url = CTFontDescriptorCopyAttribute(fd, kCTFontURLAttribute);
        CFStringRef file = url ? CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle) : NULL;
        if (name && family && file) {
            jstring jname = createJavaString(env, name);
            jstring jfamily = createJavaString(env, family);
            jstring jfile = createJavaString(env, file);
            (*env)->SetObjectArrayElement(env, result, index++, jname);
            (*env)->SetObjectArrayElement(env, result, index++, jfamily);
            (*env)->SetObjectArrayElement(env, result, index++, jfile);
        }
        if (name) CFRelease(name);
        if (family) CFRelease(family);
        if (url) CFRelease(url);
        if (file) CFRelease(file);
    }
    return index;
}
コード例 #18
0
QString ScPaths::bundleDir(void) const
{
	// On MacOS/X, override the compile-time settings with a location
// obtained from the system.
#ifdef Q_WS_MAC
	// Set up the various app paths to look inside the app bundle
	CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
										   kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath,
										   CFStringGetSystemEncoding());

	// make sure we get the Scribus.app directory, not some subdir

	// strip trailing '/':
	char *p = const_cast<char*>(pathPtr + strlen(pathPtr) - 1);
	while (*p == '/')
		--p;
	++p;
	*p = '\0';
	if (strcmp("/bin", p-4) == 0) {
		p -= 4;
		*p = '\0';
	}
	if (strcmp("/MacOS", p-6) == 0) {
		p -= 6;
		*p = '\0';
	}
	if (strcmp("/Contents", p-9) == 0) {
		p -= 9;
		*p = '\0';
	}
	CFRelease(pluginRef);
	CFRelease(macPath);
	return QString("%1").arg(pathPtr);
#endif
	return QString::null;
}
コード例 #19
0
ファイル: OSXAccess.c プロジェクト: aprasa/oldwork
JNIEXPORT jstring JNICALL
Java_org_gudy_azureus2_platform_macosx_access_jnilib_OSXAccess_getDocDir(
	JNIEnv		*env,
	jclass		cla )
{
	CFURLRef docURL;
	CFStringRef docPath;
	FSRef    fsRef;
  OSErr    err = FSFindFolder(kUserDomain, kDocumentsFolderType, kDontCreateFolder, &fsRef);
  
  jstring result = 0;

	if (err == noErr) {
  	if((docURL = CFURLCreateFromFSRef( kCFAllocatorSystemDefault, &fsRef))) {
			docPath = CFURLCopyFileSystemPath(docURL, kCFURLPOSIXPathStyle);
			
			if (docPath) {
				// convert to unicode
				CFIndex strLen = CFStringGetLength( docPath );
				UniChar uniStr[ strLen ];
				CFRange strRange;
				strRange.location = 0;
				strRange.length = strLen;
				CFStringGetCharacters( docPath, strRange, uniStr );
	
				result = (*env)->NewString( env, (jchar*)uniStr, (jsize)strLen );

				CFRelease(docPath);
				
				return result;
			}
			CFRelease(docURL);
		}

		return result;
  }
}
コード例 #20
0
ファイル: compat.c プロジェクト: TermiT/Shadow-Warrior-iOS
char *Bgethomedir(void)
{
#ifdef _WIN32
	TCHAR appdata[MAX_PATH];

	if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE)))
		return strdup(appdata);
	return NULL;
#elif defined __APPLE__
    
#if LOWANG_IOS
    const char* Sys_GetResourceDir(void);
	return strdup(Sys_GetResourceDir());
#else
    
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	char *s;

	if (FSFindFolder(kUserDomain, kVolumeRootFolderType, kDontCreateFolder, &ref) < 0) return NULL;
	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) return NULL;
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) return NULL;
	s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#endif
#else
	char *e = getenv("HOME");
	if (!e) return NULL;
	return strdup(e);
#endif
}
コード例 #21
0
ファイル: compat.c プロジェクト: Plagman/jfbuild
char *Bgetsupportdir(int global)
{
#ifndef __APPLE__
	return Bgethomedir();
#else
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	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 = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#endif
}
コード例 #22
0
ファイル: TimedExecMain.cpp プロジェクト: doctorjbeam/Syslist
long GetProcDir(std::string & Dest)
{
	CFAuto<CFURLRef> TestURL(
		CFBundleCopyExecutableURL(CFBundleGetMainBundle()));
		
	CFAuto<CFStringRef> PathCFString(
		CFURLCopyFileSystemPath(TestURL,kCFURLPOSIXPathStyle));
	
	long PathLen = CFStringGetLength(PathCFString) + 1;
	
	char PathString[PathLen];
	
	//AutoCharBuf PathString(PathLen);
	CFStringGetCString(PathCFString, PathString, PathLen ,kCFStringEncodingUTF8);
	
	char* PathTerm = strrchr(PathString, '/');
	
	if (PathTerm != NULL)
		*(PathTerm + 1) = '\0';
		
	Dest = PathString;
	
	return 0;	
}
コード例 #23
0
ファイル: kkernel_mac.cpp プロジェクト: vasi/kdelibs
QString mac_app_filename() {
	static QString appFileName;
	if (appFileName.isEmpty()) {
		CFURLRef bundleURL = NULL;
		CFBundleRef bundle = NULL;
		CFStringRef bundlePath = NULL;

		bundle = CFBundleGetMainBundle();
		if (bundle) {
			bundleURL = CFBundleCopyBundleURL(bundle);
			bundlePath = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);

			if (bundleURL) {
				CFRelease(bundleURL);
			}

			if (bundlePath) {
				appFileName = convert_CFString_to_QString(bundlePath);
				CFRelease(bundlePath);
			}
		}
	}
	return appFileName;
}
コード例 #24
0
ファイル: nfosc.c プロジェクト: guozanhua/nfosc
void read_database() {
    
    int i;
#ifdef __APPLE__
    char app_path[1024];
    CFURLRef mainBundleURL = CFBundleCopyBundleURL( CFBundleGetMainBundle());
    CFStringRef cfStringRef = CFURLCopyFileSystemPath( mainBundleURL, kCFURLPOSIXPathStyle);
    CFStringGetCString( cfStringRef, app_path, 1024, kCFStringEncodingASCII);
    CFRelease( mainBundleURL);
    CFRelease( cfStringRef);
    sprintf(db_file_name,"%s/Contents/Resources/nfosc.db",app_path);
#else
    strcpy(db_file_name,"nfosc.db");
#endif
    
    nfosc_t db_entry;
    char line[36];
    FILE *db_file = fopen(db_file_name, "r");
    if (db_file==NULL) return;
    
    while (fgets (line, 32, db_file)) {
        db_entry.symbol_id = max_symbol_id;
        for (i=0; i<32; i++) {
            if (line[i]=='\n') {
                db_entry.uid_str[i]='\0';
                break;
            }
            db_entry.uid_str[i]=line[i];
        }
        if (verbose) printf("assigning ID %d to UID %s\n",max_symbol_id,db_entry.uid_str);
        tag_database[max_symbol_id] = db_entry;
        max_symbol_id++;
    }
    
    fclose (db_file);
}
コード例 #25
0
ファイル: main.cpp プロジェクト: 3liz/Quantum-GIS
#endif

  QSettings mySettings;

  // For non static builds on mac and win (static builds are not supported)
  // we need to be sure we can find the qt image
  // plugins. In mac be sure to look in the
  // application bundle...
#ifdef Q_OS_WIN
  QCoreApplication::addLibraryPath( QApplication::applicationDirPath()
                                    + QDir::separator() + "qtplugins" );
#endif
#ifdef Q_OS_MACX
  //qDebug("Adding qt image plugins to plugin search path...");
  CFURLRef myBundleRef = CFBundleCopyBundleURL( CFBundleGetMainBundle() );
  CFStringRef myMacPath = CFURLCopyFileSystemPath( myBundleRef, kCFURLPOSIXPathStyle );
  const char *mypPathPtr = CFStringGetCStringPtr( myMacPath, CFStringGetSystemEncoding() );
  CFRelease( myBundleRef );
  CFRelease( myMacPath );
  QString myPath( mypPathPtr );
  // if we are not in a bundle assume that the app is built
  // as a non bundle app and that image plugins will be
  // in system Qt frameworks. If the app is a bundle
  // lets try to set the qt plugin search path...
  QFileInfo myInfo( myPath );
  if ( myInfo.isBundle() )
  {
    // First clear the plugin search paths so we can be sure
    // only plugins from the bundle are being used
    QStringList myPathList;
    QCoreApplication::setLibraryPaths( myPathList );
コード例 #26
0
CFDictionaryRef createDockDescriptionForURL(CFURLRef url) {
	if (!url) {
		NSLog(CFSTR("%@"), CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: Cannot copy Dock description for a NULL URL"));
		return NULL;
	}

	//return NULL for non-file: URLs.
	CFStringRef scheme = CFURLCopyScheme(url);
	Boolean isFileURL = (CFStringCompare(scheme, CFSTR("file"), kCFCompareCaseInsensitive) == kCFCompareEqualTo);
	CFRelease(scheme);
	if (!isFileURL)
		return NULL;

	CFDictionaryRef dict = NULL;
	CFStringRef path     = NULL;
	CFDataRef aliasData  = NULL;

	FSRef    fsref;
	if (CFURLGetFSRef(url, &fsref)) {
		AliasHandle alias = NULL;
		OSStatus    err   = FSNewAlias(/*fromFile*/ NULL, &fsref, &alias);
		if (err != noErr) {
			NSLog(CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: FSNewAlias for %@ returned %li"), url, (long)err);
		} else {
			HLock((Handle)alias);

			err = FSCopyAliasInfo(alias, /*targetName*/ NULL, /*volumeName*/ NULL, (CFStringRef *)&path, /*whichInfo*/ NULL, /*info*/ NULL);
			if (err != noErr) {
				NSLog(CFSTR("in copyDockDescriptionForURL in CFGrowlAdditions: FSCopyAliasInfo for %@ returned %li"), url, (long)err);
			}

			aliasData = CFDataCreate(kCFAllocatorDefault, (UInt8 *)*alias, GetHandleSize((Handle)alias));

			HUnlock((Handle)alias);
			DisposeHandle((Handle)alias);
		}
	}

	if (!path) {
		path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
	}

	if (path || aliasData) {
		CFMutableDictionaryRef temp = CFDictionaryCreateMutable(kCFAllocatorDefault, /*capacity*/ 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

		if (path) {
			CFDictionarySetValue(temp, _CFURLStringKey, path);
			CFRelease(path);

			int pathStyle = kCFURLPOSIXPathStyle;
			CFNumberRef pathStyleNum = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pathStyle);
			CFDictionarySetValue(temp, _CFURLStringTypeKey, pathStyleNum);
			CFRelease(pathStyleNum);
		}

		if (aliasData) {
			CFDictionarySetValue(temp, _CFURLAliasDataKey, aliasData);
			CFRelease(aliasData);
		}

		dict = temp;
	}

	return dict;
}
コード例 #27
0
CFStringRef copyCurrentProcessPath(void) {
	CFURLRef URL = copyCurrentProcessURL();
	CFStringRef path = CFURLCopyFileSystemPath(URL, kCFURLPOSIXPathStyle);
	CFRelease(URL);
	return path;
}
コード例 #28
0
ファイル: stratagus.cpp プロジェクト: ajaykon/Stratagus
/**
**  The main program: initialise, parse options and arguments.
**
**  @param argc  Number of arguments.
**  @param argv  Vector of arguments.
*/
int main(int argc, char **argv)
{
#ifdef REDIRECT_OUTPUT
	RedirectOutput();
#endif

#ifdef USE_BEOS
	//  Parse arguments for BeOS
	beos_init(argc, argv);
#endif

	//  Setup some defaults.
#ifndef MAC_BUNDLE
	StratagusLibPath = ".";
#else
	freopen("/tmp/stdout.txt", "w", stdout);
	freopen("/tmp/stderr.txt", "w", stderr);
	// Look for the specified data set inside the application bundle
	// This should be a subdir of the Resources directory
	CFURLRef pluginRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
												 CFSTR(MAC_BUNDLE_DATADIR), NULL, NULL);
	CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,  kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
	Assert(pathPtr);
	StratagusLibPath = pathPtr;
#endif

	Parameters &parameters = Parameters::Instance;
	parameters.SetDefaultValues();
	parameters.LocalPlayerName = GetLocalPlayerNameFromEnv();

	if (argc > 0) {
		parameters.applicationName = argv[0];
	}

	// FIXME: Parse options before or after scripts?
	ParseCommandLine(argc, argv, parameters);
	// Init the random number generator.
	InitSyncRand();

	makedir(parameters.GetUserDirectory().c_str(), 0777);

	// Init Lua and register lua functions!
	InitLua();
	LuaRegisterModules();

	// Initialise AI module
	InitAiModule();

	LoadCcl(parameters.luaStartFilename);

	PrintHeader();
	PrintLicense();

	// Setup video display
	InitVideo();

	// Setup sound card
	if (!InitSound()) {
		InitMusic();
	}

#ifndef DEBUG           // For debug it's better not to have:
	srand(time(NULL));  // Random counter = random each start
#endif

	//  Show title screens.
	SetDefaultTextColors(FontYellow, FontWhite);
	LoadFonts();
	SetClipping(0, 0, Video.Width - 1, Video.Height - 1);
	Video.ClearScreen();
	ShowTitleScreens();

	// Init player data
	ThisPlayer = NULL;
	//Don't clear the Players strucure as it would erase the allowed units.
	// memset(Players, 0, sizeof(Players));
	NumPlayers = 0;

	UnitManager.Init(); // Units memory management
	PreMenuSetup();     // Load everything needed for menus

	MenuLoop();

	Exit(0);
	return 0;
}
コード例 #29
0
ファイル: dev.c プロジェクト: JeremyAgost/SDMMobileDevice
void StartDebuggingAndDetach(char *udid, char *app_path) {
	SDMMD_AMDeviceRef device = FindDeviceFromUDID(udid);
	if (device) {

		CFStringRef bundleId = CFStringCreateWithBytes(kCFAllocatorDefault, (UInt8 *)app_path, strlen(app_path), kCFStringEncodingUTF8, false);
		CFURLRef relative_url = CFURLCreateWithFileSystemPath(NULL, bundleId, kCFURLPOSIXPathStyle, false);
		CFURLRef disk_app_url = CFURLCopyAbsoluteURL(relative_url);
		CFStringRef bundle_identifier = copy_disk_app_identifier(disk_app_url);

		
		SDMMD_AMDebugConnectionRef debug = SDMMD_AMDebugConnectionCreateForDevice(device);
		SDMMD_AMDebugConnectionStart(debug);
		
		uintptr_t socket = SDMMD_AMDServiceConnectionGetSocket(debug->connection);
		CFSocketContext context = { 0, (void*)socket, NULL, NULL, NULL };
		CFSocketRef fdvendor = CFSocketCreate(NULL, AF_UNIX, 0, 0, kCFSocketAcceptCallBack, &socket_callback, &context);
		
		int yes = 1;
		setsockopt(CFSocketGetNative(fdvendor), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
		
		struct sockaddr_un address;
		memset(&address, 0, sizeof(address));
		address.sun_family = AF_UNIX;
		strcpy(address.sun_path, SDM_LLDB_SOCKET);
		address.sun_len = SUN_LEN(&address);
		CFDataRef address_data = CFDataCreate(NULL, (const UInt8 *)&address, sizeof(address));
		
		unlink(SDM_LLDB_SOCKET);
		
		CFSocketSetAddress(fdvendor, address_data);
		CFRelease(address_data);
		CFRunLoopAddSource(CFRunLoopGetMain(), CFSocketCreateRunLoopSource(NULL, fdvendor, 0), kCFRunLoopCommonModes);
		
		SDMMD_AMDeviceRef device = SDMMD_AMDServiceConnectionGetDevice(debug->connection);
		CFMutableStringRef cmds = CFStringCreateMutableCopy(NULL, 0, LLDB_PREP_CMDS);
		CFRange range = { 0, CFStringGetLength(cmds) };
		
		CFURLRef device_app_url = copy_device_app_url(device, bundle_identifier);
		CFStringRef device_app_path = CFURLCopyFileSystemPath(device_app_url, kCFURLPOSIXPathStyle);
		CFStringFindAndReplace(cmds, CFSTR("{DEVICE_PATH}"), device_app_path, range, 0);
		range.length = CFStringGetLength(cmds);
		
		CFStringRef disk_app_path = CFURLCopyFileSystemPath(disk_app_url, kCFURLPOSIXPathStyle);
		CFStringFindAndReplace(cmds, CFSTR("{APP_PATH}"), disk_app_path, range, 0);
		range.length = CFStringGetLength(cmds);
		
		CFURLRef device_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, device_app_url);
		CFStringRef device_container_path = CFURLCopyFileSystemPath(device_container_url, kCFURLPOSIXPathStyle);
		CFMutableStringRef dcp_noprivate = CFStringCreateMutableCopy(NULL, 0, device_container_path);
		range.length = CFStringGetLength(dcp_noprivate);
		CFStringFindAndReplace(dcp_noprivate, CFSTR("/private/var/"), CFSTR("/var/"), range, 0);
		range.length = CFStringGetLength(cmds);
		CFStringFindAndReplace(cmds, CFSTR("{device_container}"), dcp_noprivate, range, 0);
		range.length = CFStringGetLength(cmds);
		
		CFURLRef disk_container_url = CFURLCreateCopyDeletingLastPathComponent(NULL, disk_app_url);
		CFStringRef disk_container_path = CFURLCopyFileSystemPath(disk_container_url, kCFURLPOSIXPathStyle);
		CFStringFindAndReplace(cmds, CFSTR("{disk_container}"), disk_container_path, range, 0);
		
		CFDataRef cmds_data = CFStringCreateExternalRepresentation(NULL, cmds, kCFStringEncodingASCII, 0);
		FILE *out = fopen(PREP_CMDS_PATH, "w");
		fwrite(CFDataGetBytePtr(cmds_data), CFDataGetLength(cmds_data), 1, out);
		fclose(out);
		
		CFSafeRelease(cmds);
		CFSafeRelease(bundle_identifier);
		CFSafeRelease(device_app_url);
		CFSafeRelease(device_app_path);
		CFSafeRelease(disk_app_path);
		CFSafeRelease(device_container_url);
		CFSafeRelease(device_container_path);
		CFSafeRelease(dcp_noprivate);
		CFSafeRelease(disk_container_url);
		CFSafeRelease(disk_container_path);
		CFSafeRelease(cmds_data);
		
		signal(SIGHUP, exit);
		
		pid_t parent = getpid();
		int pid = fork();
		if (pid == 0) {
			system("xcrun -sdk iphoneos lldb /tmp/sdmmd-lldb-prep");
			kill(parent, SIGHUP);
			_exit(0);
		}
		CFRunLoopRun();
	}
}
コード例 #30
0
__private_extern__ CFArrayRef  _CFPreferencesCreateDomainList(CFStringRef  userName, CFStringRef  hostName) {
    CFAllocatorRef prefAlloc = __CFPreferencesAllocator();
    CFArrayRef  domains;
    CFMutableArrayRef  marray;
    CFStringRef  *cachedDomainKeys;
    CFPreferencesDomainRef *cachedDomains;
    SInt32 idx, cnt;
    CFStringRef  suffix;
    UInt32 suffixLen;
    CFURLRef prefDir = _preferencesDirectoryForUserHost(userName, hostName);
    
    if (!prefDir) {
        return NULL;
    }
    if (hostName == kCFPreferencesAnyHost) {
        suffix = CFStringCreateWithCString(prefAlloc, ".plist", kCFStringEncodingASCII);
    } else if (hostName == kCFPreferencesCurrentHost) {
        CFStringRef hostID = _CFPreferencesGetByHostIdentifierString();
        suffix = CFStringCreateWithFormat(prefAlloc, NULL, CFSTR(".%@.plist"), hostID);
    } else {
        suffix = CFStringCreateWithFormat(prefAlloc, NULL, CFSTR(".%@.plist"), hostName);   // sketchy - this allows someone to create a domain list for an arbitrary hostname.
    }
    suffixLen = CFStringGetLength(suffix);
    
    domains = (CFArrayRef)CFURLCreatePropertyFromResource(prefAlloc, prefDir, kCFURLFileDirectoryContents, NULL);
    CFRelease(prefDir);
    if (domains){
        marray = CFArrayCreateMutableCopy(prefAlloc, 0, domains);
        CFRelease(domains);
    } else {
        marray = CFArrayCreateMutable(prefAlloc, 0, & kCFTypeArrayCallBacks);
    }
    for (idx = CFArrayGetCount(marray)-1; idx >= 0; idx --) {
        CFURLRef  url = (CFURLRef)CFArrayGetValueAtIndex(marray, idx);
        CFStringRef string = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
        if (!CFStringHasSuffix(string, suffix)) {
            CFArrayRemoveValueAtIndex(marray, idx);
        } else {
            CFStringRef  dom = CFStringCreateWithSubstring(prefAlloc, string, CFRangeMake(0, CFStringGetLength(string) - suffixLen));
            if (CFEqual(dom, CFSTR(".GlobalPreferences"))) {
                CFArraySetValueAtIndex(marray, idx, kCFPreferencesAnyApplication);
            } else {
                CFArraySetValueAtIndex(marray, idx, dom);
            }
            CFRelease(dom);
        }
        CFRelease(string);
    }
    CFRelease(suffix);
    
    // Now add any domains added in the cache; delete any that have been deleted in the cache
    __CFSpinLock(&domainCacheLock);
    if (!domainCache) {
        __CFSpinUnlock(&domainCacheLock);
        return marray;
    }
    cnt = CFDictionaryGetCount(domainCache);
    cachedDomainKeys = (CFStringRef *)CFAllocatorAllocate(prefAlloc, 2 * cnt * sizeof(CFStringRef), 0);
    cachedDomains = (CFPreferencesDomainRef *)(cachedDomainKeys + cnt);
    CFDictionaryGetKeysAndValues(domainCache, (const void **)cachedDomainKeys, (const void **)cachedDomains);
    __CFSpinUnlock(&domainCacheLock);
    suffix = _CFPreferencesCachePrefixForUserHost(userName, hostName);
    suffixLen = CFStringGetLength(suffix);
    
    for (idx = 0; idx < cnt; idx ++) {
        CFStringRef  domainKey = cachedDomainKeys[idx];
        CFPreferencesDomainRef domain = cachedDomains[idx];
        CFStringRef  domainName;
        CFIndex keyCount = 0;
        
        if (!CFStringHasPrefix(domainKey, suffix)) continue;
        domainName = CFStringCreateWithSubstring(prefAlloc, domainKey, CFRangeMake(suffixLen, CFStringGetLength(domainKey) - suffixLen));
        if (CFEqual(domainName, CFSTR("*"))) {
            CFRelease(domainName);
            domainName = (CFStringRef)CFRetain(kCFPreferencesAnyApplication);
        } else if (CFEqual(domainName, kCFPreferencesCurrentApplication)) {
            CFRelease(domainName);
            domainName = (CFStringRef)CFRetain(_CFProcessNameString());
        }
        CFDictionaryRef d = _CFPreferencesDomainDeepCopyDictionary(domain);
        keyCount = d ? CFDictionaryGetCount(d) : 0;
        if (keyCount) CFRelease(d);
        if (keyCount == 0) {
            // Domain was deleted
            SInt32 firstIndexOfValue = CFArrayGetFirstIndexOfValue(marray, CFRangeMake(0, CFArrayGetCount(marray)), domainName);
            if (0 <= firstIndexOfValue) {
                CFArrayRemoveValueAtIndex(marray, firstIndexOfValue);
            }
        } else if (!CFArrayContainsValue(marray, CFRangeMake(0, CFArrayGetCount(marray)), domainName)) {
            CFArrayAppendValue(marray, domainName);
        }
        CFRelease(domainName);
    }
    CFRelease(suffix);
    CFAllocatorDeallocate(prefAlloc, cachedDomainKeys);
    return marray;
}