本文整理匯總了C++中CFURLCreateFromFileSystemRepresentation函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFURLCreateFromFileSystemRepresentation函數的具體用法?C++ CFURLCreateFromFileSystemRepresentation怎麽用?C++ CFURLCreateFromFileSystemRepresentation使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFURLCreateFromFileSystemRepresentation函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: CFCopySearchPathForDirectoriesInDomains
CFArrayRef CFCopySearchPathForDirectoriesInDomains(CFSearchPathDirectory directory, CFSearchPathDomainMask domainMask, Boolean expandTilde) {
CFMutableArrayRef array;
CFSearchPathEnumerationState state;
CFIndex homeLen = -1;
char cPath[CFMaxPathSize], home[CFMaxPathSize];
array = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeArrayCallBacks);
state = __CFStartSearchPathEnumeration(directory, domainMask);
while ((state = __CFGetNextSearchPathEnumeration(state, (uint8_t *)cPath, sizeof(cPath)))) {
CFURLRef url = NULL;
if (expandTilde && (cPath[0] == '~')) {
if (homeLen < 0) {
CFURLRef homeURL = CFCopyHomeDirectoryURLForUser(NULL);
if (homeURL) {
CFURLGetFileSystemRepresentation(homeURL, true, (uint8_t *)home, CFMaxPathSize);
homeLen = strlen(home);
CFRelease(homeURL);
}
}
if (homeLen + strlen(cPath) < CFMaxPathSize) {
home[homeLen] = '\0';
strlcat(home, &cPath[1], sizeof(home));
url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)home, strlen(home), true);
}
} else {
url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)cPath, strlen(cPath), true);
}
if (url) {
CFArrayAppendValue(array, url);
CFRelease(url);
}
}
return array;
}
示例2: _CFCopyHomeDirURLForUser
// Set the fallBackToHome parameter to true if we should fall back to the HOME environment variable if all else fails. Otherwise return NULL.
static CFURLRef _CFCopyHomeDirURLForUser(const char *username, bool fallBackToHome) {
const char *fixedHomePath = issetugid() ? NULL : __CFgetenv("CFFIXED_USER_HOME");
const char *homePath = NULL;
// Calculate the home directory we will use
// First try CFFIXED_USER_HOME (only if not setugid), then fall back to the upwd, then fall back to HOME environment variable
CFURLRef home = NULL;
if (!issetugid() && fixedHomePath) home = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)fixedHomePath, strlen(fixedHomePath), true);
if (!home) {
struct passwd *upwd = NULL;
if (username) {
upwd = getpwnam(username);
} else {
uid_t euid;
__CFGetUGIDs(&euid, NULL);
upwd = getpwuid(euid ?: getuid());
}
if (upwd && upwd->pw_dir) {
home = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)upwd->pw_dir, strlen(upwd->pw_dir), true);
}
}
if (fallBackToHome && !home) homePath = __CFgetenv("HOME");
if (fallBackToHome && !home && homePath) home = CFURLCreateFromFileSystemRepresentation(kCFAllocatorSystemDefault, (uint8_t *)homePath, strlen(homePath), true);
return home;
}
示例3: main
int main (int argc, const char * argv[]) {
const char *inputFileName = NULL;
char *outputFileName = NULL;
CFURLRef inURL = NULL;
if(argc != 2){
fprintf(stderr, "Usage: %s [inputfile] \n", argv[0]);
return 1;
}
inputFileName = argv[1];
fprintf(stdout, "Beginning Document \"%s\"\n", inputFileName);
inURL = CFURLCreateFromFileSystemRepresentation(NULL, inputFileName,
strlen(inputFileName), false);
if(!inURL){
fprintf(stderr, "Couldn't create URL for input file!\n");
return 1;
}
dumpPageStreams(inURL, stdout);
CFRelease(inURL);
return 0;
}
示例4: CFURLCreateFromFileSystemRepresentation
bool ofxAudioUnitFilePlayer::setFile(const std::string &filePath) {
CFURLRef fileURL;
fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
(const UInt8 *)filePath.c_str(),
filePath.length(),
NULL);
if(_fileID[0]) {
AudioFileClose(_fileID[0]);
_fileID[0] = NULL;
}
OSStatus s = AudioFileOpenURL(fileURL, kAudioFileReadPermission, 0, _fileID);
CFRelease(fileURL);
_primed = false;
if(s != noErr) {
cout << "Error " << s << " while opening file at " << filePath << endl;
return false;
} else {
// setting the file ID now since it seems to have some overhead.
// Doing it now ensures you'll get sound pretty much instantly after
// calling play() (subsequent calls don't have the overhead)
OFXAU_RET_BOOL(AudioUnitSetProperty(*_unit,
kAudioUnitProperty_ScheduledFileIDs,
kAudioUnitScope_Global,
0,
_fileID,
sizeof(_fileID)),
"setting file player's file ID");
}
}
示例5: CFDataCreate
//-----------------------------------------------------------------------------
int C700::CreatePGDataDic(CFDictionaryRef *data, int pgnum)
{
CFMutableDictionaryRef dict = CFDictionaryCreateMutable (NULL, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
const InstParams *vpSet = mEfx->GetVP();
if (vpSet[pgnum].loop) {
vpSet[pgnum].brr.data[vpSet[pgnum].brr.size - 9] |= 2;
}
else {
vpSet[pgnum].brr.data[vpSet[pgnum].brr.size - 9] &= ~2;
}
CFDataRef brrdata = CFDataCreate(NULL, vpSet[pgnum].brr.data, vpSet[pgnum].brr.size);
CFDictionarySetValue(dict, kSaveKey_brrdata, brrdata);
CFRelease(brrdata);
AddNumToDictionary(dict, kSaveKey_looppoint, vpSet[pgnum].lp);
CFNumberRef num = CFNumberCreate(NULL, kCFNumberDoubleType, &vpSet[pgnum].rate);
CFDictionarySetValue(dict, kSaveKey_samplerate, num);
CFRelease(num);
AddNumToDictionary(dict, kSaveKey_basekey, vpSet[pgnum].basekey);
AddNumToDictionary(dict, kSaveKey_lowkey, vpSet[pgnum].lowkey);
AddNumToDictionary(dict, kSaveKey_highkey, vpSet[pgnum].highkey);
AddNumToDictionary(dict, kSaveKey_ar, vpSet[pgnum].ar);
AddNumToDictionary(dict, kSaveKey_dr, vpSet[pgnum].dr);
AddNumToDictionary(dict, kSaveKey_sl, vpSet[pgnum].sl);
AddNumToDictionary(dict, kSaveKey_sr, vpSet[pgnum].sr);
AddBooleanToDictionary(dict, kSaveKey_SustainMode, vpSet[pgnum].sustainMode);
AddNumToDictionary(dict, kSaveKey_volL, vpSet[pgnum].volL);
AddNumToDictionary(dict, kSaveKey_volR, vpSet[pgnum].volR);
AddBooleanToDictionary(dict, kSaveKey_echo, vpSet[pgnum].echo);
AddNumToDictionary(dict, kSaveKey_bank, vpSet[pgnum].bank);
AddBooleanToDictionary(dict, kSaveKey_MonoMode, vpSet[pgnum].monoMode);
AddBooleanToDictionary(dict, kSaveKey_PortamentoOn, vpSet[pgnum].portamentoOn);
AddNumToDictionary(dict, kSaveKey_PortamentoRate, vpSet[pgnum].portamentoRate);
AddNumToDictionary(dict, kSaveKey_NoteOnPriority, vpSet[pgnum].noteOnPriority);
AddNumToDictionary(dict, kSaveKey_ReleasePriority, vpSet[pgnum].releasePriority);
//元波形情報
AddBooleanToDictionary(dict, kSaveKey_IsEmphasized, vpSet[pgnum].isEmphasized);
if ( vpSet[pgnum].sourceFile[0] ) {
CFURLRef url =
CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)vpSet[pgnum].sourceFile,
strlen(vpSet[pgnum].sourceFile), false);
CFDataRef urlData = CFURLCreateData( NULL, url, kCFStringEncodingUTF8, false );
CFDictionarySetValue(dict, kSaveKey_SourceFile, urlData);
CFRelease(urlData);
CFRelease(url);
}
//プログラム名
if (vpSet[pgnum].pgname[0] != 0) {
CFStringRef str = CFStringCreateWithCString(NULL, vpSet[pgnum].pgname, kCFStringEncodingUTF8);
CFDictionarySetValue(dict, kSaveKey_ProgName, str);
CFRelease(str);
}
*data = dict;
return 0;
}
示例6: mBundle
MDSAttrParser::MDSAttrParser(
const char *bundlePath,
MDSSession &dl,
CSSM_DB_HANDLE objectHand,
CSSM_DB_HANDLE cdsaDirHand) :
mBundle(NULL),
mPath(NULL),
mDl(dl),
mObjectHand(objectHand),
mCdsaDirHand(cdsaDirHand),
mGuid(NULL),
mDefaults(NULL)
{
/* Only task here is to cook up a CFBundle for the specified path */
unsigned pathLen = strlen(bundlePath);
CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL,
(unsigned char *)bundlePath,
pathLen,
false);
if(url == NULL) {
Syslog::alert("CFURLCreateFromFileSystemRepresentation(%s) failure", mPath);
CssmError::throwMe(CSSMERR_DL_INVALID_DB_NAME);
}
/* FIXME - this leaks 28 bytes each time thru, even though we CFRelease the
* mBundle in out destructor. I think this is a CF leak. */
mBundle = CFBundleCreate(NULL, url);
CFRelease(url);
if(mBundle == NULL) {
Syslog::alert("CFBundleCreate(%s) failure", mPath);
CssmError::throwMe(CSSMERR_DL_INVALID_DB_NAME);
}
mPath = new char[pathLen + 1];
strcpy(mPath, bundlePath);
}
示例7: impExpImportDeleteExtension
/* do a [NSString stringByDeletingPathExtension] equivalent */
CFStringRef impExpImportDeleteExtension(
CFStringRef fileStr)
{
CFDataRef fileStrData = CFStringCreateExternalRepresentation(NULL, fileStr,
kCFStringEncodingUTF8, 0);
if(fileStrData == NULL) {
return NULL;
}
CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(NULL,
CFDataGetBytePtr(fileStrData), CFDataGetLength(fileStrData), false);
if(urlRef == NULL) {
CFRelease(fileStrData);
return NULL;
}
CFURLRef rtnUrl = CFURLCreateCopyDeletingPathExtension(NULL, urlRef);
CFStringRef rtnStr = NULL;
CFRelease(urlRef);
if(rtnUrl) {
rtnStr = CFURLGetString(rtnUrl);
CFRetain(rtnStr);
CFRelease(rtnUrl);
}
CFRelease(fileStrData);
return rtnStr;
}
示例8: diskarb_unmount
int diskarb_unmount( const char * dir, int flags )
{
int status;
status = -1;
if ( dir )
{
DASessionRef session;
session = DASessionCreate( kCFAllocatorDefault );
if ( session )
{
CFURLRef path;
path = CFURLCreateFromFileSystemRepresentation( kCFAllocatorDefault, ( void * ) dir, strlen( dir ), TRUE );
if ( path )
{
DADiskRef disk;
disk = DADiskCreateFromVolumePath( kCFAllocatorDefault, session, path );
if ( disk )
{
DADiskUnmountOptions options;
options = kDADiskUnmountOptionDefault;
if ( ( flags & MNT_FORCE ) )
{
options |= kDADiskUnmountOptionForce;
}
DASessionScheduleWithRunLoop( session, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );
DADiskUnmount( disk, options, __diskarb_unmount, &status );
if ( status == -1 )
{
CFRunLoopRun( );
}
status = status ? -1 : 0;
DASessionUnscheduleFromRunLoop( session, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode );
CFRelease( disk );
}
CFRelease( path );
}
CFRelease( session );
}
}
return status;
}
示例9: CFStringGetCString
CFPropertyListRef Resources::getPropertyList(const char* filename)
{
CFDataRef xmlCFDataRef;
CFStringRef error;
char cerror[10240];
CFPropertyListRef myCFPropertyListRef = NULL;
Boolean readOK;
char filePathBuf[PATH_MAX];
CFStringRef filePath = this->getResourcePath(filename);
CFStringGetCString(filePath, filePathBuf, sizeof(filePathBuf), kCFStringEncodingUTF8);
CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const unsigned char*)filePathBuf, strlen (filePathBuf), false);
if (fileURL!=NULL) {
readOK = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, fileURL, &xmlCFDataRef, NULL, NULL, NULL);
if (readOK)
{
myCFPropertyListRef = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, xmlCFDataRef, kCFPropertyListImmutable, &error);
if (error != NULL){
CFStringGetCString(error, cerror, sizeof(cerror), kCFStringEncodingUTF8);
scprintf("getPropertyList error: %s\n", cerror);
}
CFRelease(xmlCFDataRef);
}
else{
scprintf("Couldn't read Plist File %s\n", filePathBuf);
}
}
return myCFPropertyListRef;
}
示例10: examine_bundle
/* Examines a directory, treating it as a bundle, and determines whether it has an executable.
* Examines the executable as a regular file to determine which architectures it matches.
* Prints out the results.
*/
static void examine_bundle(const uint8_t *bundle_path) {
CFURLRef bundleURL = CFURLCreateFromFileSystemRepresentation(NULL, bundle_path, strlen((const char *)bundle_path), true), executableURL = NULL;
CFBundleRef bundle = NULL;
uint8_t path[PATH_MAX];
struct stat statBuf;
if (bundleURL && (bundle = CFBundleCreate(NULL, bundleURL))) {
// Try to obtain a path to an executable within the bundle.
executableURL = CFBundleCopyExecutableURL(bundle);
if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, path, PATH_MAX) && stat((const char *)path, &statBuf) == 0) {
// Make sure it is a regular file, and if so examine it as a regular file.
if ((statBuf.st_mode & S_IFMT) == S_IFREG) {
examine_file(path);
} else {
printf("Unsupported file type for file %s.\n", path);
}
} else {
printf("No executable located for %s.\n", bundle_path);
}
} else {
printf("Cannot read %s.\n", bundle_path);
}
if (executableURL) CFRelease(executableURL);
if (bundle) CFRelease(bundle);
if (bundleURL) CFRelease(bundleURL);
}
示例11: CFURLCreateFromFileSystemRepresentation
QImage FileImageProvider::image(const QFileInfo &info, const QSize size) const
{
QImage result;
#ifdef Q_OS_MAC
QString path = info.absoluteFilePath();
CGSize s;
s.width = size.width();
s.height = size.height();
CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
(const UInt8*)path.toUtf8().data(),
path.length(),
true);
if (url) {
CGImageRef image = QLThumbnailImageCreate(kCFAllocatorDefault, url, s, 0);
if (image) {
// result = QPixmap::fromMacCGImageRef(image).toImage();
// CFRelease(image);
}
CFRelease(url);
}
#else
#endif
if (result.isNull())
result = icon(info).pixmap(size).toImage();
return result;
}
示例12: _CFXBundleCreateFromImageName
static CFBundleRef _CFXBundleCreateFromImageName (CFAllocatorRef allocator, const char* image_name)
{
CFURLRef myBundleExecutableURL = CFURLCreateFromFileSystemRepresentation (allocator, (const unsigned char*)image_name, strlen (image_name), false);
if (myBundleExecutableURL == 0)
return 0;
CFURLRef myBundleContentsMacOSURL = CFURLCreateCopyDeletingLastPathComponent (allocator, myBundleExecutableURL); // Delete Versions/Current/Executable
CFRelease (myBundleExecutableURL);
if (myBundleContentsMacOSURL == 0)
return 0;
CFURLRef myBundleContentsURL = CFURLCreateCopyDeletingLastPathComponent (allocator, myBundleContentsMacOSURL); // Delete Current
CFRelease (myBundleContentsMacOSURL);
if (myBundleContentsURL == 0)
return 0;
CFURLRef theBundleURL = CFURLCreateCopyDeletingLastPathComponent (allocator, myBundleContentsURL); // Delete Versions
CFRelease (myBundleContentsURL);
if (theBundleURL == 0)
return 0;
CFBundleRef result = CFBundleCreate (allocator, theBundleURL);
CFRelease (theBundleURL);
return result;
}
示例13: CGImageRelease
bool ImageIODecoder::readHeader()
{
CFURLRef imageURLRef;
CGImageSourceRef sourceRef;
// diciu, if ReadHeader is called twice in a row make sure to release the previously allocated imageRef
if (imageRef != NULL)
CGImageRelease(imageRef);
imageRef = NULL;
imageURLRef = CFURLCreateFromFileSystemRepresentation( NULL,
(const UInt8*)m_filename.c_str(), m_filename.size(), false );
sourceRef = CGImageSourceCreateWithURL( imageURLRef, NULL );
CFRelease( imageURLRef );
if ( !sourceRef )
return false;
imageRef = CGImageSourceCreateImageAtIndex( sourceRef, 0, NULL );
CFRelease( sourceRef );
if( !imageRef )
return false;
m_width = CGImageGetWidth( imageRef );
m_height = CGImageGetHeight( imageRef );
CGColorSpaceRef colorSpace = CGImageGetColorSpace( imageRef );
if( !colorSpace )
return false;
m_type = CGColorSpaceGetNumberOfComponents( colorSpace ) > 1 ? CV_8UC3 : CV_8UC1;
return true;
}
示例14: _CFCopyHomeDirURLForUser
static CFURLRef _CFCopyHomeDirURLForUser(struct passwd *upwd) {
CFURLRef home = NULL;
if (upwd && upwd->pw_dir) {
home = CFURLCreateFromFileSystemRepresentation(NULL, upwd->pw_dir, strlen(upwd->pw_dir), true);
}
return home;
}
示例15: getBundleVersion
char* getBundleVersion(const char* bundlePath) {
CFURLRef bundlePackageURL = NULL;
bundlePackageURL = CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault,
(const UInt8*)bundlePath,
strlen(bundlePath),
true);
assert(bundlePackageURL);
CFBundleRef bundle = NULL;
bundle = CFBundleCreate(kCFAllocatorDefault, bundlePackageURL);
assert(bundle);
CFStringRef versionStr = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(
bundle, kCFBundleVersionKey);
int length = CFStringGetLength(versionStr)+1;
char* ret = (char*)malloc(length);
Boolean v = CFStringGetCString(versionStr, ret, length, kCFStringEncodingASCII);
assert(v);
CFRelease(bundle);
CFRelease(bundlePackageURL);
return ret;
}