[futurebasic] alias of self

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2001 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <wedwards@...>
Date: Sun, 25 Mar 2001 14:56:34 -0500
Maybe someone has an answer for this one.  I want to give the user the
option of having the program launch at OS startup. I attempt to create an
alias file of my application in the startup folder.  To do this you would
have to create a resource file, set the alias bit and create an 'alis'
resource ID 0 of the target file.  The only thing that I've been successful
at doing is placing the file in the startup folder.

Does anyone see whats wrong with what I'm doing. 


W.



_isAlias       = bit(15) // findInfo bit

CLEAR LOCAL
LOCAL FN fileExists(fName$,fVol)
'~'
DIM fileExists
DIM pBlk.ioHFQElSiz

pBlk.ioVRefNum%  = fVol
pBlk.ioNamePtr& = @fName$
LONG IF FN HGETFILEINFO(@pBlk) = _noErr
fileExists = (pBlk.iocompletion% = _noErr)
XELSE
fileExists = _false
END IF

END FN = fileExists


/*
begin record FInfo
dim fdType&//the type of the file//
dim fdCreator&//file's creator//
dim fdFlags%//flags ex. hasbundle,invisible,locked, etc.//
dim fdLocation&//file's location in folder -- pixel position as point//
dim fdFldr%//folder containing file//
end record
*/

register off
LOCAL FN SetFileAttribToAlias(fileSpec as ptr to fsspec)
register on
DIM iErr%
dim fInfoRec as FInfo

// purpose is to set the "alias" finder bit on file so
// the finder recognizes the file as an alias

iErr% = fn FSpGetFInfo(fileSpec, fInfoRec)
fInfoRec.fdFlags = fInfoRec.fdFlags OR _isAlias
iErr% = fn FSpsetFInfo(fileSpec, fInfoRec)
long if iErr%
stop str$(iErr%)
end if
END FN = iErr%


CLEAR LOCAL MODE
LOCAL FN getParID(fName$,fVRefNum)
DIM pBlk&,paramBlock$,OSErr

//  Return a folder's parent ID.

pBlk& = @paramBlock$
& pBlk& + _ioNamePtr  ,@fName$
% pBlk& + _ioVRefNum  ,fVRefNum
% pBlk& + _ioFDirIndex,0
OSErr = FN GETCATINFO(pBlk&)
END FN = [pBlk& + _ioFLParID]


CLEAR LOCAL
DIM   pBlk.80
dim   aliasName$,appName$
DIM   aliasSpec      as fsSpec
DIM   targetSpec     as fsSpec
dim   targVol,targDirID&
dim @ aplDirID&,dirID&
DIM @ vRef%,resRef%,aplVRef%, err
DIM @ fromFile, aHndl&
LOCAL FN startAliasPref(placeInStartup)

// purpose is to make an alias of self in the
// startup folder.  This could be modified to 
// handle more than just an application.

// aliasSpec is the file spec of the intended alias file
// targetSpec is the this application

resRef%  = 0
fromFile = 0

LONG IF  FN FINDFOLDER (_kOnSystemDisk, _kStartupFolderType,
_kDontCreateFolder, vRef%, dirID&) = _noErr

// if the user renames the application this will still work
appName$   = PSTR$(_curApName)
aliasName$ = appName$ + " alias"
targVol    = system(_aplVol)
targDirID& = FN getParID(appName$,targVol)

long if FN fileExists(appName$,vRef%)
// ALWAYS delete the existing alias file
// if user wants app to startup then the
// following flag will create the alias
// in the startup folder
kill appName$, vRef%, dirID&
end if

long if placeInStartup// if user wants to start app on OS startup
err = FN FSMakeFSSpec(targVol,targDirID&,appName$,targetSpec)
err = FN FSMakeFSSpec(vRef%,dirID&,aliasName$,aliasSpec)

LONG IF err = _FNFerr
call FSpCreateResFile(aliasSpec,_"FB3!",_"adrp",_smSystemScript)
// _"adrp" is application alias
resRef% = FN FSPOPENRESFILE(aliasSpec,_fsRdWrShPerm)

LONG IF FN NEWALIAS(fromFile,targetSpec,aHndl&)
// error, alias was not created
XELSE
call addresource(aHndl&,_"alis",0,aliasSpec.name$)
// we can just add because we are the top resource file
END IF

xelse
// problem with the filespec
END IF
END IF
end if

long if resRef%
call closeresfile(resRef%)
FN SetFileAttribToAlias(aliasSpec)// set the alias bit
end if
END FN

FN startAliasPref(_true)
// if true then place an alias of self in startup folder


// no need to stick around, just quit