- Joined
- Aug 18, 2009
- Messages
- 4,099
Hi,
This basic problem keeps nagging me. My applications do not consist of a single file but draw in further script data and other media from the file system (Windows) dynamically. To find these assets, ofc I do not want to use absolute paths but relative paths according to the directory structure. But all the io functions (in Windows at least) base the given relative paths on the current working directory of the process. So when I load in a script file from another directory, the working directory no longer matches the path the now executing file resides in and therefore I cannot specify the paths relative to the executing file anymore. Moreover, even the entry points can be launched from another location, which is why it seems to me, to have any integrity at all, you have to change the working directory when starting an application.
The solution I have been using to this date is to either do that or to include a method to determine the local directory + transformation functions. But it's annoying to have to add this method everywhere, in each and every single entry point. Also it's language-dependent and e.g. in Lua, you cannot statically link it, so the option is to directly inline the implementation in the same file (which does not work either because in this case I need the help of a dll) or to specify the location of the library explicitly, just so I can draw in these basic functions.
An alternative is to set global environment variables, especially PATH, but well, it implies to pollute and expose to the global space and then I would have to instruct any user of my applications to set it up or I need to provide an installer.
It's very rare that I actually want to reference the working directory. On the other hand, there were countless times where I generated files in places they were not meant to be. I have written lots of small tools that call each other. Spanning new processes is recommendable but requires interface work. When calling jasshelper, I really have to wonder why it's in my domain to know that it must be started from the JNGP main directory in order to find its dlls and other stuff.
This basic problem keeps nagging me. My applications do not consist of a single file but draw in further script data and other media from the file system (Windows) dynamically. To find these assets, ofc I do not want to use absolute paths but relative paths according to the directory structure. But all the io functions (in Windows at least) base the given relative paths on the current working directory of the process. So when I load in a script file from another directory, the working directory no longer matches the path the now executing file resides in and therefore I cannot specify the paths relative to the executing file anymore. Moreover, even the entry points can be launched from another location, which is why it seems to me, to have any integrity at all, you have to change the working directory when starting an application.
The solution I have been using to this date is to either do that or to include a method to determine the local directory + transformation functions. But it's annoying to have to add this method everywhere, in each and every single entry point. Also it's language-dependent and e.g. in Lua, you cannot statically link it, so the option is to directly inline the implementation in the same file (which does not work either because in this case I need the help of a dll) or to specify the location of the library explicitly, just so I can draw in these basic functions.
An alternative is to set global environment variables, especially PATH, but well, it implies to pollute and expose to the global space and then I would have to instruct any user of my applications to set it up or I need to provide an installer.
It's very rare that I actually want to reference the working directory. On the other hand, there were countless times where I generated files in places they were not meant to be. I have written lots of small tools that call each other. Spanning new processes is recommendable but requires interface work. When calling jasshelper, I really have to wonder why it's in my domain to know that it must be started from the JNGP main directory in order to find its dlls and other stuff.