Created
August 3, 2011 11:33
-
-
Save hetima/1122416 to your computer and use it in GitHub Desktop.
set FileType And Creator on i386 x86_64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//i386 x86_64用 | |
//needs CoreServices.framework | |
BOOL setFileTypeAndCreator(NSString* asFilePath, const char* typeStr, const char* creatorStr); | |
UInt32 OSTypeFromString(const char* inStr); | |
UInt32 OSTypeFromString(const char* inStr) | |
{ | |
UInt32 outType; | |
char *buff; | |
if(strlen(inStr)!=4){ | |
outType=0; | |
}else{ | |
buff=(char*)&outType; | |
*(buff)=*(inStr+3); | |
*(buff+1)=*(inStr+2); | |
*(buff+2)=*(inStr+1); | |
*(buff+3)=*(inStr); | |
} | |
return outType; | |
} | |
BOOL setFileTypeAndCreator(NSString* asFilePath, const char* typeStr, const char* creatorStr){ | |
BOOL result=NO; | |
UInt32 fType=OSTypeFromString(typeStr); | |
UInt32 fCreator=OSTypeFromString(creatorStr); | |
FSRef fRef; | |
FSCatalogInfo catInfo; | |
FInfo *finderInfo = (FInfo *)&(catInfo.finderInfo); | |
CFURLRef url; | |
//LOG(@"%s,%s=%d,%d",typeStr,creatorStr,fType,fCreator); | |
url=CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)asFilePath, kCFURLPOSIXPathStyle, false); | |
if(CFURLGetFSRef(url, &fRef)){ | |
if (FSGetCatalogInfo(&fRef, kFSCatInfoFinderInfo, &catInfo, NULL, NULL, NULL) == noErr){ | |
finderInfo->fdCreator = fCreator; | |
finderInfo->fdType = fType; | |
//if(fCreator==0)finderInfo->fdFlags &= ~kHasBeenInited; | |
if (FSSetCatalogInfo(&fRef, kFSCatInfoFinderInfo, &catInfo)==noErr) { | |
result=YES; | |
} | |
} | |
CFRelease(url); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment