Store files within livecode app?

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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 5:04 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Store files within livecode app?

Post by Mark » Tue Mar 18, 2014 5:28 pm

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
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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 5:34 pm

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!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Store files within livecode app?

Post by Mark » Tue Mar 18, 2014 5:47 pm

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
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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 5:53 pm

Ok thanks for the pointers. I am still unsure of a way of livecode identifying the files regardless of where they are efficiently.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Store files within livecode app?

Post by Mark » Tue Mar 18, 2014 5:56 pm

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
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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 6:02 pm

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.

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 6:11 pm

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.

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 6:15 pm

Was able to get it all sorted!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Store files within livecode app?

Post by Mark » Tue Mar 18, 2014 6:18 pm

Hi,

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"
or

Code: Select all

revCopyFile "/path/to/file.xyz","/otherpath/to/file.xyz"
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
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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 6:26 pm

Mark wrote:Hi,

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"
or

Code: Select all

revCopyFile "/path/to/file.xyz","/otherpath/to/file.xyz"
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
It will be useful to me, as revCopyFile doesnt work when its been saved as a standalone application, so I shall try put url!

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
When I run the standalone application, this runs and when I click this button, it creates folders, but doesn't copy files?

Klaus
Posts: 14192
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Store files within livecode app?

Post by Klaus » Tue Mar 18, 2014 6:52 pm

Hi axcwilson96,

here a revised version of your script, please read all comments carefully 8)

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
Best

Klaus

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 6:57 pm

Klaus wrote:Hi axcwilson96,

here a revised version of your script, please read all comments carefully 8)

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
Best

Klaus
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 programmer :) Also NumberCrunch is a .app file!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Store files within livecode app?

Post by Mark » Tue Mar 18, 2014 7:09 pm

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
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

acwilson96
Posts: 22
Joined: Tue Nov 26, 2013 9:55 pm

Re: Store files within livecode app?

Post by acwilson96 » Tue Mar 18, 2014 7:20 pm

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
Here is an update of the code without comment lines:

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
It writes the text files blank, so I will try to use BINFILE instead of FILE, and then report results, also the NumberCrunch.app file doesn't copy.
*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

Post Reply