Browse Source

Add network::init(). Add asset::bundlePath.

tags/v1.1.5
Andrew Belt 5 years ago
parent
commit
1388e9ebb1
6 changed files with 38 additions and 3 deletions
  1. +2
    -0
      include/asset.hpp
  2. +1
    -0
      include/network.hpp
  3. +12
    -1
      src/asset.cpp
  4. +3
    -0
      src/main.cpp
  5. +7
    -0
      src/network.cpp
  6. +13
    -2
      src/updater.cpp

+ 2
- 0
include/asset.hpp View File

@@ -31,6 +31,8 @@ extern std::string pluginsPath;
extern std::string settingsPath;
extern std::string autosavePath;
extern std::string templatePath;
// Only defined on Mac
extern std::string bundlePath;


} // namespace asset


+ 1
- 0
include/network.hpp View File

@@ -18,6 +18,7 @@ enum Method {
METHOD_DELETE,
};

void init();
/** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc)
Caller must json_decref().
*/


+ 12
- 1
src/asset.cpp View File

@@ -37,9 +37,19 @@ void init() {
#if defined ARCH_MAC
CFBundleRef bundle = CFBundleGetMainBundle();
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);
char resourcesBuf[PATH_MAX];
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
assert(success);
CFRelease(resourcesUrl);
systemDir = resourcesBuf;
@@ -145,6 +155,7 @@ std::string pluginsPath;
std::string settingsPath;
std::string autosavePath;
std::string templatePath;
std::string bundlePath;


} // namespace asset


+ 3
- 0
src/main.cpp View File

@@ -17,6 +17,7 @@
#include <system.hpp>
#include <string.hpp>
#include <updater.hpp>
#include <network.hpp>

#include <osdialog.h>
#include <thread>
@@ -97,6 +98,7 @@ int main(int argc, char* argv[]) {
patchPath = argv[optind];
}

// Initialize environment
asset::init();
logger::init();

@@ -145,6 +147,7 @@ int main(int argc, char* argv[]) {

INFO("Initializing environment");
random::init();
network::init();
midi::init();
rtmidiInit();
bridgeInit();


+ 7
- 0
src/network.cpp View File

@@ -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) {
CURL* curl = createCurl();
char* reqStr = NULL;


+ 13
- 2
src/updater.cpp View File

@@ -74,8 +74,19 @@ void update() {
INFO("Launching update %s", path.c_str());
system::runProcessDetached(path);
#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());
#else
system::openBrowser(downloadUrl);


Loading…
Cancel
Save