Create Bookmark File from Mac Alias ​​Classic Record

For an application that has existed for many years and that has kept classic alias entries in files, I like to recreate Alias ​​files pointing to the same file without having to transfer the alias first (since the destination may not be available at this point).

Presumably this should do the following:

CFDataRef aliasRecord = ... ; // contains the Alias Record data, see below for an example CFURLRef url = ... ; // initialized with a file URL CFDataRef bmData = CFURLCreateBookmarkDataFromAliasRecord (NULL, aliasRecord); CFError error; bool ok = CFURLWriteBookmarkDataToFile (bmData, url, 0, &error); 

However, the recording function does not work, and the error says: "File cannot be saved."

If you use CreateBookmarkData instead of creating bookmark data, the write will succeed.

How do I do this job? I would try to write an old Alias ​​file with data in the fork resource if it weren’t so categorical.

Here is an example of aliases that I would have in an aliasRecord object - I can solve this using the classic Alias ​​Manager function FSResolveAlias , so I know that it really is.

 00 00 00 00 01 12 00 02 00 01 06 54 54 73 4D 42 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 CC 31 2F 12 48 2B 00 00 01 A5 F3 9B 03 74 6D 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 AC 1C 67 D1 FE B7 D0 00 00 00 00 00 00 00 00 FF FF FF FF 00 00 09 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 70 72 69 76 61 74 65 00 00 10 00 08 00 00 CC 31 12 F2 00 00 00 11 00 08 00 00 D1 FE 9B B0 00 00 00 01 00 04 01 A5 F3 9B 00 02 00 13 54 54 73 4D 42 50 3A 70 72 69 76 61 74 65 3A 00 74 6D 70 00 00 0E 00 08 00 03 00 74 00 6D 00 70 00 0F 00 0E 00 06 00 54 00 54 00 73 00 4D 00 42 00 50 00 12 00 0B 70 72 69 76 61 74 65 2F 74 6D 70 00 00 13 00 01 2F 00 FF FF 00 00 
+1
carbon macos
source share
1 answer

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.

+3
source share

All Articles