[futurebasic] Re: [FB] Making an alias

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2010 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Fri, 12 Feb 2010 11:01:44 -0700
On Feb 12, 2010, at 8:29 AM, Jay Reeve wrote:

> I can't find any examples showing how I might do that. Is there one?


Jay - two items:

(1) here are two snippets( LoadAlias/SaveAlias ) to get you going.  
This is not a running demo, so please note the comments.

(2) Using CFPrefs ( utilizing Util_CFPrefs.incl - in Headers ) is the  
easiest way to save and retrieve the handle but you could write your  
own code to do the CFDataGetBytes() etc. The stock version of  
Util_CFPrefs.incl can be supplemented with two functions ( see further  
down - originals from B.W. ) to save/retrieve the handle.


'-------------
local fn LoadAlias( fsRef as ^FSRef )
'~'1
dim as ^^AliasRecord     h
dim as Boolean           wasChanged

// do your work here to load the alias into the handle *before*  
calling FSResolveAlias

fn FSResolveAlias( #0, h, #fsRef, @wasChanged )


end fn


local fn SaveAlias( fsRef as ^FSRef )
'~'1
dim as handle     h

// The FSRef passed represents the data file for which an alias needs  
to be created
// FSNewAlias returns a handle ( in 'h' ) to the new alias that has  
been created

long if ( fn FSNewAlias( #0, #fsRef, @h ) == _noErr )
// do your work here to save the alias stored in the handle
end if
end fn
'------------------------



//  These are the additional functions that rely on Util_CFPrefs.incl  
to save/retrieve the handle
local mode
local fn CFPrefsSetFSRef( key as Str255, fsRef as ^FSRef )
'~'1
dim as Handle  h

h = 0
long if ( fn FSNewAlias( #0, #fsRef, @h ) == _noErr )
fn CFPrefsSetHandle( key, h )
DisposeHandle( h )
end if
end fn

local mode
local fn CFPrefsGetFSRef( key as Str255, @fsRef as ^FSRef )
'~'1
dim as ^^AliasRecord  h
dim as Boolean    fromPrefs, @ wasChanged

h = 0
fromPrefs = fn CFPrefsGetHandle( key, @h )
long if ( fromPrefs )
if ( fn FSResolveAlias( #0, h, #fsRef, @wasChanged ) ) then fromPrefs  
= _false
fn DisposeH ( h )
end if
end fn = fromPrefs



Brian S