@@ -37,61 +37,61 @@ void assetInit(bool devMode, std::string customGlobalDir, std::string customLoca | |||||
if (customGlobalDir.empty()) { | if (customGlobalDir.empty()) { | ||||
#if ARCH_MAC | #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; | |||||
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; | |||||
#endif | #endif | ||||
#if ARCH_WIN | #if ARCH_WIN | ||||
char moduleBuf[MAX_PATH]; | |||||
DWORD length = GetModuleFileName(NULL, moduleBuf, sizeof(moduleBuf)); | |||||
assert(length > 0); | |||||
PathRemoveFileSpec(moduleBuf); | |||||
globalDir = moduleBuf; | |||||
char moduleBuf[MAX_PATH]; | |||||
DWORD length = GetModuleFileName(NULL, moduleBuf, sizeof(moduleBuf)); | |||||
assert(length > 0); | |||||
PathRemoveFileSpec(moduleBuf); | |||||
globalDir = moduleBuf; | |||||
#endif | #endif | ||||
#if ARCH_LIN | #if ARCH_LIN | ||||
// TODO For now, users should launch Rack from their terminal in the global directory | |||||
globalDir = "."; | |||||
// TODO For now, users should launch Rack from their terminal in the global directory | |||||
globalDir = "."; | |||||
#endif | #endif | ||||
} | } | ||||
else { | else { | ||||
globalDir = customGlobalDir; | |||||
globalDir = customGlobalDir; | |||||
} | } | ||||
if (customLocalDir.empty()) { | if (customLocalDir.empty()) { | ||||
#if ARCH_MAC | #if ARCH_MAC | ||||
// Get home directory | |||||
struct passwd *pw = getpwuid(getuid()); | |||||
assert(pw); | |||||
localDir = pw->pw_dir; | |||||
localDir += "/Documents/Rack"; | |||||
// Get home directory | |||||
struct passwd *pw = getpwuid(getuid()); | |||||
assert(pw); | |||||
localDir = pw->pw_dir; | |||||
localDir += "/Documents/Rack"; | |||||
#endif | #endif | ||||
#if ARCH_WIN | #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); | |||||
localDir = documentsBuf; | |||||
localDir += "/Rack"; | |||||
// 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"; | |||||
#endif | #endif | ||||
#if ARCH_LIN | #if ARCH_LIN | ||||
// Get home directory | |||||
const char *homeBuf = getenv("HOME"); | |||||
if (!homeBuf) { | |||||
struct passwd *pw = getpwuid(getuid()); | |||||
assert(pw); | |||||
homeBuf = pw->pw_dir; | |||||
} | |||||
localDir = homeBuf; | |||||
localDir += "/.Rack"; | |||||
// Get home directory | |||||
const char *homeBuf = getenv("HOME"); | |||||
if (!homeBuf) { | |||||
struct passwd *pw = getpwuid(getuid()); | |||||
assert(pw); | |||||
homeBuf = pw->pw_dir; | |||||
} | |||||
localDir = homeBuf; | |||||
localDir += "/.Rack"; | |||||
#endif | #endif | ||||
} | } | ||||
else { | else { | ||||
localDir = customLocalDir; | |||||
localDir = customLocalDir; | |||||
} | } | ||||
} | } | ||||
@@ -30,47 +30,47 @@ int main(int argc, char* argv[]) { | |||||
// Parse command line arguments | // Parse command line arguments | ||||
argagg::parser argparser {{ | argagg::parser argparser {{ | ||||
{ "help", {"-h", "--help"}, "shows this help message", 0}, | |||||
{ "devmod", {"-d", "--devmod"}, "enables dev mode (supersedes local/global folders)", 0}, | |||||
{ "global", {"-g", "--globaldir"}, "set golbalDir", 1}, | |||||
{ "local", {"-l", "--localdir"}, "set localDir", 1}, | |||||
{ "port", {"-p", "--port"}, "Bridge port number", 1}, | |||||
{ "help", {"-h", "--help"}, "shows this help message", 0}, | |||||
{ "devmod", {"-d", "--devmod"}, "enables dev mode (supersedes local/global folders)", 0}, | |||||
{ "global", {"-g", "--globaldir"}, "set golbalDir", 1}, | |||||
{ "local", {"-l", "--localdir"}, "set localDir", 1}, | |||||
{ "port", {"-p", "--port"}, "Bridge port number", 1}, | |||||
}}; | }}; | ||||
argagg::parser_results args; | argagg::parser_results args; | ||||
try { | try { | ||||
args = argparser.parse(argc, argv); | |||||
args = argparser.parse(argc, argv); | |||||
} catch (const std::exception& e) { | } catch (const std::exception& e) { | ||||
std::cerr << "Encountered exception while parsing arguments: " << e.what() << std::endl; | |||||
return EXIT_FAILURE; | |||||
std::cerr << "Encountered exception while parsing arguments: " << e.what() << std::endl; | |||||
return EXIT_FAILURE; | |||||
} | } | ||||
if (args["help"]) { | if (args["help"]) { | ||||
std::cerr << "Usage: program [options] [FILENAME]" << std::endl; | |||||
std::cerr << argparser; | |||||
return EXIT_SUCCESS; | |||||
std::cerr << "Usage: program [options] [FILENAME]" << std::endl; | |||||
std::cerr << argparser; | |||||
return EXIT_SUCCESS; | |||||
} | } | ||||
if (args["devmod"]) { | if (args["devmod"]) { | ||||
devMode = true; | |||||
devMode = true; | |||||
} | } | ||||
if (args["global"]) { | if (args["global"]) { | ||||
customGlobalDir = args["global"].as<std::string>(); | |||||
customGlobalDir = args["global"].as<std::string>(); | |||||
} | } | ||||
if (args["local"]) { | if (args["local"]) { | ||||
customLocalDir = args["local"].as<std::string>(); | |||||
customLocalDir = args["local"].as<std::string>(); | |||||
} | } | ||||
if (args["port"]) { | if (args["port"]) { | ||||
customBridgePort = args["port"].as<int>(); | |||||
customBridgePort = args["port"].as<int>(); | |||||
} | } | ||||
// Filename as first positional argument | // Filename as first positional argument | ||||
if (args.pos.size() > 0) { | if (args.pos.size() > 0) { | ||||
patchFile = args.as<std::string>(0); | |||||
patchFile = args.as<std::string>(0); | |||||
} | } | ||||
// Initialize environment | // Initialize environment | ||||
@@ -90,10 +90,10 @@ int main(int argc, char* argv[]) { | |||||
engineInit(); | engineInit(); | ||||
rtmidiInit(); | rtmidiInit(); | ||||
if (customBridgePort > 0) { | if (customBridgePort > 0) { | ||||
bridgeInit(customBridgePort); | |||||
bridgeInit(customBridgePort); | |||||
} | } | ||||
else { | else { | ||||
bridgeInit(); | |||||
bridgeInit(); | |||||
} | } | ||||
keyboardInit(); | keyboardInit(); | ||||
gamepadInit(); | gamepadInit(); | ||||