Storing Data on Desktop Apps

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

Post Reply
physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Contact:

Storing Data on Desktop Apps

Post by physicsclassroom »

I'm looking for advice on where to store data (preferences, progress data, etc.) on a Desktop app that I'm building. I want to make sure I'm doing this correctly. It looks like I really only have two choices - documents folder or preferences folder. On the mobile version of the same app, I stored the data in the documents folder. On a desktop app, it doesn't seem that the documents folder would be the best choice. A user looks in their documents folder quite regularly and might see a file they don't recognize and trash the file. Are there any best practices for the location for stored data or pros and cons of each possibility? I will be using both a stack and some text files for the storage containers. It is an educational app that tracks student progress and so some of the information must be kept very secure. And ideas?
ClipArtGuy
Posts: 265
Joined: Wed Aug 19, 2015 4:29 pm

Re: Storing Data on Desktop Apps

Post by ClipArtGuy »

You can write to folders other than documents or preferences using:

Code: Select all

put myData into URL ("binfile:"&thePathToFile)
This path can be just about anywhere the user has permission to write.
bern333
Posts: 25
Joined: Tue Aug 02, 2016 11:03 am

Re: Storing Data on Desktop Apps

Post by bern333 »

So can you put "G:\data\mine" into "thePathToFile"and have it work?

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

Re: Storing Data on Desktop Apps

Post by physicsclassroom »

Thanks for getting back to me ClipArtGuy
ClipArtGuy wrote:This path can be just about anywhere the user has permission to write.
My real question is not so much HOW to write, but WHERE to write. Are there more than two places to write to on Desktop - Preferences and Desktop? And what ate the pros and cons to one location over the other?

Thanks in advance.

Tom
ClipArtGuy
Posts: 265
Joined: Wed Aug 19, 2015 4:29 pm

Re: Storing Data on Desktop Apps

Post by ClipArtGuy »

bern333 wrote:So can you put "G:\data\mine" into "thePathToFile"and have it work?

B

I think you would need to specify a file as well -- put "G:\data\mine\output.txt" into thePathToFile.
ClipArtGuy
Posts: 265
Joined: Wed Aug 19, 2015 4:29 pm

Re: Storing Data on Desktop Apps

Post by ClipArtGuy »

physicsclassroom wrote:Thanks for getting back to me ClipArtGuy
ClipArtGuy wrote:This path can be just about anywhere the user has permission to write.
My real question is not so much HOW to write, but WHERE to write. Are there more than two places to write to on Desktop - Preferences and Desktop? And what ate the pros and cons to one location over the other?

Thanks in advance.

Tom
The answer to your first question is -yes, many. (refer to my initial response)

For the second, I usually save any external files relative to my executable. If my executable lives at "/home/clipartguy/MyApp/MyAppsExecutable" I might keep my preferences in "/home/clipartguy/MyApp/Preferences/"
physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Contact:

Re: Storing Data on Desktop Apps

Post by physicsclassroom »

ClipArtGuy wrote:For the second, I usually save any external files relative to my executable. If my executable lives at "/home/clipartguy/MyApp/MyAppsExecutable" I might keep my preferences in "/home/clipartguy/MyApp/Preferences/"
That will be helpful. Thanks. Two questions though:
1) Do I need to create the folder titled Preferences and then save files to it or does the Preference file already exist?
2) Can I save stacks in the Preferences folder or is it limited to just text files?
ClipArtGuy
Posts: 265
Joined: Wed Aug 19, 2015 4:29 pm

Re: Storing Data on Desktop Apps

Post by ClipArtGuy »

1 - You can either create folders during development, or through script using the "create folder" command.

2 - To my knowledge you can save just about any type of data this way , although if you are using stacks, the save command might be a better bet.
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Storing Data on Desktop Apps

Post by jacque »

Which OS? On Mac the only approved location is in the Application Support folder which is specialFolderPath("asup"). You can still store data in Preferences too, but Apple has deprecated that and suggests you avoid it for future compatibility. Windows has a similar approved location but it escapes me at the moment.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
physicsclassroom
Posts: 50
Joined: Sun Jun 30, 2013 1:43 am
Contact:

Re: Storing Data on Desktop Apps

Post by physicsclassroom »

Thanks Jacque,
jacque wrote:Which OS? On Mac the only approved location is in the Application Support folder which is specialFolderPath("asup"). You can still store data in Preferences too, but Apple has deprecated that and suggests you avoid it for future compatibility. Windows has a similar approved location but it escapes me at the moment.
I am developing for a Mac at the moment. My hope was to use specialFolderPath("Documents") as it seems to be permitted but was wondering what the pros and cons were for saving to documents as opposed to saving to preferences or any other location?
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Storing Data on Desktop Apps

Post by jacque »

The documents folder is permitted (it's writable) but only approved for files the user creates. Some apps ignore that but Apple doesn't like it. If you are saving user-generated data then it's appropriate. If you're saving preferences or other data the app needs but the user never interacts with directly, the app support folder is where those files should go.

The idea is not to clutter the documents folder with files the user will never need to open. In either location you should create a folder named for the app and put the files in there rather than loose in the main folder.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Storing Data on Desktop Apps

Post by Klaus »

Hi all,

this is my function to get the appropriate "preferences/user data" folder on each platform:

Code: Select all

function mkprefsfolder
  switch the platform
  case "MacOS"

    ## Application support
    put specialFolderPath("asup") into spfp
    break
  case "Win32"

    ## Windows >= 2000
    if the systemversion contains "NT" then
      put specialFolderPath(35) into spfp
      ### For all users!
      ### specialfolderpath(26) = for the current user only!
    else

     ## Win95 - XP
      put specialfolderpath("system") into spfp
    end if
    break
  default

    ## *nix
    put $HOME into spfp
    break
  end switch
  return spfp
end mkprefsfolder
And yes, creating a subfolder here for your application a good idea! :D


Best

Klaus
MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Storing Data on Desktop Apps

Post by MaxV »

Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
Post Reply