Open a LC document using a standalone

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5138
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Open a LC document using a standalone

Post by jacque » Sun Apr 29, 2018 8:37 pm

Klaus gave the definitive method. It assumes you have included the writable stack in the Copy Files pane of the standalone settings. The stack won't be in the folder with the standalone, it will be embedded in the bundle.

You can't save files inside the app bundle, which is why you need to copy it to a folder that has correct permissions. If you actually do want the stack to be visible outside the bundle, then your original script will work with some changes. But if Klaus' method is acceptable then you should do it that way.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Open a LC document using a standalone

Post by bogs » Sun Apr 29, 2018 9:11 pm

jacque wrote:
Sun Apr 29, 2018 4:42 pm
Using a Home folder is a Unix thing, it isn't a good choice for Mac or Windows.
Then the dictionary needs a correction entered, cause that is where I got the information from.
Windows folder names:
- "home": The current user's profile folder
- "desktop": The current user's desktop folder
- "documents": The current user's "My Documents" folder
- "support": The current user's application-specific data ("AppData") folder
- "system": The Windows System folder
- "start": The folder that contains Start Menu items
- "fonts": The folder that contains fonts
- "temporary": The folder where temporary files can be placed
- "engine": The folder containing the LiveCode engine and the executable files copied in the standalone application
- "resources": In development mode, the current stack's folder. In a standalone, the resources folder where files or folders specified in the Standalone Builder are located.

On Mac OS systems, the following folderIdentifier values are supported:
- "home": The current user's home folder
- "desktop": The current user's desktop folder
- "preferences": The current user's preferences folder
- "documents": The current user's documents folder
- "support": The current user's application-specific data folder
- "system": The System Folder (usually /System)
- "fonts": The folder that contains fonts
- "temporary": The folder where temporary files can be placed
- "engine": The folder containing the LiveCode engine and the executable files copied in the standalone application
- "resources": In development mode, the current stack's folder. In a standalone, the resources folder where files or folders specified in the Standalone Builder are located.

On Linux systems, the following folderIdentifier values are supported:
- "home": The current user's home folder
- "desktop": The current user's desktop folder
- "temporary": The folder where temporary files can be placed
- "engine": The folder containing the LiveCode engine and the executable files copied in the standalone application
- "resources": In development mode, the current stack's folder.
I'll concede I didn't thoroughly read through the iOs section, but it *does* still have a 'home' specialFolderPath, but you should of course use 'documents' on mobile is recommended.
On iOS systems, only create files in the "documents", "cache" and "temporary" folders. Be careful not to change or add any files within the application bundle. The application bundle is digitally signed when it is built, and any changes after this point will invalidate the signature and prevent it from launching.

iOS imposes strict controls over what you can and cannot access. Each application in iOS is stored in its own "sandbox" folder (specialFolderPath("home")). An application is free to read and write files anywhere beneath this folder, but it is not allowed to access anything outside of the "sandbox".

The following folderIdentifier values are supported:
"home": The (unique) folder containing the application bundle and its associated data and folders
"documents": The folder in which document data should be stored (backed up by iTunes on sync)
"library": The folder in which to store data of various types (backed up by iTunes on sync). In particular, data private to the application should be stored in a folder named with the app's bundle identifier inside the "library" folder
"cache": The folder where transient data that needs to be preserved between launches should be stored (not backed up by iTunes)
"temporary": The folder where temporary data that is not preserved between launches should be stored (not backed up by iTunes)
"engine": The folder containing the built standalone engine (i.e. the bundle). This is useful for constructing paths to resources that have been copied into the bundle at build time
"resources": Same as "engine".
*Edit -
Klaus wrote:
Sun Apr 29, 2018 4:58 pm
2. When your app starts, copy that stack over to the users documents folder,
this is where we definitivley have WRITE (save a stack) permission!
Just keep in mind if you decide to develop for Linux, change 'documents' to 'home', cuz linux :P

You know what they say, there is no place like home :mrgreen:
Selection_003.png
OSX 10.6.5
Selection_003.png (13.93 KiB) Viewed 1483 times
Image

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Sun Apr 29, 2018 9:22 pm

Hi Klaus,

Thanks for staying with me.

I made your changes, but I still get the same errors. The second file "testb" wont open and the document file has 0 size and the error message says it is not a livecode file.

I tried
if there is not a file tTargetStack then
put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
end if

and
if there is not a file tTargetStack then
put url("binfile:" & tTargetStack) into url("binfile:" & tTargetStack)
end if


Here is the complete code
on openstack
## Create path to RESOURCES folder!!!!! and target stack in the users docs folder
put specialfolderpath("resources") & "/testa.livecode" into tSourceStack
put specialfolderpath("documents") & "/testb.livecode" into tTargetStack

## check if stack already exists:

if there is not a file tTargetStack then
put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)
end if

## Now open that stack that we can modify and SAVE!
go stack tTargetStack
end openstack

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Sun Apr 29, 2018 9:24 pm

THanks for the attention to detail. All these years and now I know what a home folder is.

Max

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

Re: Open a LC document using a standalone

Post by bogs » Sun Apr 29, 2018 9:29 pm

No problem my friend, Klaus and Jacque are well versed in the intricacies of Mac Os things, I'm sure they will have you straightened out in no time :wink:
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5138
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Open a LC document using a standalone

Post by jacque » Sun Apr 29, 2018 10:44 pm

Yes, they all have Home folders, but it isn't the right place for files on Mac and Windows.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

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

Re: Open a LC document using a standalone

Post by bogs » Sun Apr 29, 2018 11:21 pm

Hm. Well, like I said, she would know for sure. I tend to treat Macs like 'nix, since they tend to have a lot in common.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5138
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Open a LC document using a standalone

Post by jacque » Mon Apr 30, 2018 4:59 pm

bogs wrote:
Sun Apr 29, 2018 11:21 pm
I tend to treat Macs like 'nix, since they tend to have a lot in common.
They do have a lot in common under hood. But on Mac at least the home folder is virtually never used for user documents. It's also not immediately visible to users except via the sidebar shortcut. I'd bet that 99% of Mac users would never think of drilling down to the home folder to find a file.

On Windows it's a little easier to find, but typically on that OS all user files get dumped into Documents.

That may be why so many users don't even know what a Home folder is.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Mon Apr 30, 2018 5:27 pm

So does anyone have an idea why this code does not work?

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

Re: Open a LC document using a standalone

Post by Klaus » Mon Apr 30, 2018 5:49 pm

Hi Max,

the code is correct should definitively work!

To be sure, you have added a stack file named "testa.livecode" to your standalone via the "Copy files" tab in the "Standalone Builder Settings"?


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6960
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Open a LC document using a standalone

Post by FourthWorld » Mon Apr 30, 2018 5:55 pm

maxs wrote:
Mon Apr 30, 2018 5:27 pm
So does anyone have an idea why this code does not work?
No, but I'll bet the OS wants to tell you: After any file I/O statement check "the result" and get sysError().
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

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

Re: Open a LC document using a standalone

Post by bogs » Mon Apr 30, 2018 7:28 pm

jacque wrote:
Mon Apr 30, 2018 4:59 pm
I'd bet that 99% of Mac users would never think of drilling down to the home folder to find a file.
In this case, maybe that is exactly what maxs might want to target, and put it in a hidden folder to boot, with a [.hiddenFolder] name to match.

After all, as a stack file that is being launched by the app and saved whole again, the end user isn't going to be able to open it or modify it in any meaningful way outside of the program itself, and (at least where Mac is concerned) it can't be saved to the app folder itself as a sub file.

If you were trying to save out say, text files or images, then yah [Documents] in both cases would be the norm for sure. Interesting thought puzzle :?

Of course, he still needs to get to a solution before he ponders the greater mysteries in life :D That last bit Richard posted should help narrow it down.
Image

bwmilby
Posts: 278
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Open a LC document using a standalone

Post by bwmilby » Mon Apr 30, 2018 9:08 pm

A single stack with app and data is easy... until you need to make any changes to the app. I’m dealing with that on a stack that I’ve distributed (next version will separate out the data).

Have you considered partitioning things and having the data be separate from the logic?

Does the data need to be portable by the user? If not, one of the not-so-obvious locations may be suitable (prefs...)
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

maxs
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 402
Joined: Sat Jun 24, 2006 12:02 am
Contact:

Re: Open a LC document using a standalone

Post by maxs » Tue May 01, 2018 5:23 am

Hi,

Thanks again to all of you who are still offering advice and not giving up on me.

First, I cannot add a stack file named "testa.livecode" to my standalone via the "Copy files" tab in the "Standalone Builder Settings" because that is the name of the source file. The target file "Testb" I can and did add. Perhaps that is what you meant?

Second, I added a line , put the result into field "testresult". The result was "The file is not a stack"

Third, I looked at this code "put url("binfile:" & tSourceStack) into url("binfile:" & tTargetStack)"
I have no idea what this means, what it is suppose to do, seen any livecode documentation on it, and how to solve my problem using code so unknown to me. My guess it that it makes a copy of any file. But the file is not copying correctly.

Fourth, The stack is so small, I figured I can just post it here as an attachment to share it with you. When I click on the "Add Files " button below, my livecode files are greyed out, so I am unable to select them. Also, Im advised that I can just drag and drop them to this window. That did not work either.

Finally, I will resolve this tonight by putting Tequila into me. Thank you, Max

bwmilby
Posts: 278
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Open a LC document using a standalone

Post by bwmilby » Tue May 01, 2018 6:07 am

Compress the stack as a zip file to attach.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

Post Reply

Return to “Talking LiveCode”