Preferred Multi-Platform Development Method
Derek Bump
userevolution at dreamscapesoftware.com
Fri May 8 18:58:53 EDT 2009
Hello David,
I ran into the same problem with Preferences and the Registry when I
started porting my software to Mac. Since I fully intended to
eventually port my software to Linux as well, I figured it would be a
good idea to move away from using the Registry and any "system-specific"
mechanisms.
I accomplished this by creating a handler that loads a preferences
stack, that is encrypted. You can view the handler here...
on doLoadPreferences
-- Save the Default Stack
put the defaultStack into cDefaultStack
-- Determine the Location of the Preferences based on the Operating
System
if platform() = "MacOS" then
put specialFolderPath("Preferences") & "/MyProgram/" into
myPreferences
else if platform() = "Win32" then
put specialFolderPath("0x001a") & "/MyProgram/" into myPreferences
else
put specialFolderPath("Home") & "/.MyProgram/" into myPreferences
end if
-- Create the Preferences File
if there is not a folder myPreferences then create folder myPreferences
put myPreferences & "Preferences.dss" into myPreferences
if there is not a file myPreferences then
create invisible stack "myPreferences"
set the password of stack "myPreferences" to "MyPassword"
save stack "myPreferences" as myPreferences
else
go invisible stack myPreferences
end if
-- Some Fine Tuning
hide stack "myPreferences"
set the passKey of stack "myPreferences" to "MyPassword"
set the defaultStack to cDefaultStack
end doLoadPreferences
The hander creates a preference "stack" if needed, and places it in the
appropriate location for each operating system. It also loads the
Preferences stack into memory, and decrypts it so it can be modified.
Then, I created my own versions of the queryRegistry() and getRegistry()
functions...
function doGetPref prefName
if there is a stack "myPreferences" then
put the prefName of stack "myPreferences" into theResult
return theResult
else
return "Error: Preferences Unavailable."
end if
end doGetPref
function doSetPref prefName,prefData
if there is a stack "myPreferences" then
set the prefName of stack "myPreferences" to prefData
save stack "myPreferences"
return empty
else
return "Error: Preferences Unavailable."
end if
end doSetPref
This allowed me to stop using the Windows Registry completely, and also
created a fully functional mechanism for creating a Preference file on
any system.
Derek Bump
Dreamscape Software
http://www.dreamscapesoftware.com
___________________________________________________________________
Compress your photos quickly and easily with JPEGCompress 2.9!
http://www.dreamscapesoftware.com/products/jpegcompress/
David Beck wrote:
>
> We are just starting to play around with building stacks for the Mac. We
> have concentrated exclusively on Windows in the past since that is where
> the majority of our user base is. However, I have had many requests for
> a Mac version of the volunteer scheduling software we produce.
>
> I can't believe how easy it looks like it will be to migrate to Mac. I
> tried it the other day and everything just works! It is incredible.
> Working with Rev just keeps getting better and better!
>
> My only question is where to store the preferences that we are storing
> in the Windows Registry. We do have a mechanism to store preferences,
> but there are certain preferences that are system wide, and should not
> change based on the user of the computer (e.g. the install path of a
> standalone application, etc.). Any advice on where to store these global
> system-wide preferences on the Mac?
>
> Richard, I understand you are using a stackfile for preferences. How
> exactly do you implement this? That is, what calls do you use to get and
> set preferences in the stackfile? Does the folder you mentioned
> (specialApplicationFolder("preferences")) change based on the current
> user or is it system wide? Also, are there any permissions issues to be
> careful about?
>
> Thanks very much in advance for any guidance!
>
> --
> David Beck
> Rotunda Software
> www.ministryschedulerpro.com
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list