@@ -40,10 +40,6 @@ extern std::string userDir; | |||||
// Only defined on Mac | // Only defined on Mac | ||||
extern std::string bundlePath; | extern std::string bundlePath; | ||||
extern std::string pluginsPath; | |||||
extern std::string settingsPath; | |||||
extern std::string templatePath; | |||||
} // namespace asset | } // namespace asset | ||||
} // namespace rack | } // namespace rack |
@@ -23,7 +23,7 @@ namespace rack { | |||||
namespace logger { | namespace logger { | ||||
extern std::string path; | |||||
extern std::string logPath; | |||||
enum Level { | enum Level { | ||||
@@ -12,6 +12,10 @@ struct PatchManager { | |||||
std::string path; | std::string path; | ||||
/** Path to autosave folder */ | /** Path to autosave folder */ | ||||
std::string autosavePath; | std::string autosavePath; | ||||
/** Path to user template patch */ | |||||
std::string templatePath; | |||||
/** Path to factory template patch */ | |||||
std::string factoryTemplatePath; | |||||
/** Append to this while loading/saving a patch to display messages to the user after success. */ | /** Append to this while loading/saving a patch to display messages to the user after success. */ | ||||
std::string warningLog; | std::string warningLog; | ||||
@@ -28,6 +28,8 @@ bool isSlugValid(const std::string& slug); | |||||
std::string normalizeSlug(const std::string& slug); | std::string normalizeSlug(const std::string& slug); | ||||
/** Path to plugins installation folder */ | |||||
extern std::string pluginsPath; | |||||
extern std::vector<Plugin*> plugins; | extern std::vector<Plugin*> plugins; | ||||
@@ -19,6 +19,10 @@ namespace rack { | |||||
namespace settings { | namespace settings { | ||||
/** Path to settings.json */ | |||||
extern std::string settingsPath; | |||||
// Runtime state, not serialized. | // Runtime state, not serialized. | ||||
extern bool devMode; | extern bool devMode; | ||||
@@ -86,6 +90,7 @@ struct ModuleUsage { | |||||
extern std::map<std::string, std::map<std::string, ModuleUsage>> moduleUsages; | extern std::map<std::string, std::map<std::string, ModuleUsage>> moduleUsages; | ||||
ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& moduleSlug); | ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& moduleSlug); | ||||
void init(); | |||||
json_t* toJson(); | json_t* toJson(); | ||||
void fromJson(json_t* rootJ); | void fromJson(json_t* rootJ); | ||||
void save(const std::string& path); | void save(const std::string& path); | ||||
@@ -83,7 +83,7 @@ void Scene::step() { | |||||
if (time - lastAutosaveTime >= settings::autosaveInterval) { | if (time - lastAutosaveTime >= settings::autosaveInterval) { | ||||
lastAutosaveTime = time; | lastAutosaveTime = time; | ||||
APP->patch->saveAutosave(); | APP->patch->saveAutosave(); | ||||
settings::save(asset::settingsPath); | |||||
settings::save(settings::settingsPath); | |||||
} | } | ||||
} | } | ||||
@@ -115,18 +115,6 @@ void init() { | |||||
initUserDir(); | initUserDir(); | ||||
system::createDirectory(userDir); | system::createDirectory(userDir); | ||||
// Set paths | |||||
if (settings::devMode) { | |||||
pluginsPath = system::join(userDir, "plugins"); | |||||
settingsPath = system::join(userDir, "settings.json"); | |||||
templatePath = system::join(userDir, "template.vcv"); | |||||
} | |||||
else { | |||||
pluginsPath = system::join(userDir, "plugins-v" + ABI_VERSION); | |||||
settingsPath = system::join(userDir, "settings-v" + ABI_VERSION + ".json"); | |||||
templatePath = system::join(userDir, "template-v" + ABI_VERSION + ".vcv"); | |||||
} | |||||
} | } | ||||
@@ -149,9 +137,6 @@ std::string plugin(plugin::Plugin* plugin, std::string filename) { | |||||
std::string systemDir; | std::string systemDir; | ||||
std::string userDir; | std::string userDir; | ||||
std::string pluginsPath; | |||||
std::string settingsPath; | |||||
std::string templatePath; | |||||
std::string bundlePath; | std::string bundlePath; | ||||
@@ -317,7 +317,7 @@ void syncUpdate(const std::string& slug) { | |||||
// Get file path | // Get file path | ||||
std::string packageFilename = slug + "-" + update.version + "-" + APP_ARCH + ".vcvplugin"; | std::string packageFilename = slug + "-" + update.version + "-" + APP_ARCH + ".vcvplugin"; | ||||
std::string packagePath = system::join(asset::pluginsPath, packageFilename); | |||||
std::string packagePath = system::join(plugin::pluginsPath, packageFilename); | |||||
// Download plugin package | // Download plugin package | ||||
if (!network::requestDownload(downloadUrl, packagePath, &updateProgress, getTokenCookies())) { | if (!network::requestDownload(downloadUrl, packagePath, &updateProgress, getTokenCookies())) { | ||||
@@ -11,7 +11,7 @@ namespace rack { | |||||
namespace logger { | namespace logger { | ||||
std::string path; | |||||
std::string logPath; | |||||
static FILE* outputFile = NULL; | static FILE* outputFile = NULL; | ||||
static std::mutex mutex; | static std::mutex mutex; | ||||
@@ -25,11 +25,11 @@ void init() { | |||||
outputFile = stderr; | outputFile = stderr; | ||||
} | } | ||||
else { | else { | ||||
path = asset::user("log.txt"); | |||||
logPath = asset::user("log.txt"); | |||||
outputFile = std::fopen(path.c_str(), "w"); | |||||
outputFile = std::fopen(logPath.c_str(), "w"); | |||||
if (!outputFile) { | if (!outputFile) { | ||||
std::fprintf(stderr, "Could not open log at %s\n", path.c_str()); | |||||
std::fprintf(stderr, "Could not open log at %s\n", logPath.c_str()); | |||||
} | } | ||||
} | } | ||||
@@ -99,11 +99,11 @@ static bool fileEndsWith(FILE* file, std::string str) { | |||||
} | } | ||||
bool isTruncated() { | bool isTruncated() { | ||||
if (path.empty()) | |||||
if (logPath.empty()) | |||||
return false; | return false; | ||||
// Open existing log file | // Open existing log file | ||||
FILE* file = std::fopen(path.c_str(), "r"); | |||||
FILE* file = std::fopen(logPath.c_str(), "r"); | |||||
if (!file) | if (!file) | ||||
return false; | return false; | ||||
DEFER({std::fclose(file);}); | DEFER({std::fclose(file);}); | ||||
@@ -25,10 +25,13 @@ static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv"; | |||||
PatchManager::PatchManager() { | PatchManager::PatchManager() { | ||||
if (settings::devMode) { | if (settings::devMode) { | ||||
autosavePath = asset::user("autosave"); | autosavePath = asset::user("autosave"); | ||||
templatePath = asset::user("template.vcv"); | |||||
} | } | ||||
else { | else { | ||||
autosavePath = asset::user("autosave-v" + ABI_VERSION); | autosavePath = asset::user("autosave-v" + ABI_VERSION); | ||||
templatePath = asset::user("template-v" + ABI_VERSION + ".vcv"); | |||||
} | } | ||||
factoryTemplatePath = asset::system("template.vcv"); | |||||
} | } | ||||
@@ -172,7 +175,7 @@ void PatchManager::saveTemplateDialog() { | |||||
return; | return; | ||||
try { | try { | ||||
save(asset::templatePath); | |||||
save(templatePath); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
std::string message = string::f("Could not save template patch: %s", e.what()); | std::string message = string::f("Could not save template patch: %s", e.what()); | ||||
@@ -264,12 +267,12 @@ void PatchManager::load(std::string path) { | |||||
void PatchManager::loadTemplate() { | void PatchManager::loadTemplate() { | ||||
try { | try { | ||||
load(asset::templatePath); | |||||
load(templatePath); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
// Do nothing because it's okay for the user template to not exist. | |||||
// Try loading the system template patch | |||||
try { | try { | ||||
load(asset::system("template.vcv")); | |||||
load(factoryTemplatePath); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
std::string message = string::f("Could not load system template patch, clearing rack: %s", e.what()); | std::string message = string::f("Could not load system template patch, clearing rack: %s", e.what()); | ||||
@@ -213,19 +213,26 @@ void init() { | |||||
// Load Core | // Load Core | ||||
loadPlugin(""); | loadPlugin(""); | ||||
if (settings::devMode) { | |||||
pluginsPath = asset::user("plugins"); | |||||
} | |||||
else { | |||||
pluginsPath = asset::user("plugins-v" + ABI_VERSION); | |||||
} | |||||
// Get user plugins directory | // Get user plugins directory | ||||
system::createDirectory(asset::pluginsPath); | |||||
system::createDirectory(pluginsPath); | |||||
// Extract packages and load plugins | // Extract packages and load plugins | ||||
extractPackages(asset::pluginsPath); | |||||
loadPlugins(asset::pluginsPath); | |||||
extractPackages(pluginsPath); | |||||
loadPlugins(pluginsPath); | |||||
// If Fundamental wasn't loaded, copy the bundled Fundamental package and load it | // If Fundamental wasn't loaded, copy the bundled Fundamental package and load it | ||||
std::string fundamentalSrc = asset::system("Fundamental.vcvplugin"); | std::string fundamentalSrc = asset::system("Fundamental.vcvplugin"); | ||||
std::string fundamentalDir = system::join(asset::pluginsPath, "Fundamental"); | |||||
std::string fundamentalDir = system::join(pluginsPath, "Fundamental"); | |||||
if (!settings::devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) { | if (!settings::devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) { | ||||
INFO("Extracting bundled Fundamental package"); | INFO("Extracting bundled Fundamental package"); | ||||
system::unarchiveToFolder(fundamentalSrc.c_str(), asset::pluginsPath.c_str()); | |||||
system::unarchiveToFolder(fundamentalSrc.c_str(), pluginsPath.c_str()); | |||||
loadPlugin(fundamentalDir); | loadPlugin(fundamentalDir); | ||||
} | } | ||||
} | } | ||||
@@ -342,6 +349,7 @@ std::string normalizeSlug(const std::string& slug) { | |||||
} | } | ||||
std::string pluginsPath; | |||||
std::vector<Plugin*> plugins; | std::vector<Plugin*> plugins; | ||||
@@ -8,12 +8,16 @@ | |||||
#include <engine/Engine.hpp> | #include <engine/Engine.hpp> | ||||
#include <context.hpp> | #include <context.hpp> | ||||
#include <patch.hpp> | #include <patch.hpp> | ||||
#include <asset.hpp> | |||||
namespace rack { | namespace rack { | ||||
namespace settings { | namespace settings { | ||||
std::string settingsPath; | |||||
bool devMode = false; | bool devMode = false; | ||||
bool headless = false; | bool headless = false; | ||||
std::string token; | std::string token; | ||||
@@ -59,6 +63,16 @@ std::map<std::string, std::set<std::string>> moduleWhitelist = {}; | |||||
std::map<std::string, std::map<std::string, ModuleUsage>> moduleUsages = {}; | std::map<std::string, std::map<std::string, ModuleUsage>> moduleUsages = {}; | ||||
void init() { | |||||
if (devMode) { | |||||
settingsPath = asset::user("settings.json"); | |||||
} | |||||
else { | |||||
settingsPath = asset::user("settings-v" + ABI_VERSION + ".json"); | |||||
} | |||||
} | |||||
ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& moduleSlug) { | ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& moduleSlug) { | ||||
auto it1 = moduleUsages.find(pluginSlug); | auto it1 = moduleUsages.find(pluginSlug); | ||||
if (it1 == moduleUsages.end()) | if (it1 == moduleUsages.end()) | ||||
@@ -49,7 +49,7 @@ static void fatalSignalHandler(int sig) { | |||||
// This might fail because we might not be in the main thread. | // This might fail because we might not be in the main thread. | ||||
// But oh well, we're crashing anyway. | // But oh well, we're crashing anyway. | ||||
std::string text = APP_NAME + " has crashed. See " + logger::path + " for details."; | |||||
std::string text = APP_NAME + " has crashed. See " + logger::logPath + " for details."; | |||||
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, text.c_str()); | osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, text.c_str()); | ||||
abort(); | abort(); | ||||
@@ -144,8 +144,9 @@ int main(int argc, char* argv[]) { | |||||
#endif | #endif | ||||
// Load settings | // Load settings | ||||
settings::init(); | |||||
try { | try { | ||||
settings::load(asset::settingsPath); | |||||
settings::load(settings::settingsPath); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
std::string msg = e.what(); | std::string msg = e.what(); | ||||
@@ -240,7 +241,7 @@ int main(int argc, char* argv[]) { | |||||
delete APP; | delete APP; | ||||
contextSet(NULL); | contextSet(NULL); | ||||
if (!settings::headless) { | if (!settings::headless) { | ||||
settings::save(asset::settingsPath); | |||||
settings::save(settings::settingsPath); | |||||
} | } | ||||
// Destroy environment | // Destroy environment | ||||