Browse Source

Remove preset directory if empty.

tags/v2.0.0
Andrew Belt 5 years ago
parent
commit
cc14d40fe3
3 changed files with 19 additions and 5 deletions
  1. +4
    -0
      include/system.hpp
  2. +10
    -5
      src/app/ModuleWidget.cpp
  3. +5
    -0
      src/system.cpp

+ 4
- 0
include/system.hpp View File

@@ -26,6 +26,10 @@ void copyFile(const std::string& srcPath, const std::string& destPath);
The parent directory must exist. The parent directory must exist.
*/ */
void createDirectory(const std::string& path); void createDirectory(const std::string& path);
/** Deletes a directory.
The directory must be empty. Fails silently.
*/
void removeDirectory(const std::string& path);
/** Returns the number of logical simultaneous multithreading (SMT) (e.g. Intel Hyperthreaded) threads on the CPU. */ /** Returns the number of logical simultaneous multithreading (SMT) (e.g. Intel Hyperthreaded) threads on the CPU. */
int getLogicalCoreCount(); int getLogicalCoreCount();
/** Sets a name of the current thread for debuggers and OS-specific process viewers. */ /** Sets a name of the current thread for debuggers and OS-specific process viewers. */


+ 10
- 5
src/app/ModuleWidget.cpp View File

@@ -652,17 +652,22 @@ void ModuleWidget::loadDialog() {
void ModuleWidget::saveDialog() { void ModuleWidget::saveDialog() {
std::string presetDir = asset::user("presets"); std::string presetDir = asset::user("presets");
system::createDirectory(presetDir); system::createDirectory(presetDir);
presetDir += "/" + model->plugin->slug;
system::createDirectory(presetDir);
presetDir += "/" + model->slug;
system::createDirectory(presetDir);
std::string pluginPresetDir = presetDir + "/" + model->plugin->slug;
system::createDirectory(pluginPresetDir);
std::string modulePresetDir = pluginPresetDir + "/" + model->slug;
system::createDirectory(modulePresetDir);
// Delete directory if empty
DEFER({
system::removeDirectory(modulePresetDir);
system::removeDirectory(pluginPresetDir);
});


osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS); osdialog_filters* filters = osdialog_filters_parse(PRESET_FILTERS);
DEFER({ DEFER({
osdialog_filters_free(filters); osdialog_filters_free(filters);
}); });


char* path = osdialog_file(OSDIALOG_SAVE, presetDir.c_str(), "Untitled.vcvm", filters);
char* path = osdialog_file(OSDIALOG_SAVE, modulePresetDir.c_str(), "Untitled.vcvm", filters);
if (!path) { if (!path) {
// No path selected // No path selected
return; return;


+ 5
- 0
src/system.cpp View File

@@ -137,6 +137,11 @@ void createDirectory(const std::string& path) {
} }




void removeDirectory(const std::string& path) {
rmdir(path.c_str());
}


int getLogicalCoreCount() { int getLogicalCoreCount() {
return std::thread::hardware_concurrency(); return std::thread::hardware_concurrency();
} }


Loading…
Cancel
Save