How To Get the Path of the .rev file

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
phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

How To Get the Path of the .rev file

Post by phaworth » Wed Jan 13, 2010 10:13 pm

How do I get the directory path of the .rev file that is being used by my app? I need to set up a test environment separate from my production environment and my database file will be in the same folder as the .rev file so need to be able to open it based on the .rev file path.
Thanks,
Pete

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

Re: How To Get the Path of the .rev file

Post by Mark » Thu Jan 14, 2010 1:36 am

Hi Pete,

Code: Select all

set the itemDel to slash
put item 1 to -2 of the effective filename of this stack into myFolderPath
Problem: if you install your standalone on a different computer or platform, you might discover that you can no longer write to your database file. You should never save files that need to be written to in the same folder as your standalone. Instead, keep such files in the application data folder (Win), the application support folder (Mac) or in the documents folder.

Best,

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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: How To Get the Path of the .rev file

Post by phaworth » Thu Jan 14, 2010 2:28 am

Thanks for the code Mark and also the heads up on file access. My plan on my machine was to have:

- a development folder holding the .rev file and any other required fiels
- a production folder, still using the .rev file
- a standalone folder.

I think I'm fine for the first two of the above with your code but not sure what to do about the standlone envirronment in view of your comments. Can the code find out if its running as a standalone app and do something different to find it's data folder (which I plan to put in the Documents folder (on a Mac)? I'm hesitant to hardcode the path name for the standalone environment because some people might prefer to install it elsewhere.

Thanks,
Pete

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

Re: How To Get the Path of the .rev file

Post by Mark » Thu Jan 14, 2010 2:43 am

Pete,

To find out whether the stack is running as astandalone, check the environment property:

Code: Select all

if the environment is "standalone application" then....
Find your data folder inside the documents folder this way:

Code: Select all

put specialFolderpath("documents") & "/path/to/folder" into myDataFolder
Best,

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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: How To Get the Path of the .rev file

Post by phaworth » Thu Jan 14, 2010 7:46 pm

Thanks for that code Mark. So here's what I hope is my final issue on this. I want people to be able to install my app wherever they want, not necessarily in the Documents folder and not necessarily with the standard name. So somehow I have to capture where they install it in order to be able to use your code.

My plan right now is to try to open my database file in the standard install folder and if it's not there, to prompt for the folder where they installed the app. No problem with that but I then need to store the path of their install folder somewhere so next time the app runs it knows where to go. I can't store it in my database because I need the path to the install folder before I can open the database.

On a Windows machine I would just store the location in a registry entry but I don't know what the standard way of storing info like that is on a Mac so would appreciate any suggestions on that.

Thanks,
Pete

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

Re: How To Get the Path of the .rev file

Post by Mark » Fri Jan 15, 2010 12:42 am

Hi Pete,

Apparently, your database file already exists when your application is installed. Since you seem to need read and write access to that file, you need a way to install it. If you make sure that it is always installed in the same place, you don't need to capture where users install it. Don't bother your users with files that need to be copied manually into the right location or with dialog windows asking for folders of which they aren't even aware they exist.

Just keep your database file in a custom property in a stack. If the database file doesn't exist inside the documents folder, just save the contents of the custom property to the location where it is expected to be. You might also want to keep another file in the preferences folder (application data on Windows), which remembers that the database file has been saved to disk. Use the specialFolderpath function with "preferences" as parameter on Mac and "26" on Windows. If the database doesn't exist later on, while the preferences file indicates that it should exist, you can give the user a warning, ask the user whether the file should be created again or whether s/he will restore the old file. If the user wants to restore the old file, just quit and if the use wants to create a new file continue like before.

You could keep info in the registry on Windows, but my problem with that is that most people won't delete that registry entry when they delete your application and they and up with garbage in the registry. So, in most cases I prefer to use a preferences file, just as on the Mac and on Linux machines. Having said that, I should note that I do use the registry quite often, but in those cases I provide an installer and uninstaller (made with RunRev) to make sure that a computer is clean after the removal of my software.

Best 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

phaworth
Posts: 592
Joined: Thu Jun 11, 2009 9:51 pm

Re: How To Get the Path of the .rev file

Post by phaworth » Fri Jan 15, 2010 1:17 am

Thanks Mark. The custom property sounds like it will work just fine. I do intend to install the app in a standard place but I can't rely on users leaving it there and I think they should be able to put it wherever they want it on their computer - might even offer that option on install with a caveat that they must have read/write access of course.

Thanks for the code you've given me, together I think it achieves what I wanted to do.

Pete

Post Reply