"Save" in a standalone application
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
"Save" in a standalone application
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
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
Re: "Save" in a standalone application
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":
Then later you can:
Best
Klaus
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
Code: Select all
...
save stack "name_of_savable_stack_here"
...
Klaus
Re: "Save" in a standalone application
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 -
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 -
*Edit - while composing this, Klaus chimed in. I'll defer to him on the workings of a MacHow 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
Re: "Save" in a standalone application
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
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
Re: "Save" in a standalone application
Bogs,
Thanks for the link. I am going to have to spend some time studying it.
Larry
Thanks for the link. I am going to have to spend some time studying it.
Larry
Re: "Save" in a standalone application
Hi Larry,
Best
Klaus
maybe, maybe not, I really would not rely on this!
No, a simple "save stack xxx" will save the main- and all of its substacks, too.
Best
Klaus
Re: "Save" in a standalone application
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.No, a simple "save stack xxx" will save the main- and all of its substacks, too.
Larry
Re: "Save" in a standalone application
It took me a while to get a screenshot of what I am seeing but here it is.
Larry
Larry
Re: "Save" in a standalone application
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. 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.
This is the stack we'll be saving information in and its code, which in the stack script...
And this is what the folder all this is sitting in looks like...
To make sure it is saving, I'll change Curly to Sue, and then add another entry ...
After closing and opening it, the change and new info is still there.
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. 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
After closing and opening it, the change and new info is still there.
Last edited by bogs on Mon Jan 28, 2019 4:41 pm, edited 2 times in total.
Re: "Save" in a standalone application
Here are the stacks for you to play with - too many attachments in the post above
Re: "Save" in a standalone application
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!
Will also work in the IDE!
Best
Klaus
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
...
Best
Klaus
Re: "Save" in a standalone application
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...
Re: "Save" in a standalone application
Thanks Klaus and bogs for your suggestions. I now have an openStack script that uses some of both of your suggestions.
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
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
Any thoughts?
Larry
Re: "Save" in a standalone application
Hi Larry,
sorry for my typo, at least you found it, I ususally type all this out of my head and very quickly.
Please check THE RESULT, maybe that will give us a hint:
Best
Klaus
sorry for my typo, at least you found it, I ususally type all this out of my head and very quickly.
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
...
Klaus
Re: "Save" in a standalone application
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:
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
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
Regards,
Larry