MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / Load_IniFile

Function Load_IniFile

src/inifile.c:35–126  ·  view source on GitHub ↗

* Find and read the opendune.ini file * * @return True if and only if opendune.ini file was found and read. */

Source from the content-addressed store, hash-verified

33 * @return True if and only if opendune.ini file was found and read.
34 */
35bool Load_IniFile(void)
36{
37 FILE *f = NULL;
38 long fileSize;
39 /* look for opendune.ini in the following locations :
40 1) %APPDATA%/OpenDUNE (win32)
41 ~/Library/Application Support/OpenDUNE (Mac OS X)
42 ~/.config/opendune (Linux)
43 2) current directory
44 3) data/ dir
45 4) parent of bundle dir (Mac OS X)
46 */
47#if defined(_WIN32)
48 TCHAR path[MAX_PATH];
49 if (SHGetFolderPath( NULL, CSIDL_APPDATA/*CSIDL_COMMON_APPDATA*/, NULL, 0, path ) != S_OK) {
50 Warning("Cannot find AppData directory.\n");
51 } else {
52 PathAppend(path, TEXT("OpenDUNE\\opendune.ini"));
53 f = fopen(path, "rb");
54 }
55#elif !defined(TOS) && !defined(DOS) /* _WIN32 */
56 char path[PATH_MAX];
57 char * homeDir;
58 homeDir = getenv("HOME");
59 if (homeDir != NULL) {
60#if defined(__APPLE__)
61 snprintf(path, sizeof(path), "%s/Library/Application Support/OpenDUNE/opendune.ini", homeDir);
62#else /* __APPLE__ */
63 snprintf(path, sizeof(path), "%s/.config/opendune/opendune.ini", homeDir);
64#endif /* __APPLE__ */
65 f = fopen(path, "rb");
66 }
67#endif /* not TOS, not _WIN32 */
68 if (f == NULL) {
69 /* current directory */
70 f = fopen("opendune.ini", "rb");
71 }
72 if (f == NULL) {
73 f = fopen("data/opendune.ini", "rb");
74 }
75#ifdef OSX
76 if (f == NULL) {
77 CFBundleRef mainBundle = CFBundleGetMainBundle();
78 if (mainBundle != NULL) {
79 CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle);
80 if (bundleURL != NULL) {
81 size_t len;
82 CFStringRef bundleDir = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
83 CFStringGetFileSystemRepresentation(bundleDir, path, sizeof(path));
84 len = strlen(path);
85 strncpy(path + len, "/../opendune.ini", sizeof(path) - len);
86 Debug("trying to open %s\n", path);
87 f = fopen(path, "rb");
88 CFRelease(bundleDir);
89 CFRelease(bundleURL);
90 }
91 }
92 }

Callers 1

mainFunction · 0.85

Calls 5

snprintfFunction · 0.85
freeFunction · 0.85
WarningFunction · 0.50
DebugFunction · 0.50
ErrorFunction · 0.50

Tested by

no test coverage detected