Browse Source

Use different temporary autosave dir in safe mode. Don't check for library updates in safe mode.

tags/v2.1.2
Andrew Belt 2 years ago
parent
commit
a4c8ee3b5e
2 changed files with 39 additions and 23 deletions
  1. +21
    -14
      src/library.cpp
  2. +18
    -9
      src/patch.cpp

+ 21
- 14
src/library.cpp View File

@@ -25,21 +25,28 @@ static std::condition_variable updateCv;


void init() {
if (settings::autoCheckUpdates && !settings::devMode) {
std::thread t([&]() {
system::setThreadName("Library");
// Wait a few seconds before updating in case library is destroyed immediately afterwards
{
std::unique_lock<std::mutex> lock(timeoutMutex);
if (updateCv.wait_for(lock, std::chrono::duration<double>(4.0)) != std::cv_status::timeout)
return;
}
if (!settings::autoCheckUpdates)
return;
// Dev mode is typically used when Rack or plugins are compiled from source, so updating might overwrite assets.
if (settings::devMode)
return;
// Safe mode disables plugin loading, so Rack will unnecessarily try to sync all plugins.
if (settings::safeMode)
return;

checkAppUpdate();
checkUpdates();
});
t.detach();
}
std::thread t([&]() {
system::setThreadName("Library");
// Wait a few seconds before updating in case library is destroyed immediately afterwards
{
std::unique_lock<std::mutex> lock(timeoutMutex);
if (updateCv.wait_for(lock, std::chrono::duration<double>(4.0)) != std::cv_status::timeout)
return;
}

checkAppUpdate();
checkUpdates();
});
t.detach();
}




+ 18
- 9
src/patch.cpp View File

@@ -24,12 +24,25 @@ static const char PATCH_FILTERS[] = "VCV Rack patch (.vcv):vcv";

Manager::Manager() {
autosavePath = asset::user("autosave");

// Use a different temporary autosave dir when safe mode is enabled, to avoid altering normal autosave.
if (settings::safeMode) {
autosavePath = asset::user("autosave-safe");
clearAutosave();
}

templatePath = asset::user("template.vcv");
factoryTemplatePath = asset::system("template.vcv");
}


Manager::~Manager() {
// In safe mode, delete autosave dir.
if (settings::safeMode) {
clearAutosave();
return;
}

// Dispatch onSave to all Modules so they save their patch storage, etc.
APP->engine->prepareSave();
// Save autosave if not headless
@@ -41,19 +54,16 @@ Manager::~Manager() {


void Manager::launch(std::string pathArg) {
// Don't load any patches if safe mode is enabled
if (settings::safeMode)
return;

// Load the argument if exists
if (pathArg != "") {
loadAction(pathArg);
return;
}

// Don't load autosave or template if safe mode is enabled
if (settings::safeMode) {
clear();
clearAutosave();
return;
}

// Try loading the autosave patch
if (hasAutosave()) {
try {
@@ -222,7 +232,6 @@ void Manager::saveAutosave() {

void Manager::clearAutosave() {
system::removeRecursively(autosavePath);
system::createDirectories(autosavePath);
}


@@ -265,6 +274,7 @@ void Manager::load(std::string path) {

clear();
clearAutosave();
system::createDirectories(autosavePath);

if (isPatchLegacyV1(path)) {
// Copy the .vcv file directly to "patch.json".
@@ -316,7 +326,6 @@ void Manager::loadTemplateDialog() {

bool Manager::hasAutosave() {
std::string patchPath = system::join(autosavePath, "patch.json");
INFO("Loading autosave %s", patchPath.c_str());
FILE* file = std::fopen(patchPath.c_str(), "r");
if (!file)
return false;


Loading…
Cancel
Save