MCPcopy Create free account
hub / github.com/VCVRack/Rack / initSystemDir

Function initSystemDir

src/asset.cpp:40–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40static void initSystemDir() {
41 if (!systemDir.empty())
42 return;
43
44 if (settings::devMode) {
45 systemDir = system::getWorkingDirectory();
46 return;
47 }
48
49 // Environment variable overrides
50 const char* envSystem = getenv("RACK_SYSTEM_DIR");
51 if (envSystem) {
52 systemDir = envSystem;
53 return;
54 }
55
56#if defined ARCH_MAC
57 CFBundleRef bundle = CFBundleGetMainBundle();
58 assert(bundle);
59
60 // Check if we're running as a command-line program or an app bundle.
61 CFURLRef bundleUrl = CFBundleCopyBundleURL(bundle);
62 // Thanks Ken Thomases! https://stackoverflow.com/a/58369256/272642
63 CFStringRef uti;
64 if (CFURLCopyResourcePropertyForKey(bundleUrl, kCFURLTypeIdentifierKey, &uti, NULL) && uti && UTTypeConformsTo(uti, kUTTypeApplicationBundle)) {
65 char bundleBuf[PATH_MAX];
66 Boolean success = CFURLGetFileSystemRepresentation(bundleUrl, TRUE, (UInt8*) bundleBuf, sizeof(bundleBuf));
67 assert(success);
68 bundlePath = bundleBuf;
69 }
70
71 CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
72 char resourcesBuf[PATH_MAX];
73 Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
74 assert(success);
75 CFRelease(resourcesUrl);
76 systemDir = resourcesBuf;
77#endif
78#if defined ARCH_WIN
79 // Get path to executable
80 wchar_t moduleBufW[MAX_PATH] = L"";
81 DWORD length = GetModuleFileNameW(NULL, moduleBufW, LENGTHOF(moduleBufW));
82 assert(length > 0);
83 // Get directory of executable
84 PathRemoveFileSpecW(moduleBufW);
85 systemDir = string::UTF16toUTF8(moduleBufW);
86#endif
87#if defined ARCH_LIN
88 // Use the current working directory as the default path on Linux.
89 systemDir = system::getWorkingDirectory();
90#endif
91}
92
93
94static void initUserDir() {

Callers 1

initFunction · 0.85

Calls 3

getWorkingDirectoryFunction · 0.85
UTF16toUTF8Function · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected