CFURLCreateBookmarkDataFromAliasRecord() does not create bookmark data with the kCFURLBookmarkCreationSuitableForBookmarkFile parameter required by CFURLWriteBookmarkDataToFile() .
CFURLCreateBookmarkDataFromAliasRecord() was intended as a way to convert alias entries storing files of the program’s own files to bookmarks without I / O.
Prior to CFURLWriteBookmarkDataToFile() Finder Alias files (bookmark files) were created by Finder. These files contained an Alias resource (containing known properties that could be obtained from an Alias resource using FSCopyAliasInfo() ) and icon resources. Apple required bookmark data in files written by CFURLWriteBookmarkDataToFile() to provide the same properties. The kCFURLBookmarkCreationSuitableForBookmarkFile option ensures that this requirement is met.
If you have AliasHandle and want to create a new style alias file with bookmark data, you need to:
(1) enable AliasHandle on FSRef , create CFURLRef from FSRef , and then create bookmark data using the kCFURLBookmarkCreationSuitableForBookmarkFile parameter,
or
(2) you will need to enable bookmark data created using CFURLCreateBookmarkDataFromAliasRecord() , and then create new bookmark data using the kCFURLBookmarkCreationSuitableForBookmarkFile parameter.
However, you indicated that you want to handle this without the permission of AliasHandle , so the only solution is to create an old-style Finder Alias alias file. Although I know that you already know how to do this, see How to create an alias Finder in an application? .
The first time a user allows / opens this old-style Alias file with Finder, Finder discovers that the Alias file needs updating (i.e. CFURLCreateByResolvingBookmarkData() will return with isStale == true ), and Finder will create a new bookmark in the target Alias file and overwrite the Alias file. CFURLCreateBookmarkDataFromFile() will continue to support old-style alias files for as long as possible for backward compatibility.
Jim luther
source share