Runtime data path

i am trying to figure out how to code media paths in sdl. on each
system it would be installed into a different folder, and a user
should be able to run the application with or without installing. i
have spent a few hours googling and nothing seems to come up. so i
picked an open source project and looked at it. i found that
supertux handles it quit well. it tries the current working dir then
the install dir. this seems to work well except that the code is not
clean, it has ifdef in it for windows or unix.

i would like to add similar functionality so my application would try
to find the runtime data in the install prefix, current working dir,
or specified at runtime with an option like --data-dir=/usr/local/
share/myapp for example.

i think this has been lightly discussed before but could not find the
emails.

i would like to know if anyone has any links that might explain
options on how to do this.
what keywords that might help google.
or any opensource and cross platform applications that handle this well.

thanks

matt

i am trying to figure out how to code media paths in sdl. on each
system it would be installed into a different folder, and a user
should be able to run the application with or without installing. i
have spent a few hours googling and nothing seems to come up. so i
picked an open source project and looked at it. i found that
supertux handles it quit well. it tries the current working dir then
the install dir. this seems to work well except that the code is not
clean, it has ifdef in it for windows or unix.

http://icculus.org/physfs/

I haven’t personally used this, but I plan to check it out when I get
some time. From what I understand, you set up some pre-determined
search paths and/or archives… or something. Well just look at the
website and I’m sure you can figure it out faster than by reading
whatever summary I could write. :wink:

ChazOn Thu, 2008-01-31 at 21:00 -0600, matt hull wrote:

that doesnt seem to be a solution as it too would need to know where
to find the data files to populate its internal file system.

thanks

mattOn Jan 31, 2008, at 9:11 PM, Charles McGarvey wrote:

On Thu, 2008-01-31 at 21:00 -0600, matt hull wrote:

i am trying to figure out how to code media paths in sdl. on each
system it would be installed into a different folder, and a user
should be able to run the application with or without installing. i
have spent a few hours googling and nothing seems to come up. so i
picked an open source project and looked at it. i found that
supertux handles it quit well. it tries the current working dir then
the install dir. this seems to work well except that the code is not
clean, it has ifdef in it for windows or unix.

http://icculus.org/physfs/

I haven’t personally used this, but I plan to check it out when I get
some time. From what I understand, you set up some pre-determined
search paths and/or archives… or something. Well just look at the
website and I’m sure you can figure it out faster than by reading
whatever summary I could write. :wink:

Chaz


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

that doesnt seem to be a solution as it too would need to know where
to find the data files to populate its internal file system.

Yep. Generally speaking, you have to tell whatever library you use
where your files will be on each platform.

Let’s examine the problem: You want a functon, GetResource, that you
can pass a name to and it gives you the same resource on every platform
without having to actually specify where that resource came from. The
problem is, no library will automatically know where you plan to store
your files. It isn’t magic.

Technically, somebody could write a library which accessed resources
from standard locations on each platform (such as in the app bundle on
OS X); the problem is not every platform has such standard locations.
Therefore, you will have to give any library you use at least some
information as to where you files are.

The virtues of the library I pointed out to you is that it will do all
the work of finding resources and loading them (including automatic
[un]archiving) from a “virtual” hierarchical system that you design,
which is the same on all platforms. Therefore, the actual reading and
writing code is the same across the board.

The only thing you have to do, during initialization of your app, is
tell it where to find your resources depending on each platform, which
you can use #ifdef for. (Precompiler directives are not evil or
"innelegant." Really, they’re quite nice.)

I know, it would be rad to have a single method that automatically knew
where all the resources would be, but considering the problem, I think
something like this library is the best we can hope for, and I think the
implementation of its solution is very elegant indeed.

Hope that helped a bit more,
ChazOn Thu, 2008-01-31 at 22:40 -0600, matt hull wrote:

just found a binreloc after reading some more. not sure how to use
it though.

mattOn Jan 31, 2008, at 9:00 PM, matt hull wrote:

i am trying to figure out how to code media paths in sdl. on each
system it would be installed into a different folder, and a user
should be able to run the application with or without installing. i
have spent a few hours googling and nothing seems to come up. so i
picked an open source project and looked at it. i found that
supertux handles it quit well. it tries the current working dir then
the install dir. this seems to work well except that the code is not
clean, it has ifdef in it for windows or unix.

i would like to add similar functionality so my application would try
to find the runtime data in the install prefix, current working dir,
or specified at runtime with an option like --data-dir=/usr/local/
share/myapp for example.

i think this has been lightly discussed before but could not find the
emails.

i would like to know if anyone has any links that might explain
options on how to do this.
what keywords that might help google.
or any opensource and cross platform applications that handle this
well.

thanks

matt


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

i am trying to figure out how to code media paths in sdl. on each system it
would be installed into a different folder, and a user should be able to run
the application with or without installing. i have spent a few hours
googling and nothing seems to come up. so i picked an open source project
and looked at it. i found that supertux handles it quit well. it tries the
current working dir then the install dir. this seems to work well except
that the code is not clean, it has ifdef in it for windows or unix.

fnkdat is another option. I think that you’ll find that most
solutions to this problem will have #ifdefs for various platforms because
handling this varies greatly from platform to platform.
http://www.maccormack.net/~djm/fnkdat/

DaveOn Thu, 31 Jan 2008, matt hull wrote:


David MacCormack
@David_MacCormack

The key is that we (SuperTux) don’t do it based on current working
directory, but current executable directory, obtained through
PhysFS. It’s not as clean as it could be since it differentiates
between Unix and Windows when both can be handled by the same code.
Hmm, I should go fix that. It also does funny stuff with char * where
std::string is clearer and less error-prone. I should fix that too.

Tim