Replacing a stack

Shari shari at gypsyware.com
Thu Oct 25 00:02:19 EDT 2007


>I'll definitely post any updates.  I always try to post my final 
>solution when I ask a question, so that folks searching the archives 
>someday can find it :-)

Okay, here's the working solution.  I did not end up using revert, as 
it prevented the application from loading.  Maybe revert can't be 
used before any stacks have opened and you are in the startup 
preOpenStack routine?  I don't know.  But I had to take it out. 
Here's what finally worked for me:

In a stack with a button with no other purpose but to compress stacks 
and store them as custom properties of other stacks:

on mouseUp

   answer file "Select a stack to store compressed data such as 
yourMainStack.mc"
# yourMainStack.mc has a latestPrefsVersion custom property
   if it is empty then exit to top
   put it into storageStack

   answer file "Select a stack to compress such as prefStack.mc:"
# prefStack.mc has a currentPrefsVersion custom property
   if it is empty then exit to top
   put it into stackToShrink

   put url ("binfile:" & stackToShrink) into s

   set the stackData of stack storageStack to compress(s)
   save stack storageStack

   beep

end mouseUp


If you have multiple stacks that might need to be replaced, you will 
need to version each replaceable stack, I am using custom properties. 
This allows you to independantly replace a stack.  For example, if 
your application is versioned 12, but the prefStack is versioned 10, 
you might not need or want to replace the prefStack.  So you don't 
compare the prefStack version to your main app version, but to the 
prefStack that is compressed inside of your app, assuming someone 
always downloads a completely new app when they upgrade.  Rather than 
decompress the stack and check the version, create a custom property 
in the main app for each replaceable stack, and check against it.

In your startUp routine where you check versions, and replace a stack 
if the compressed custom property is a newer version:

   put the latestPrefsVersion of stack primaryAppStack into newV
   put the currentPrefsVersion of stack prefStack into oldV # UserPrefs
   if oldV is not a number then # for legacy, older stacks weren't versioned
     put 1 into oldV
   end if
   if newV > oldV then
     if "UserPrefs" is in the stacksInUse then
       stop using stack "UserPrefs"
     end if
     if "UserPrefs" is in the openstacks then
       close stack "UserPrefs"
     end if
     delete stack "UserPrefs"
     delete file prefStack
     # if you are using a custom filetype or stackFileType
# set your fileType or stackFileType before decompressing
     put decompress(the stackData of stack yourMainStack.mc) \
         into url ("binfile:" & prefStack)

Final note:  Once I moved the prefStack out of the main application 
folder into a preferences folder somewhere else on the user's 
computer, I encountered another problem that caused me grief.  If I 
edited the stack via "go stack prefStack", I was editing not the 
stack that gets compressed and distributed with the program, but the 
stack that is created in the Preferences folder somewhere.  Now my 
app checks for the environment and loads a stack accordingly.  Only 
if it's a standalone does it launch the prefStack in the Preferences 
folder somewhere, otherwise it launches the prefStack that is in the 
same folder as the app during development.  The one that gets 
compressed into a custom property.

-- 
WlND0WS and MAClNT0SH shareware games
BIackjack GoId
http://www.gypsyware.com



More information about the use-livecode mailing list