specialFolderPaths

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

specialFolderPaths

Post by physicsclassroom » Thu Aug 16, 2018 5:00 am

I'm having trouble with data storage and retrieval in my app. I make the stand-alone and put the build into the Applications folder. When it opens, i make a variable called storagePath and I put specialFolderPath("support") & "/" & "myFolderName" into it. I then look for a stack called "dataStack.livecode". If not found it puts a copy there using

Code: Select all

   put specialFolderPath("Resources") & "/dataStack.livecode" into sourceFile
   put storagePath  into destinationFolder
   revCopyFile sourceFile, destinationFolder
That part works. A stack is created at

Users/myUserName/Library/Application Support/myFolderName

just as I expect. But the odd part is that a second dataStack is created at

Applications/myApp/Contents/MacOS/dataStack.livecode.

It wasn't there before I open the app and I have not idea how it got there nor how to reference it. When I go to store data in the stack at storagePath/dataStack.livecode, I expect it to go into the Application Support area. Instead it gets stored in the Applications area. When the stack opens the second time, it can't find the data because it looks in storagePath/dataStack.livecode for the data but it never got stored there ... even though that is where I always direct the data to.

I'm confused as to why one command - revCopyFile sourceFile, destinationFolder[/code] - is creating the two stacks in different locations? and why it never saves it to Application Support?

Any ideas?

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

Re: specialFolderPaths

Post by Klaus » Thu Aug 16, 2018 2:37 pm

Did you check "the result" right after revcopyfile?
Maybe that will give you a hint:

Code: Select all

...
put specialFolderPath("Resources") & "/dataStack.livecode" into sourceFile
put storagePath into destinationFolder
revCopyFile sourceFile, destinationFolder
if the result <> EMPTY then
  answer "Error:" & CR & the result
end if
...

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Thu Aug 16, 2018 4:03 pm

I tried your suggestion. The result was empty.

I did notice in the Dictionary that in stand-alones, the revCopyFile code is not loaded until after the preOpenStack messages are sent.

"Note: In a standalone application the Common library is implemented as a hidden group and made available when the group receives its first openBackground message. During the first part of the application's startup process, before this message is sent, the revCopyFile command is not yet available. This may affect attempts to use this command in startup, preOpenStack, openStack, or preOpenCard handlers in the main stack. Once the application has finished starting up, the library is available and the revCopyFile command can be used in any handler."

So the might explain the odd behavior. I'm going to rework the start-up procedure of the stack and see if I get different results.

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

Re: specialFolderPaths

Post by Klaus » Thu Aug 16, 2018 4:08 pm

AHA! Yes, that is true!

Do something like this:
## Or wherever you put the script

Code: Select all

on startup
  send "Do_the_copy" to me in 1 secs
  ## or even a shorter period, do some tests, if neccessary.
end startup
Then put your script into the separate hanlder "Do_the_copy" in the stackscript.

This usually "cures" this lib-loading delay.

best

Klaus

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Thu Aug 16, 2018 4:55 pm

I was able to attach my revCopyFile command to a button on card 1 of the stack. No change in the results. There's still two stacks copied to two different locations.

What is odd is that I am also writing three .txt files to Users/myUserName/Library/Application Support/myFolderName
… which I reference as specialFolderPath(“support”) & “/myFolderName”

I am successfully reading and writing to those files. Despite the fact that my file referencing is identical, I am not able to store and retrieve data from a stack in the same directory. Instead it retrieves data from the stack located at Applications/myApp/Contents/MacOS/dataStack.livecode

Would the latter location be specialFolderPath(“engine”) & “/Contents/MacOS/dataStack.livecode”?

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

Re: specialFolderPaths

Post by Klaus » Thu Aug 16, 2018 6:22 pm

physicsclassroom wrote:
Thu Aug 16, 2018 4:55 pm
Would the latter location be specialFolderPath(“engine”) & “/Contents/MacOS/dataStack.livecode”?
Yes, and unless the current user has ADMIN permissions, we are not allowed to write there, which makes this even more mysterious! :shock:

Maybe it will work without revCopyFile:

Code: Select all

...
put specialFolderPath("Resources") & "/dataStack.livecode" into sourceFile
put storagePath & "/datastack.livecode" into destinationFile
if there is NOT a file destinationFile then
   put url("binfile:" & sourceFile) into url("binfile" & destinationFile)
end if
if the result <> EMPTY then
  answer "Error:" & CR & the result
end if
...
At least worth a try.


Best

Klaus

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Thu Aug 16, 2018 6:37 pm

Could the fact that my app is not yet signed and packaged make a difference here? I am simple dropping the build made from LiveCode into the Applications folder and then creating a folder for my files inside of the Applications Support folder. I'm noticing in the Application Support folder that there are a lot of folders of the sort com.companyName. But there's no folder titled com.physicsclassroom.

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

Re: specialFolderPaths

Post by Klaus » Thu Aug 16, 2018 6:49 pm

physicsclassroom wrote:
Thu Aug 16, 2018 6:37 pm
Could the fact that my app is not yet signed and packaged make a difference here? I am simple dropping the build made from LiveCode into the Applications folder and then creating a folder for my files inside of the Applications Support folder.
No, that should only make a difference if you put the app onto another machine, then Gatekeeper may not like this.
physicsclassroom wrote:
Thu Aug 16, 2018 6:37 pm
I'm noticing in the Application Support folder that there are a lot of folders of the sort com.companyName. But there's no folder titled com.physicsclassroom.
These folders are not created automatically, your app needs to do that.
But that should not be the reason for the extra stack.

Sorry, out of brilliant ideas in the moment...

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

Re: specialFolderPaths

Post by bwmilby » Thu Aug 16, 2018 10:55 pm

The dictionary needs to be updated. Those delay comments are OBE.

To me it looks like you are seeing the source stack (it has to copy it from somewhere). If that stack is referenced and open, then the updates will get saved to the original copy even though you duplicated it. Normally you would not be able to write where it is stored, but since you created the app, moving it to the Applications folder didn’t remove your rights. Since it is a separate stack file, it can be updated and saved.
Brian Milby

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

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Fri Aug 17, 2018 4:00 pm

So can I infer from what you are saying:

If I want to test the functionality of my app, I would need to side-load it onto another Apple computer that is not associated with my Apple ID. Then that copy in the Applications folder would not exist and the app would store in the copy and not the source. In other words, If I gave this to a friend, the saving/retrieving of data from the dataStack would work perfectly?

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

Re: specialFolderPaths

Post by bwmilby » Fri Aug 17, 2018 4:18 pm

Not exactly. When testing, you just need to be sure that the app is not making changes to files within the application bundle. You should be able to do that without going to another seat. My point was that just moving the application to the Applications folder does not change the permissions on it so that it will work just like it would on another seat.

It sounds like you are surprised that `sourceFile` exists.

Things missing from this thread is how/when that "datastack.livecode" file is opened. It is perfectly normal for the application to be able to open a stack from within the bundle, but it is not normal to be able to save it there. It sounds like your application is automatically opening "datastack.livecode" from within the bundle which is why you are seeing what you are.
Brian Milby

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

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Fri Aug 17, 2018 4:58 pm

The dataStorage stack is included in the bundle and I can see it inside the Resources folder. When I use the revCopy command, the engine makes two copies of dataStorage.livecode - one inside the Applications folder but outside of the Resources folder and the other in the Application Support folder inside of the library folder of the user folder. (which is where I expect it to be).

I'm a bit surprised that my revCopy command is making a copy of a stack inside of the bundle but I can live with that. I just can't live with the fact that the data is going into the stack. All my put commands should be putting data into the dataStorage stack in this specialFolderPath("support").

When I use the "is there a stack" function, it recognizes the existence of this copied stack in the bundle. When I try to get the data out of the stack using a reference to the stack at specialFolderPath("engine"), I can't get to it. I can only get to the data in the stack inside of the bundle using a specialFolderPath("support") reference.

It is as though the stack in the Application Support folder acts as an alias of the stack that is in the bundle. And when I restart my app, the game is over since the data doesn't get saved from session to session.

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

Re: specialFolderPaths

Post by bwmilby » Fri Aug 17, 2018 5:19 pm

I don't think it is the revcopyfiles that is putting it there. Somewhere else in the app it is saving that stack to a path that isn't fully qualified.
Brian Milby

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

physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Location: Illinois
Contact:

Re: specialFolderPaths

Post by physicsclassroom » Fri Aug 17, 2018 5:53 pm

I'll go on a witch hunt later this afternoon when I get some time to see if I can find any scripts I'm not aware of. I think I have done this before but I'll hunt again.

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

Re: specialFolderPaths

Post by bwmilby » Fri Aug 17, 2018 6:36 pm

How does the main stack/app open the file that you copy? How does it save the data stack once it is updated?
You may want to consider changing the defaultfolder.

Code: Select all

set the defaultFolder to storagePath
Brian Milby

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”