Browse Source

Move asset::pluginsPath, templatePath, and settingsPath to appropriate namespaces.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
583530032f
13 changed files with 58 additions and 40 deletions
  1. +0
    -4
      include/asset.hpp
  2. +1
    -1
      include/logger.hpp
  3. +4
    -0
      include/patch.hpp
  4. +2
    -0
      include/plugin.hpp
  5. +5
    -0
      include/settings.hpp
  6. +1
    -1
      src/app/Scene.cpp
  7. +0
    -15
      src/asset.cpp
  8. +1
    -1
      src/library.cpp
  9. +6
    -6
      src/logger.cpp
  10. +7
    -4
      src/patch.cpp
  11. +13
    -5
      src/plugin.cpp
  12. +14
    -0
      src/settings.cpp
  13. +4
    -3
      standalone/main.cpp

+ 0
- 4
include/asset.hpp View File

@@ -40,10 +40,6 @@ extern std::string userDir;
// Only defined on Mac
extern std::string bundlePath;

extern std::string pluginsPath;
extern std::string settingsPath;
extern std::string templatePath;


} // namespace asset
} // namespace rack

+ 1
- 1
include/logger.hpp View File

@@ -23,7 +23,7 @@ namespace rack {
namespace logger {


extern std::string path;
extern std::string logPath;


enum Level {


+ 4
- 0
include/patch.hpp View File

@@ -12,6 +12,10 @@ struct PatchManager {
std::string path;
/** Path to autosave folder */
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. */
std::string warningLog;



+ 2
- 0
include/plugin.hpp View File

@@ -28,6 +28,8 @@ bool isSlugValid(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;




+ 5
- 0
include/settings.hpp View File

@@ -19,6 +19,10 @@ namespace rack {
namespace settings {


/** Path to settings.json */
extern std::string settingsPath;


// Runtime state, not serialized.

extern bool devMode;
@@ -86,6 +90,7 @@ struct ModuleUsage {
extern std::map<std::string, std::map<std::string, ModuleUsage>> moduleUsages;
ModuleUsage* getModuleUsage(const std::string& pluginSlug, const std::string& moduleSlug);

void init();
json_t* toJson();
void fromJson(json_t* rootJ);
void save(const std::string& path);


+ 1
- 1
src/app/Scene.cpp View File

@@ -83,7 +83,7 @@ void Scene::step() {
if (time - lastAutosaveTime >= settings::autosaveInterval) {
lastAutosaveTime = time;
APP->patch->saveAutosave();
settings::save(asset::settingsPath);
settings::save(settings::settingsPath);
}
}



+ 0
- 15
src/asset.cpp View File

@@ -115,18 +115,6 @@ void init() {
initUserDir();

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 userDir;

std::string pluginsPath;
std::string settingsPath;
std::string templatePath;
std::string bundlePath;




+ 1
- 1
src/library.cpp View File

@@ -317,7 +317,7 @@ void syncUpdate(const std::string& slug) {

// Get file path
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
if (!network::requestDownload(downloadUrl, packagePath, &updateProgress, getTokenCookies())) {


+ 6
- 6
src/logger.cpp View File

@@ -11,7 +11,7 @@ namespace rack {
namespace logger {


std::string path;
std::string logPath;
static FILE* outputFile = NULL;
static std::mutex mutex;

@@ -25,11 +25,11 @@ void init() {
outputFile = stderr;
}
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) {
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() {
if (path.empty())
if (logPath.empty())
return false;

// Open existing log file
FILE* file = std::fopen(path.c_str(), "r");
FILE* file = std::fopen(logPath.c_str(), "r");
if (!file)
return false;
DEFER({std::fclose(file);});


+ 7
- 4
src/patch.cpp View File

@@ -25,10 +25,13 @@ static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv";
PatchManager::PatchManager() {
if (settings::devMode) {
autosavePath = asset::user("autosave");
templatePath = asset::user("template.vcv");
}
else {
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;

try {
save(asset::templatePath);
save(templatePath);
}
catch (Exception& e) {
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() {
try {
load(asset::templatePath);
load(templatePath);
}
catch (Exception& e) {
// Do nothing because it's okay for the user template to not exist.
// Try loading the system template patch
try {
load(asset::system("template.vcv"));
load(factoryTemplatePath);
}
catch (Exception& e) {
std::string message = string::f("Could not load system template patch, clearing rack: %s", e.what());


+ 13
- 5
src/plugin.cpp View File

@@ -213,19 +213,26 @@ void init() {
// Load Core
loadPlugin("");

if (settings::devMode) {
pluginsPath = asset::user("plugins");
}
else {
pluginsPath = asset::user("plugins-v" + ABI_VERSION);
}

// Get user plugins directory
system::createDirectory(asset::pluginsPath);
system::createDirectory(pluginsPath);

// 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
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)) {
INFO("Extracting bundled Fundamental package");
system::unarchiveToFolder(fundamentalSrc.c_str(), asset::pluginsPath.c_str());
system::unarchiveToFolder(fundamentalSrc.c_str(), pluginsPath.c_str());
loadPlugin(fundamentalDir);
}
}
@@ -342,6 +349,7 @@ std::string normalizeSlug(const std::string& slug) {
}


std::string pluginsPath;
std::vector<Plugin*> plugins;




+ 14
- 0
src/settings.cpp View File

@@ -8,12 +8,16 @@
#include <engine/Engine.hpp>
#include <context.hpp>
#include <patch.hpp>
#include <asset.hpp>


namespace rack {
namespace settings {


std::string settingsPath;


bool devMode = false;
bool headless = false;
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 = {};


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) {
auto it1 = moduleUsages.find(pluginSlug);
if (it1 == moduleUsages.end())


+ 4
- 3
standalone/main.cpp View File

@@ -49,7 +49,7 @@ static void fatalSignalHandler(int sig) {

// This might fail because we might not be in the main thread.
// 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());

abort();
@@ -144,8 +144,9 @@ int main(int argc, char* argv[]) {
#endif

// Load settings
settings::init();
try {
settings::load(asset::settingsPath);
settings::load(settings::settingsPath);
}
catch (Exception& e) {
std::string msg = e.what();
@@ -240,7 +241,7 @@ int main(int argc, char* argv[]) {
delete APP;
contextSet(NULL);
if (!settings::headless) {
settings::save(asset::settingsPath);
settings::save(settings::settingsPath);
}

// Destroy environment


Loading…
Cancel
Save