diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-24 08:48:40 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-24 08:48:40 +0200 |
commit | b0bcb98681e3076a44ec80cee306d14b7e6df094 (patch) | |
tree | c825c98874b47bc39c3cc5796cb039f0c9af7063 /src/app.c | |
parent | 71bcd9c1bd7174c6eb49a0a36f5b84bcd9dac3b8 (diff) |
App: Finding the resources file
While the hardcoded path is still there, it is now checked in addition to the normal executable-relative paths, not replacing them.
IssueID #395
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 34 |
1 files changed, 23 insertions, 11 deletions
@@ -94,17 +94,14 @@ static const char *defaultDataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange" | |||
94 | #endif | 94 | #endif |
95 | #if defined (iPlatformLinux) || defined (iPlatformOther) | 95 | #if defined (iPlatformLinux) || defined (iPlatformOther) |
96 | #define EMB_BIN "../../share/lagrange/resources.lgr" | 96 | #define EMB_BIN "../../share/lagrange/resources.lgr" |
97 | #define EMB_BIN2 "../../../share/lagrange/resources.lgr" | ||
97 | static const char *defaultDataDir_App_ = "~/.config/lagrange"; | 98 | static const char *defaultDataDir_App_ = "~/.config/lagrange"; |
98 | #endif | 99 | #endif |
99 | #if defined (iPlatformHaiku) | 100 | #if defined (iPlatformHaiku) |
100 | #define EMB_BIN "./resources.lgr" | 101 | #define EMB_BIN "./resources.lgr" |
101 | static const char *defaultDataDir_App_ = "~/config/settings/lagrange"; | 102 | static const char *defaultDataDir_App_ = "~/config/settings/lagrange"; |
102 | #endif | 103 | #endif |
103 | #if defined (LAGRANGE_EMB_BIN) /* specified in build config */ | 104 | #define EMB_BIN_EXEC "../resources.lgr" /* fallback from build/executable dir */ |
104 | # undef EMB_BIN | ||
105 | # define EMB_BIN LAGRANGE_EMB_BIN | ||
106 | #endif | ||
107 | #define EMB_BIN2 "../resources.lgr" /* fallback from build/executable dir */ | ||
108 | static const char *prefsFileName_App_ = "prefs.cfg"; | 105 | static const char *prefsFileName_App_ = "prefs.cfg"; |
109 | static const char *oldStateFileName_App_ = "state.binary"; | 106 | static const char *oldStateFileName_App_ = "state.binary"; |
110 | static const char *stateFileName_App_ = "state.lgr"; | 107 | static const char *stateFileName_App_ = "state.lgr"; |
@@ -722,14 +719,29 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
722 | } | 719 | } |
723 | /* Load the resources from a file. Check the executable directory first, then a | 720 | /* Load the resources from a file. Check the executable directory first, then a |
724 | system-wide location, and as a final fallback, the current working directory. */ { | 721 | system-wide location, and as a final fallback, the current working directory. */ { |
725 | if (!init_Resources(concatPath_CStr(cstr_String(execPath_App()), EMB_BIN2))) { | 722 | const char *execPath = cstr_String(execPath_App()); |
726 | if (!init_Resources(concatPath_CStr(cstr_String(execPath_App()), EMB_BIN))) { | 723 | const char *paths[] = { |
727 | if (!init_Resources("resources.lgr")) { | 724 | concatPath_CStr(execPath, EMB_BIN_EXEC), /* first the executable's directory */ |
728 | fprintf(stderr, "failed to load resources: %s\n", strerror(errno)); | 725 | #if defined (LAGRANGE_EMB_BIN) /* specified in build config (absolute path) */ |
729 | exit(-1); | 726 | LAGRANGE_EMB_BIN, |
730 | } | 727 | #endif |
728 | #if defined (EMB_BIN2) /* alternative location */ | ||
729 | concatPath_CStr(execPath, EMB_BIN2), | ||
730 | #endif | ||
731 | concatPath_CStr(execPath, EMB_BIN), | ||
732 | "resources.lgr" /* cwd */ | ||
733 | }; | ||
734 | iBool wasLoaded = iFalse; | ||
735 | iForIndices(i, paths) { | ||
736 | if (init_Resources(paths[i])) { | ||
737 | wasLoaded = iTrue; | ||
738 | break; | ||
731 | } | 739 | } |
732 | } | 740 | } |
741 | if (!wasLoaded) { | ||
742 | fprintf(stderr, "failed to load resources: %s\n", strerror(errno)); | ||
743 | exit(-1); | ||
744 | } | ||
733 | } | 745 | } |
734 | init_Lang(); | 746 | init_Lang(); |
735 | /* Configure the valid command line options. */ { | 747 | /* Configure the valid command line options. */ { |