[futurebasic] Re: [FB] Storing program information

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Mon, 13 Oct 2008 11:07:03 +1300
Joe Lertola wrote:

> Today I was fixing some problems I am having with accessing files  
> that are stored in the same folder as the application bundle. This  
> got me wondering if I am storing my program's information in the  
> wrong places. My program makes resource files to save database and  
> coloring information. At the moment I have the program save these  
> files in the same folder as the application folder. Is this OK or  
> should I save them in a different place? If so where should they go?
>
> Another question is about saving registration information. I have  
> been storing program registration information in the application  
> bundle so that if the user moved the program to a different computer  
> it would still be registered and the program would not nag for a  
> registration number. But Ken Shmidheiser once advised me not to  
> write files to the applications bundle because the application might  
> be on a read only volume. Where should I store registration  
> information not in the bundle?
>
> My program makes large temporary files while it is processing and  
> then deletes them when it is done processing. At the moment I save  
> these temporary files either in the same folder where the user has  
> chosen to save the final file or in the same folder as the  
> application if no file is being saved. I think this is probably a no- 
> no. Where should I store temporary files while the program works?


The usual place for app data is the user's Application Support folder  
(~/Library/Application Support/).

_kUserDomain = -32763
_kApplicationSupportFolderType = _"asup"
err = fn FindFolder( _kUserDomain, _kApplicationSupportFolderType,  
_kCreateFolder, @vRefNum, @dirID )
Then create a folder "MyApp" and put your data files in it.

For temporary files I use
_kChewableItemsFolderType = _"flnt"
err = fn FindFolder( _kUserDomain, _kChewableItemsFolderType,  
_kCreateFolder, @vRefNum, @dirID )


Users without admin rights cannot create files in the Applications  
folder (or inside an app in that folder).
Build the app below, put it in Applications folder, log out, then log  
in to a non-admin account and run the app.

'-------------
// open "O"... with error checking instead of the dreaded file error  
alert
local mode
local fn SafeOpenO( fbFileNum as long, fileSpec as ^FSSpec )
'~'1
dim as FSSpec localCopy // for 'open' statement
dim as OSStatus err

localCopy = fileSpec
on error end
error = _noErr
open "O", fbFileNum, @localCopy
err = error
error = _noErr
on error return
end fn = err

dim as FSSpec spec
dim as OSStatus err
err = fn FSMakeFSSpec( system( _aplVRefNum ), system( _aplParID ),  
"MyTest", @spec )
if ( err == _fnfErr ) then err = _noErr
if ( err == _noErr ) then err = fn SafeOpenO( 1, spec )
long if ( err )
stop "Could not create file"
xelse
stop "Created file MyTest"
end if
'-------------

Robert P.