diff --git a/include/app/common.hpp b/include/app/common.hpp index 4beabedb..21c3496a 100644 --- a/include/app/common.hpp +++ b/include/app/common.hpp @@ -17,6 +17,7 @@ extern std::string APP_VERSION; extern std::string APP_VERSION_UPDATE; extern std::string API_URL; extern std::string API_VERSION; +extern std::string ABI_VERSION; static const float SVG_DPI = 75.0; static const float MM_PER_IN = 25.4; diff --git a/include/asset.hpp b/include/asset.hpp index e5124c70..e65cb512 100644 --- a/include/asset.hpp +++ b/include/asset.hpp @@ -22,9 +22,15 @@ std::string user(std::string filename); std::string plugin(plugin::Plugin *plugin, std::string filename); +// Set these before calling init() to override the default paths extern std::string systemDir; extern std::string userDir; +extern std::string pluginsPath; +extern std::string settingsPath; +extern std::string autosavePath; +extern std::string templatePath; + } // namespace asset } // namespace rack diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 26d18df6..3c6cf214 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -43,8 +43,8 @@ void Scene::step() { double time = glfwGetTime(); if (time - lastAutosaveTime >= settings::autosavePeriod) { lastAutosaveTime = time; - APP->patch->save(asset::user("autosave.vcv")); - settings::save(asset::user("settings.json")); + APP->patch->save(asset::autosavePath); + settings::save(asset::settingsPath); } } diff --git a/src/app/common.cpp b/src/app/common.cpp index 118fcf80..9524531c 100644 --- a/src/app/common.cpp +++ b/src/app/common.cpp @@ -13,6 +13,7 @@ std::string APP_VERSION = TOSTRING(VERSION); std::string APP_VERSION_UPDATE; std::string API_URL = "https://api.vcvrack.com"; std::string API_VERSION = "1"; +std::string ABI_VERSION = "1"; static void checkVersion() { diff --git a/src/asset.cpp b/src/asset.cpp index 636fadc4..e833d781 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #if defined ARCH_MAC #include @@ -102,6 +103,20 @@ void init() { system::createDirectory(systemDir); system::createDirectory(userDir); + + // Set paths + if (settings::devMode) { + pluginsPath = userDir + "/plugins"; + settingsPath = userDir + "/settings.json"; + autosavePath = userDir + "/autosave.vcv"; + templatePath = userDir + "/template.vcv"; + } + else { + pluginsPath = userDir + "/plugins-v" + app::ABI_VERSION; + settingsPath = userDir + "/settings-v" + app::ABI_VERSION + ".json"; + autosavePath = userDir + "/autosave-v" + app::ABI_VERSION + ".vcv"; + templatePath = userDir + "/template-v" + app::ABI_VERSION + ".vcv"; + } } @@ -124,6 +139,11 @@ std::string plugin(plugin::Plugin *plugin, std::string filename) { std::string systemDir; std::string userDir; +std::string pluginsPath; +std::string settingsPath; +std::string autosavePath; +std::string templatePath; + } // namespace asset } // namespace rack diff --git a/src/main.cpp b/src/main.cpp index 645d0a0d..e187bada 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -113,7 +114,7 @@ int main(int argc, char *argv[]) { // Load settings try { - settings::load(asset::user("settings.json")); + settings::load(asset::settingsPath); } catch (UserException &e) { std::string msg = e.what(); @@ -179,11 +180,11 @@ int main(int argc, char *argv[]) { // Destroy app if (!settings::headless) { - APP->patch->save(asset::user("autosave.vcv")); + APP->patch->save(asset::autosavePath); } INFO("Destroying app"); appDestroy(); - settings::save(asset::user("settings.json")); + settings::save(asset::settingsPath); // Destroy environment INFO("Destroying environment"); diff --git a/src/patch.cpp b/src/patch.cpp index 337b1b39..cafae0f0 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -35,7 +36,7 @@ void PatchManager::init(std::string path) { // To prevent launch crashes, if Rack crashes between now and 15 seconds from now, the "skipAutosaveOnLaunch" property will remain in settings.json, so that in the next launch, the broken autosave will not be loaded. bool oldSkipLoadOnLaunch = settings::skipLoadOnLaunch; settings::skipLoadOnLaunch = true; - settings::save(asset::user("settings.json")); + settings::save(asset::settingsPath); settings::skipLoadOnLaunch = false; if (oldSkipLoadOnLaunch && osdialog_message(OSDIALOG_INFO, OSDIALOG_YES_NO, "Rack has recovered from a crash, possibly caused by a faulty module in your patch. Clear your patch and start over?")) { this->path = ""; @@ -43,7 +44,7 @@ void PatchManager::init(std::string path) { } // Load autosave - if (load(asset::user("autosave.vcv"))) { + if (load(asset::autosavePath)) { return; } @@ -56,7 +57,7 @@ void PatchManager::reset() { APP->scene->rackScroll->reset(); path = ""; - if (load(asset::user("template.vcv"))) { + if (load(asset::templatePath)) { return; } @@ -145,7 +146,7 @@ void PatchManager::saveTemplateDialog() { if (!osdialog_message(OSDIALOG_INFO, OSDIALOG_OK_CANCEL, "Overwrite template patch?")) return; - save(asset::user("template.vcv")); + save(asset::templatePath); } bool PatchManager::load(std::string path) { diff --git a/src/plugin.cpp b/src/plugin.cpp index 8e225bf3..293737e2 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -261,19 +261,18 @@ void init() { loadPlugin(""); // Get user plugins directory - std::string pluginsDir = asset::user("plugins"); - mkdir(pluginsDir.c_str(), 0755); + mkdir(asset::pluginsPath.c_str(), 0755); // Extract packages and load plugins - extractPackages(pluginsDir); - loadPlugins(pluginsDir); + extractPackages(asset::pluginsPath); + loadPlugins(asset::pluginsPath); // If Fundamental wasn't loaded, copy the bundled Fundamental package and load it std::string fundamentalSrc = asset::system("Fundamental.zip"); - std::string fundamentalDir = asset::user("plugins/Fundamental"); + std::string fundamentalDir = asset::pluginsPath + "/Fundamental"; if (!settings::devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) { INFO("Extracting bundled Fundamental package"); - extractZip(fundamentalSrc.c_str(), pluginsDir.c_str()); + extractZip(fundamentalSrc.c_str(), asset::pluginsPath.c_str()); loadPlugin(fundamentalDir); } @@ -473,7 +472,7 @@ void syncUpdate(Update *update) { INFO("Downloading plugin %s %s %s", update->pluginSlug.c_str(), update->version.c_str(), arch.c_str()); // Download zip - std::string pluginDest = asset::user("plugins/" + update->pluginSlug + ".zip"); + std::string pluginDest = asset::pluginsPath + "/" + update->pluginSlug + ".zip"; if (!network::requestDownload(downloadUrl, pluginDest, &update->progress)) { WARN("Plugin %s download was unsuccessful", update->pluginSlug.c_str()); return;