Store files within livecode app?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Store files within livecode app?
I have made a game, which requires the use of text files, and I want to create an "installer" which just takes the game files, and arranges them appropriately in the documents of my Mac so that they can be referred to in-game without issue. I am trying to find a way of either storing the two text files and the games .app in the installer.app or having the installer.app take the files from a folder that the installer app will also be in* and copy them to somewhere else.
* For example I have a folder named "GAME" and inside game is installer.app ; game.app ; highscores.txt and I want the installer app to be able to know where the game.app and highscores.txt are regardless of where the folder is, so the folder "GAME" could be in downloads/desktop/documents and it wouldn't matter
* For example I have a folder named "GAME" and inside game is installer.app ; game.app ; highscores.txt and I want the installer app to be able to know where the game.app and highscores.txt are regardless of where the folder is, so the folder "GAME" could be in downloads/desktop/documents and it wouldn't matter
Re: Store files within livecode app?
Hi,
One of my products is an installer maker, appropriately called "Installer Maker". During the installation process of an app, I keep a log file. When the log file is finished, I save it with the Uninstaller inside the app's folder in the Application folder. When I run the Uninstaller, I first copy it outside the Application folder and run it from there. The log file is automatically copied together with the Uninstaller and thus the Uninstaller knows exactly where to find all files.
If you don't need write access to your files, you can install them in the application folder, together with your application. If you do need write access, you might want to store them in the Application Support folder or in the Preferences folder. Users know that they should not mess with files in those folders. If they do and the Installer/Uninstaller no longer works, it is their own fault.
If you install a file in the documents folder, there is a good chance that the user will mess with it and your app or Un/Installer won't find it anymore. In short, it isn't a matter of finding back your files but a matter of where to put those files (location, location, location).
Kind regards,
Mark
One of my products is an installer maker, appropriately called "Installer Maker". During the installation process of an app, I keep a log file. When the log file is finished, I save it with the Uninstaller inside the app's folder in the Application folder. When I run the Uninstaller, I first copy it outside the Application folder and run it from there. The log file is automatically copied together with the Uninstaller and thus the Uninstaller knows exactly where to find all files.
If you don't need write access to your files, you can install them in the application folder, together with your application. If you do need write access, you might want to store them in the Application Support folder or in the Preferences folder. Users know that they should not mess with files in those folders. If they do and the Installer/Uninstaller no longer works, it is their own fault.
If you install a file in the documents folder, there is a good chance that the user will mess with it and your app or Un/Installer won't find it anymore. In short, it isn't a matter of finding back your files but a matter of where to put those files (location, location, location).
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Thanks for the quick response, however as this is part of a coursework assignment, I am not sure I would be allowed to use your software, however I will use it for my own use!
Re: Store files within livecode app?
Hi,
If it is for a course assignment, I really would recommend using the Preferences folder or Application Support folder. Try this in the message box:
put specialFolderpath("application support")
put specialFolderpath("preferences")
Don't use the abbreviated versions asup and prefs, because the path returned by the specialFolderpath function with asup and prefs as parameters will return a folder in which you may not have write permission if you are using LiveCode 6.0 (and probably 6.5 and 6.6).
Kind regards,
Mark
If it is for a course assignment, I really would recommend using the Preferences folder or Application Support folder. Try this in the message box:
put specialFolderpath("application support")
put specialFolderpath("preferences")
Don't use the abbreviated versions asup and prefs, because the path returned by the specialFolderpath function with asup and prefs as parameters will return a folder in which you may not have write permission if you are using LiveCode 6.0 (and probably 6.5 and 6.6).
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Ok thanks for the pointers. I am still unsure of a way of livecode identifying the files regardless of where they are efficiently.
Re: Store files within livecode app?
Hi,
Believe me, you don't want that
If your teacher told you to do this, tell him or her there's a better way.
Kind regards,
Mark
Believe me, you don't want that

Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
I have to do this entirely myself, so I am trying different strategies! Right now I have the idea of there being a folder with the installer.app then another folder with all the required files. Then the installer.app will open the folder it is in, then copy the required files to the install location.
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Ok I was able to work it out, I only need to know how to copy files, which I am having a little trouble with.
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Was able to get it all sorted!
Re: Store files within livecode app?
Hi,
There are at least two ways to copy files. You can use the put URL command or use the revCopyFile command.
or
You can also copy an entire folder, using revCopyFolder.
Edit: I see you figured it out while I wrote this, but maybe this will be useful to someone else.
Kind regards,
Mark
There are at least two ways to copy files. You can use the put URL command or use the revCopyFile command.
Code: Select all
put url "binfile:/path/to/file.xyz" into url "binfile:/otherpath/to/file.xyz"
Code: Select all
revCopyFile "/path/to/file.xyz","/otherpath/to/file.xyz"
Edit: I see you figured it out while I wrote this, but maybe this will be useful to someone else.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
It will be useful to me, as revCopyFile doesnt work when its been saved as a standalone application, so I shall try put url!Mark wrote:Hi,
There are at least two ways to copy files. You can use the put URL command or use the revCopyFile command.
orCode: Select all
put url "binfile:/path/to/file.xyz" into url "binfile:/otherpath/to/file.xyz"
You can also copy an entire folder, using revCopyFolder.Code: Select all
revCopyFile "/path/to/file.xyz","/otherpath/to/file.xyz"
Edit: I see you figured it out while I wrote this, but maybe this will be useful to someone else.
Kind regards,
Mark
Here is the code:
Code: Select all
on mouseUp
open file the documents folder for write
create folder the documents folder & "/NumberCrunch"
create folder the documents folder & "/NumberCrunch/Highscores"
put the documents folder
put the effective filename of this stack into tPath
set the itemDel to slash
delete last item of tPath
put tPath into filePath
put defaultfolder
//Install Game
open file filePath & "/FILES" for read
put url(filePath & "/FILES/highscoreNames.txt") into url (the documents folder & "/NumberCrunch/Highscores")
put url (filePath & "/FILES/highscoreScores.txt") into url (the documents folder & "/NumberCrunch/Highscores")
put url (filePath & "/FILES/NumberCrunch") into url (defaultfolder)
end mouseUp
Re: Store files within livecode app?
Hi axcwilson96,
here a revised version of your script, please read all comments carefully
Best
Klaus
here a revised version of your script, please read all comments carefully

Code: Select all
on mouseUp
## You cannot open a FOLDER as FILE!
## open file the documents folder for write
put the documents folder & "/NumberCrunch" into tFolder1
put the documents folder & "/NumberCrunch/Highscores" into tFolder2
## ALWAYS check before creating folders or files!
if there is not a folder tFolder1 then
create folder tFolder1
end if
if there is not a folder tFolder2 then
create folder tFolder2
end if
## ??
## put the documents folder
## "PUT" without a target will PUT the string into the message box
## but that is not present in a standalone unless you add it in the standalone builder
put the effective filename of this stack into filePath
set the itemDel to slash
delete last item of filePath
## put tPath into filePath
## See above...
## put defaultfolder
## Install Game
## Not neccessary when you are using the URL file handling
## open file filePath & "/FILES" for read
## Wrong syntax!
## put url(filePath & "/FILES/highscoreNames.txt") into url (the documents folder & "/NumberCrunch/Highscores")
## put url (filePath & "/FILES/highscoreScores.txt") into url (the documents folder & "/NumberCrunch/Highscores")
## put url (filePath & "/FILES/NumberCrunch") into url (defaultfolder)
## You need to specify FILE (text) or BINFILE (images etc...) AND the filename of the target file
put url("FILE:" & filePath & "/FILES/highscoreNames.txt") into url ("file:" & tFolder2 & "/highscoreNames.txt")
put url("FILE:" & filePath & "/FILES/highscoreScores.txt") into url ("file:" & tFolder2 & "/highscoreScores.txt")
## ??? is NumberCrunch a text file? If yes, handle like the examples above :-)
## put url (filePath & "/FILES/NumberCrunch") into url (defaultfolder)
end mouseUp
Klaus
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Thanks for the help, I had the put in there for troubleshooting and I really appreciate the help, will try now and the comments made all make sense, just hard to think of when you aren't an experienced programmerKlaus wrote:Hi axcwilson96,
here a revised version of your script, please read all comments carefully
BestCode: Select all
on mouseUp ## You cannot open a FOLDER as FILE! ## open file the documents folder for write put the documents folder & "/NumberCrunch" into tFolder1 put the documents folder & "/NumberCrunch/Highscores" into tFolder2 ## ALWAYS check before creating folders or files! if there is not a folder tFolder1 then create folder tFolder1 end if if there is not a folder tFolder2 then create folder tFolder2 end if ## ?? ## put the documents folder ## "PUT" without a target will PUT the string into the message box ## but that is not present in a standalone unless you add it in the standalone builder put the effective filename of this stack into filePath set the itemDel to slash delete last item of filePath ## put tPath into filePath ## See above... ## put defaultfolder ## Install Game ## Not neccessary when you are using the URL file handling ## open file filePath & "/FILES" for read ## Wrong syntax! ## put url(filePath & "/FILES/highscoreNames.txt") into url (the documents folder & "/NumberCrunch/Highscores") ## put url (filePath & "/FILES/highscoreScores.txt") into url (the documents folder & "/NumberCrunch/Highscores") ## put url (filePath & "/FILES/NumberCrunch") into url (defaultfolder) ## You need to specify FILE (text) or BINFILE (images etc...) AND the filename of the target file put url("FILE:" & filePath & "/FILES/highscoreNames.txt") into url ("file:" & tFolder2 & "/highscoreNames.txt") put url("FILE:" & filePath & "/FILES/highscoreScores.txt") into url ("file:" & tFolder2 & "/highscoreScores.txt") ## ??? is NumberCrunch a text file? If yes, handle like the examples above :-) ## put url (filePath & "/FILES/NumberCrunch") into url (defaultfolder) end mouseUp
Klaus

Re: Store files within livecode app?
Hi Klaus,
I just had only a very quick look at your script, so I might be wrong, but I'm wondering if you didn't forget a "binfile:" in the last line? Also, since the app is using the text files and not some text editor, you might want to use binfile when writing the files to disk. I would assume that OP doesn't want to convert line endings, unless he says he wants to (so, do you want to convert line endings, OP?).
Kind regards,
Mark
I just had only a very quick look at your script, so I might be wrong, but I'm wondering if you didn't forget a "binfile:" in the last line? Also, since the app is using the text files and not some text editor, you might want to use binfile when writing the files to disk. I would assume that OP doesn't want to convert line endings, unless he says he wants to (so, do you want to convert line endings, OP?).
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 22
- Joined: Tue Nov 26, 2013 9:55 pm
Re: Store files within livecode app?
Here is an update of the code without comment lines:Mark wrote:Hi Klaus,
I just had only a very quick look at your script, so I might be wrong, but I'm wondering if you didn't forget a "binfile:" in the last line? Also, since the app is using the text files and not some text editor, you might want to use binfile when writing the files to disk. I would assume that OP doesn't want to convert line endings, unless he says he wants to (so, do you want to convert line endings, OP?).
Kind regards,
Mark
Code: Select all
on mouseUp
put the documents folder & "/NumberCrunch" into tFolder1
put the documents folder & "/NumberCrunch/Highscores" into tFolder2
if there is not a folder tFolder1 then
create folder tFolder1
end if
if there is not a folder tFolder2 then
create folder tFolder2
end if
put the effective filename of this stack into filePath
set the itemDel to slash
delete last item of filePath
put url("FILE:" & filePath & "/FILES/highscoreNames.txt") into url ("file:" & tFolder2 & "/highscoreNames.txt")
put url("FILE:" & filePath & "/FILES/highscoreScores.txt") into url ("file:" & tFolder2 & "/highscoreScores.txt")
put url("BINFILE:" & filePath & "/FILES/NumberCrunch.app") into url (defaultfolder)
end mouseUp
*EDIT*
The files still copy blank and the .app doesnt copy, I will attempt revCopyFile and report the results
*EDIT2*
Cannot get the files to copy without using the code above. However the file is blank using the code above. However since they are just text files I could copy the contents and write the contents to new files, but it still doesn't solve the issue regarding the .app not copying