Browse Source

Add -g and -l command line arguments

tags/v0.6.2b
Andrew Belt 6 years ago
parent
commit
9d1d08105d
3 changed files with 73 additions and 50 deletions
  1. +4
    -0
      include/asset.hpp
  2. +62
    -49
      src/asset.cpp
  3. +7
    -1
      src/main.cpp

+ 4
- 0
include/asset.hpp View File

@@ -16,4 +16,8 @@ std::string assetLocal(std::string filename);
std::string assetPlugin(Plugin *plugin, std::string filename);


extern std::string assetGlobalDir;
extern std::string assetLocalDir;


} // namespace rack

+ 62
- 49
src/asset.cpp View File

@@ -23,73 +23,86 @@
namespace rack {


static std::string globalDir;
static std::string localDir;
std::string assetGlobalDir;
std::string assetLocalDir;


void assetInit(bool devMode) {
if (devMode) {
// Use current working directory if running in development mode
globalDir = ".";
localDir = ".";
return;
}

if (assetGlobalDir.empty()) {
if (devMode) {
assetGlobalDir = ".";
}
else {
#if ARCH_MAC
CFBundleRef bundle = CFBundleGetMainBundle();
assert(bundle);
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
char resourcesBuf[PATH_MAX];
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
assert(success);
CFRelease(resourcesUrl);
globalDir = resourcesBuf;

// Get home directory
struct passwd *pw = getpwuid(getuid());
assert(pw);
localDir = pw->pw_dir;
localDir += "/Documents/Rack";
CFBundleRef bundle = CFBundleGetMainBundle();
assert(bundle);
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
char resourcesBuf[PATH_MAX];
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
assert(success);
CFRelease(resourcesUrl);
assetGlobalDir = resourcesBuf;
#endif
#if ARCH_WIN
char moduleBuf[MAX_PATH];
DWORD length = GetModuleFileName(NULL, moduleBuf, sizeof(moduleBuf));
assert(length > 0);
PathRemoveFileSpec(moduleBuf);
globalDir = moduleBuf;

// Get "My Documents" folder
char documentsBuf[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBuf);
assert(result == S_OK);
localDir = documentsBuf;
localDir += "/Rack";
char moduleBuf[MAX_PATH];
DWORD length = GetModuleFileName(NULL, moduleBuf, sizeof(moduleBuf));
assert(length > 0);
PathRemoveFileSpec(moduleBuf);
assetGlobalDir = moduleBuf;
#endif
#if ARCH_LIN
// TODO For now, users should launch Rack from their terminal in the global directory
globalDir = ".";

// Get home directory
const char *homeBuf = getenv("HOME");
if (!homeBuf) {
struct passwd *pw = getpwuid(getuid());
assert(pw);
homeBuf = pw->pw_dir;
// TODO For now, users should launch Rack from their terminal in the global directory
assetGlobalDir = ".";
#endif
}
}
localDir = homeBuf;
localDir += "/.Rack";

if (assetLocalDir.empty()) {
if (devMode) {
assetLocalDir = ".";
}
else {
#if ARCH_WIN
// Get "My Documents" folder
char documentsBuf[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBuf);
assert(result == S_OK);
assetLocalDir = documentsBuf;
assetLocalDir += "/Rack";
#endif
systemCreateDirectory(localDir);
#if ARCH_MAC
// Get home directory
struct passwd *pw = getpwuid(getuid());
assert(pw);
assetLocalDir = pw->pw_dir;
assetLocalDir += "/Documents/Rack";
#endif
#if ARCH_LIN
// Get home directory
const char *homeBuf = getenv("HOME");
if (!homeBuf) {
struct passwd *pw = getpwuid(getuid());
assert(pw);
homeBuf = pw->pw_dir;
}
assetLocalDir = homeBuf;
assetLocalDir += "/.Rack";
#endif
}
}

systemCreateDirectory(assetGlobalDir);
systemCreateDirectory(assetLocalDir);
}


std::string assetGlobal(std::string filename) {
return globalDir + "/" + filename;
return assetGlobalDir + "/" + filename;
}


std::string assetLocal(std::string filename) {
return localDir + "/" + filename;
return assetLocalDir + "/" + filename;
}




+ 7
- 1
src/main.cpp View File

@@ -26,11 +26,17 @@ int main(int argc, char* argv[]) {
// Parse command line arguments
int c;
opterr = 0;
while ((c = getopt(argc, argv, "d")) != -1) {
while ((c = getopt(argc, argv, "dg:l:")) != -1) {
switch (c) {
case 'd': {
devMode = true;
} break;
case 'g': {
assetGlobalDir = optarg;
} break;
case 'l': {
assetLocalDir = optarg;
} break;
default: break;
}
}


Loading…
Cancel
Save