libgdx / packr

Packages your JAR, assets and a JVM for distribution on Windows, Linux and Mac OS X
Apache License 2.0
2.57k stars 171 forks source link

Load configuration file relative to executable location, not working directory #221

Closed TypeSafeSchwalbe closed 2 years ago

TypeSafeSchwalbe commented 2 years ago

Currently, when building my application using packr, the executable loads the configuration file relative to the current working directory. So when having a file structure like this...

- Desktop
    - <App>Build << current working directory
        - <App>.exe
        - <App>.json << the configuration is here - executable expects configuration to be here
    - DifferentDirectory
        - test.png
        - ...

It works fine. But if the current working directory is changed...

- Desktop
    - <App>Build
        - <App>.exe
        - <App>.json << the configuration is here
    - DifferentDirectory << current working directory
        - test.png
        - ... << executable expects configuration to be here (it is not)

The executable suddenly does not know where the configuration file is. That is to be expected, as it seems to be looking in the current working directory.

I am building a command line app and want to be able to put the executable inside of the PATH, so that I call it from anywhere on my system. Running the executable fails, because it cannot find the configuration file.

Error: failed to load configuration: <App>.json

Is there some way to tell it to look where the executable is stored, not where the executable is run?

karlsabo commented 2 years ago

It's not possible. You could patch the C++ code to find the executable location and load the config file relative to the executable path.