Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
set FileType And Creator on i386 x86_64
//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
You can’t perform that action at this time.