Standalone App and file paths

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

Standalone App and file paths

Post by phaworth » Sat Sep 12, 2009 12:16 am

Just did my first build of a standalone application and came across something I hadn't anticipated.

I have the following code in an openStack handler to open my sqlite database (it was supplied to me by someone on this forum):

Code: Select all

set the itemDelimiter to "/"
      put item 1 to -2 of the filename of this stack into tSQLiteDatabaseFile
      put "/BandTrak.s3db" after tSQLiteDatabaseFile
      if there is no file tSQLiteDatabaseFile then
         answer information "Can't find db file" & tSQLiteDataBaseFile
      else
...
The intent is to have the database reside in the same directory as the application. Works fine while developing.

When I build a standalone app for the Mac, I'm getting bitten by the fact that the OSX stores the executables inside a package so the code above fails since the db is not inside the package but in the directory that includes the package.

I could put the db inside the package but that doesn't feel like the best place for it somehow.

I'm sure this is a known catch when building standalones on a Mac so I'm hoping someone has a code snippet that will work for development and standalone versions of an app.

Thanks,
Pete

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Sat Sep 12, 2009 8:31 am

This is, indeed a special case for MacOSX: .app executables are actually folders with files inside them (you can verify this by right-clicking on the icon and picking the item "Show package contents" - this will show you the inside)
So to get to files at the same level as the .app file, use this:

Code: Select all

function AbsolutePathFromStack pRelativePath
  local tPath
  --
  put the effective filename of this stack into tPath
  set the itemDelimiter to slash
  if the environment is not "development" and the platform is "MacOS" then
    delete item -3 to -1 of tPath
  else
    delete item -1 of tPath
  end if
  if pRelativePath is not empty then
    put slash & pRelative after tPath
  end if
  return tPath
end AbsolutePathFromStack
However, there is another problem with this: the user may not have enough rights to write to the file if it is in the Applications directory; and what should happen when another user logs into the same machine?
If each user should have its own copy of the database, it's best to store it in a location specific to the user; otherwise you have to find a shared location. Such locations can be found usi g the specialFolderPath function; check it in the Dictionary, and also read Ken Ray's excellent list of specialFolderPath codes.

HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

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

Post by phaworth » Sat Sep 12, 2009 4:38 pm

Thank you Jan, that code will suffice for now. Thanks also for the warning about permissions/sharing. I don't think of my app as one that will be used simultaneously by multiple users, but who knows what happens when it gets on a user's computer.

One thing I will be looking into regarding sharing is the possibility of the db residing on a web host and accessed over the internet. I haven't even looked at rev's web capabilities yet but hoping that sort of thing is possible.

Pete

Post Reply