"Save" in a standalone application

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

"Save" in a standalone application

Post by lohill » Sun Jan 27, 2019 3:28 pm

When I make a standalone application I typically have a "splash" screen that becomes my .exe and another file called MyProgram.livecode. These can be seen as two separate files on a PC and they are part of the .app bundle on the Mac. It is my understanding that while saving changes during the course of running, it is the "MyProgram.livecode" module that gets changed while the .exe remains unchanged.

Unless the program is trivial, the stack that is turned into MyProgram.livecode is really a stack with a number of sub stacks. If I want to make sure that my users always have their fields and datagrids saved when they are finished using the application (i.e. quit) where should I issue the command "save this stack"? If I issue it to the main stack are all others saved as well or does each sub stack need to be told? Also are their inefficiencies involved in one main stack with lots of subs as opposed to multiple stacks with fewer subs?

Thanks,
Larry

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "Save" in a standalone application

Post by Klaus » Sun Jan 27, 2019 3:52 pm

Hi Larry,

since only users with ADMIN privileges are allowed to write (and saving a stack IS writing) in the "Applications"/"Programmes" folder, you need to do this trick and copy your savable stack to the users documents folder and then open and save it right there!

Something like this, guve you have added your stacks via the "Copy files" tab in the "Stanalone Application Settings":

Code: Select all

## Script of splash screen/exe/app:
on openstack
  ## Show Splash:
  wait 2 secs
  ## or whatever...
  
  ## Important line if you want to access all the externals, libs etc from the splah screen stack 
  ## in the other "independant" stack to:
  start using stack "your splash stack"

  ## Where to copy the savable stack to?
  ## We definitively have WRITE permission here:
  put specialfolderpath("documentes") & "/your_savable_stack_here.rev" into tTargetStack  

  ## Stack to copy:
  put specialfolderpath("resources") & "/your_savable_stack_here.rev" into tSourceStack

  ## Only copy the very first time:
  if there is NOT a file tTargetstack then
    put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
  end if

  ## Now:
  go stack tTargetStack
  
   ## Hide your splash here:
   hide stack "your splash stack"
end openstack
Then later you can:

Code: Select all

...
save stack "name_of_savable_stack_here"
...
Best

Klaus

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: "Save" in a standalone application

Post by bogs » Sun Jan 27, 2019 4:09 pm

You understand correctly that you can't save a file that is an executable while it is running on an Os, but the stacks that are launched by it can be saved.

I generally follow the pattern laid out in this article for the basics. As to where to put the 'save this stack', I've never found any place better than the suggestion in this lesson -
How do I save custom properties in a standalone application? wrote: Saving the stack

In order to preserve the custom property cName we need to save our Main Application stack when it is closed. Add the following script to the stack script of the Main Application stack

on closeStack
save this stack
pass closeStack
end closeStack
*Edit - while composing this, Klaus chimed in. I'll defer to him on the workings of a Mac :wink:
Image

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Sun Jan 27, 2019 7:31 pm

Klaus,

Is all this necessary if the person using the program is just putting the standalone in a folder on their desktop or one of their other personal folders?

Also can I expect "save this stack" executed in the main stack to take care of all the saves in the sub stacks automatically or does each sub stack need to get the command as well?

Regards,
Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Sun Jan 27, 2019 7:32 pm

Bogs,

Thanks for the link. I am going to have to spend some time studying it.

Larry

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "Save" in a standalone application

Post by Klaus » Sun Jan 27, 2019 7:43 pm

Hi Larry,
lohill wrote:
Sun Jan 27, 2019 7:31 pm
Is all this necessary if the person using the program is just putting the standalone in a folder on their desktop or one of their other personal folders?
maybe, maybe not, I really would not rely on this! 8)
lohill wrote:
Sun Jan 27, 2019 7:31 pm
Also can I expect "save this stack" executed in the main stack to take care of all the saves in the sub stacks automatically or does each sub stack need to get the command as well?
No, a simple "save stack xxx" will save the main- and all of its substacks, too.

Best

Klaus

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Sun Jan 27, 2019 9:21 pm

No, a simple "save stack xxx" will save the main- and all of its substacks, too.
Thanks Klaus. While I was waiting for you to answer I tried changing my standalone settings to put the sub stacks into individual files with generic names and collect then in a folder. I tried doing this in LC 8.1.9 and LC 9.0.2 with basically the same very interesting results. The compile went smoothly in both versions but the resulting executable most of its datagrids that show only the top line of data. As you scroll down new data gets put in that top line and gives the appearance of having written over what is already there.

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Mon Jan 28, 2019 1:00 am

It took me a while to get a screenshot of what I am seeing but here it is.
Screen Shot 2019-01-27 at 3.56.46 PM.png
Larry

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: "Save" in a standalone application

Post by bogs » Mon Jan 28, 2019 4:38 pm

Hm. I don't have access to a current mac, but you could try this (tested on 'nix).

First I setup the stacks as you see here, the 1 mainStack launcher, and the other mainStack that we'll save information in. The Datagrid template can reside in either, in this case it is in the launcher. Normally, it would be sitting in the launched stack.
Selection_001.png
The setup...
I didn't use the standalone settings to set up the splash / launcher, I did it through this code, which may need to be modified for working/saving on a mac. The launch routine was copied from Andy P.'s post here.

Code: Select all

// in the launcher stack at the card script...
on openStack
// see if we are programming or in a standalone...
   if the environment is "Development" then
      answer "would you like run or exit?" with "Exit" or "Run"
      if it is "Exit" then exit to top
      else
// we continue on with the program...
         set the itemDelimiter to "/"
         get the effective fileName of this stack
         set the defaultFolder to item 1 to -2 of it
         if there is a stack "stkMyData.livecode" then go to stack "stkMyData.livecode"
         wait 2 seconds
         close stack "stkLauncher"
      end if
   end if
end openStack
This is the stack we'll be saving information in and its code, which in the stack script...
Selection_004.png
Saving stack...
And this is what the folder all this is sitting in looks like...
Selection_003.png
The folder...
To make sure it is saving, I'll change Curly to Sue, and then add another entry ...
Image

After closing and opening it, the change and new info is still there.
Image
Last edited by bogs on Mon Jan 28, 2019 4:41 pm, edited 2 times in total.
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: "Save" in a standalone application

Post by bogs » Mon Jan 28, 2019 4:39 pm

Here are the stacks for you to play with - too many attachments in the post above :D
SplashStackWithDatagrid.zip
Splash with Datagrid...
(6.63 KiB) Downloaded 219 times
Image

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "Save" in a standalone application

Post by Klaus » Mon Jan 28, 2019 5:04 pm

Hi friends,

no messing with the DEFAULTFOLDER neccessary, this is why we have specialfolderpath() in LC!
Your script may not work in a Mac standalone!

Code: Select all

...
# set the itemDelimiter to "/"
# get the effective fileName of this stack
# set the defaultFolder to item 1 to -2 of it 
## -> yields to specialfolderpath("engine")!? DEAD WRONG! :-D

## This is how to do it crossplatform:
put specialfolderpath("resources") & "/stkMyData.livecode" into tStack

# if there is a stack "stkMyData.livecode" then go to stack "stkMyData.livecode"
if there is a file tStack then 
    go to stack tStack
end if
...
Will also work in the IDE!

Best

Klaus

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "Save" in a standalone application

Post by Klaus » Mon Jan 28, 2019 5:17 pm

lohill wrote:
Mon Jan 28, 2019 1:00 am
It took me a while to get a screenshot of what I am seeing but here it is.
Screen Shot 2019-01-27 at 3.56.46 PM.png
Larry
This looks as if the first line has exceeded the maximum length of a line in LC.
Maybe the CRs in the dgtext have been corrupted?
Sorry, have to guess...

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Wed Feb 06, 2019 11:40 pm

Thanks Klaus and bogs for your suggestions. I now have an openStack script that uses some of both of your suggestions.

Code: Select all

## Script of splash screen/exe/app:
on openstack
   put the name of this stack into tStack
   if tStack<>"Giving" then exit to top
   If the environment is "Development"  then
      answer question "Do you want to Run or Develop this application?" with "Run" or "Develop" as sheet
      if it is "Develop" then
         exit to top
      end if
   end if
   ## Show Splash:
   wait 2 secs
   ## or whatever...
   
   ## Important line if you want to access all the externals, libs etc from the splah screen stack 
   ## in the other "independant" stack to:
   start using stack "Giving"
   
   ## Where to copy the savable stack to?
   ## We definitively have WRITE permission here:
   put specialfolderpath("documents") & "/Giving_Main.rev" into tTargetStack  
   
   ## Stack to copy:
   put specialfolderpath("resources") & "/Giving_Main.rev" into tSourceStack
   
   ## Only copy the very first time:
   if there is NOT a file tTargetstack then
      put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
   end if
   
   ## Now:
   open stack tTargetStack
   
   ## Hide your splash here:
   hide stack "Giving"
end openstack
I did have a little hang up on the spelling of "documentes" in Klaus' script but with that corrected it appears that my standalone on the PC seems to be saving the data. The same script does not seem to work on my Mac. Nothing visible happens when I start the application. Further exploration shows a file called "Giving_Main.rev" in my "documents" folder. A double-click on that does not launch LiveCode. Instead I get the message "Unable to open stack: file is not a stack". I have also tried using .livecode and .rev in the names of source and target

Any thoughts?

Larry

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: "Save" in a standalone application

Post by Klaus » Thu Feb 07, 2019 10:13 am

Hi Larry,

sorry for my typo, at least you found it, I ususally type all this out of my head and very quickly. :D
Please check THE RESULT, maybe that will give us a hint:

Code: Select all

...
  ## Only copy the very first time:
   if there is NOT a file tTargetstack then
      put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
     if the result <> EMPTY then
        answer the result
       ## Should be EMPTY on success.
     end if
   end if
...
Best

Klaus

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm
Location: San Diego, CA USA

Re: "Save" in a standalone application

Post by lohill » Thu Feb 07, 2019 8:58 pm

Hi Klaus,

I did check the result and it was empty indicating that the file was created in the documents folder.( Prior to running the openStack I had made sure that no file "Giving.livecode" was in the documents folder.) The file that ended up in "documents" is still not a stack and I get the message I mentioned above.

Here is my code now:

Code: Select all

## Script of splash screen/exe/app:
on openstack
   put the short name of this stack into tStack
   if tStack="Giving" then 
      If the environment is "Development"  then
         answer question "Do you want to Run or Develop this application?" with "Run" or "Develop" as sheet
         if it is "Develop" then
            exit to top
         end if
      end if
      ## Show Splash:
      wait 2 secs
      ## or whatever...
      
      ## Important line if you want to access all the externals, libs etc from the splah screen stack 
      ## in the other "independant" stack to:
      start using stack "Giving"
      
      ## Where to copy the savable stack to?
      ## We definitively have WRITE permission here:
      put specialfolderpath("documents") & "/Giving_Main.livecode" into tTargetStack  
      
      ## Stack to copy:
      put specialfolderpath("resources") & "/Giving_Main.livecode" into tSourceStack
      
      ## Only copy the very first time:
      if there is NOT a file tTargetstack then
         put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
         put the result into tResult
         if the result <> EMPTY then
            answer the result
            ## Should be EMPTY on success.
         end if
      end if
      
      ## Now:
      open stack tTargetStack
      
      ## Hide your splash here:
      hide stack "Giving"
   end if
end openstack
I am doing this in LC 8.1.7 and it is almost like the url("bindle" is not working properly on a Mac.

Regards,
Larry

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”