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

Function initUserDir

src/asset.cpp:94–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92
93
94static void initUserDir() {
95 if (!userDir.empty())
96 return;
97
98 if (settings::devMode) {
99 userDir = systemDir;
100 return;
101 }
102
103 // Environment variable overrides
104 const char* envUser = getenv("RACK_USER_DIR");
105 if (envUser) {
106 userDir = envUser;
107 return;
108 }
109
110#if defined ARCH_WIN
111 // Get AppData/Local path
112 WCHAR localBufW[MAX_PATH] = {};
113 HRESULT localH = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, localBufW);
114 assert(SUCCEEDED(localH));
115 std::string localDir = string::UTF16toUTF8(localBufW);
116
117 // Usually C:/Users/<username>/AppData/Local/Rack2
118 userDir = system::join(localDir, "Rack" + APP_VERSION_MAJOR);
119
120 // Get Documents path
121 WCHAR documentsBufW[MAX_PATH] = {};
122 HRESULT documentsH = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW);
123 assert(SUCCEEDED(documentsH));
124 std::string documentsDir = string::UTF16toUTF8(documentsBufW);
125
126 // Rack <2.5.0 used "My Documents/Rack2"
127 oldUserDir = system::join(documentsDir, "Rack" + APP_VERSION_MAJOR);
128#endif
129
130#if defined ARCH_MAC
131 // Usually ~/Library/Application Support/Rack2
132 userDir = system::join(getApplicationSupportDir(), "Rack" + APP_VERSION_MAJOR);
133
134 // Get home directory
135 struct passwd* pw = getpwuid(getuid());
136 assert(pw);
137 std::string homeDir = pw->pw_dir;
138
139 // Rack <2.5.0 used ~/Documents/Rack2
140 oldUserDir = system::join(homeDir, "Documents", "Rack" + APP_VERSION_MAJOR);
141#endif
142
143#if defined ARCH_LIN
144 // Get home path
145 const char* homeBuf = getenv("HOME");
146 if (!homeBuf) {
147 struct passwd* pw = getpwuid(getuid());
148 assert(pw);
149 homeBuf = pw->pw_dir;
150 }
151 std::string homeDir = homeBuf;

Callers 1

initFunction · 0.85

Calls 6

UTF16toUTF8Function · 0.85
isDirectoryFunction · 0.85
renameFunction · 0.85
createDirectoryFunction · 0.85
joinFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected