@@ -31,6 +31,8 @@ extern std::string pluginsPath; | |||||
extern std::string settingsPath; | extern std::string settingsPath; | ||||
extern std::string autosavePath; | extern std::string autosavePath; | ||||
extern std::string templatePath; | extern std::string templatePath; | ||||
// Only defined on Mac | |||||
extern std::string bundlePath; | |||||
} // namespace asset | } // namespace asset | ||||
@@ -18,6 +18,7 @@ enum Method { | |||||
METHOD_DELETE, | METHOD_DELETE, | ||||
}; | }; | ||||
void init(); | |||||
/** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) | /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) | ||||
Caller must json_decref(). | Caller must json_decref(). | ||||
*/ | */ | ||||
@@ -37,9 +37,19 @@ void init() { | |||||
#if defined ARCH_MAC | #if defined ARCH_MAC | ||||
CFBundleRef bundle = CFBundleGetMainBundle(); | CFBundleRef bundle = CFBundleGetMainBundle(); | ||||
assert(bundle); | assert(bundle); | ||||
CFURLRef bundleUrl = CFBundleCopyBundleURL(bundle); | |||||
char bundleBuf[PATH_MAX]; | |||||
Boolean success = CFURLGetFileSystemRepresentation(bundleUrl, TRUE, (UInt8*) bundleBuf, sizeof(bundleBuf)); | |||||
assert(success); | |||||
bundlePath = bundleBuf; | |||||
// If the bundle path doesn't end with ".app", assume it's a fake app bundle run from the command line. | |||||
if (string::filenameExtension(string::filename(bundlePath)) != "app") | |||||
bundlePath = ""; | |||||
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle); | CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle); | ||||
char resourcesBuf[PATH_MAX]; | char resourcesBuf[PATH_MAX]; | ||||
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf)); | |||||
success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf)); | |||||
assert(success); | assert(success); | ||||
CFRelease(resourcesUrl); | CFRelease(resourcesUrl); | ||||
systemDir = resourcesBuf; | systemDir = resourcesBuf; | ||||
@@ -145,6 +155,7 @@ std::string pluginsPath; | |||||
std::string settingsPath; | std::string settingsPath; | ||||
std::string autosavePath; | std::string autosavePath; | ||||
std::string templatePath; | std::string templatePath; | ||||
std::string bundlePath; | |||||
} // namespace asset | } // namespace asset | ||||
@@ -17,6 +17,7 @@ | |||||
#include <system.hpp> | #include <system.hpp> | ||||
#include <string.hpp> | #include <string.hpp> | ||||
#include <updater.hpp> | #include <updater.hpp> | ||||
#include <network.hpp> | |||||
#include <osdialog.h> | #include <osdialog.h> | ||||
#include <thread> | #include <thread> | ||||
@@ -97,6 +98,7 @@ int main(int argc, char* argv[]) { | |||||
patchPath = argv[optind]; | patchPath = argv[optind]; | ||||
} | } | ||||
// Initialize environment | |||||
asset::init(); | asset::init(); | ||||
logger::init(); | logger::init(); | ||||
@@ -145,6 +147,7 @@ int main(int argc, char* argv[]) { | |||||
INFO("Initializing environment"); | INFO("Initializing environment"); | ||||
random::init(); | random::init(); | ||||
network::init(); | |||||
midi::init(); | midi::init(); | ||||
rtmidiInit(); | rtmidiInit(); | ||||
bridgeInit(); | bridgeInit(); | ||||
@@ -30,6 +30,13 @@ static size_t writeStringCallback(char* ptr, size_t size, size_t nmemb, void* us | |||||
} | } | ||||
void init() { | |||||
// curl_easy_init() calls this automatically, but it's good to make sure this is done on the main thread before other threads are spawned. | |||||
// https://curl.haxx.se/libcurl/c/curl_easy_init.html | |||||
curl_global_init(CURL_GLOBAL_ALL); | |||||
} | |||||
json_t* requestJson(Method method, std::string url, json_t* dataJ) { | json_t* requestJson(Method method, std::string url, json_t* dataJ) { | ||||
CURL* curl = createCurl(); | CURL* curl = createCurl(); | ||||
char* reqStr = NULL; | char* reqStr = NULL; | ||||
@@ -74,8 +74,19 @@ void update() { | |||||
INFO("Launching update %s", path.c_str()); | INFO("Launching update %s", path.c_str()); | ||||
system::runProcessDetached(path); | system::runProcessDetached(path); | ||||
#elif defined ARCH_MAC | #elif defined ARCH_MAC | ||||
// Unzip app using Apple's unzipper, since Rack's unzipper doesn't handle the metadata stuff correctly. | |||||
std::string cmd = "open \"" + path + "\""; | |||||
std::string cmd; | |||||
// std::string appPath = asset::userDir + "/Rack.app"; | |||||
// cmd = "rm -rf '" + appPath + "'"; | |||||
// std::system(cmd.c_str()); | |||||
// // Unzip app using Apple's unzipper, since Rack's unzipper doesn't handle the metadata stuff correctly. | |||||
// cmd = "unzip -q '" + path + "' -d '" + asset::userDir + "'"; | |||||
// std::system(cmd.c_str()); | |||||
// // Open app in Finder | |||||
// cmd = "open -R '" + appPath + "'"; | |||||
// std::system(cmd.c_str()); | |||||
// Open Archive Utility | |||||
cmd = "open '" + path + "'"; | |||||
std::system(cmd.c_str()); | std::system(cmd.c_str()); | ||||
#else | #else | ||||
system::openBrowser(downloadUrl); | system::openBrowser(downloadUrl); | ||||