Browse Source

Rename *Dir() functions to *Directory(), backtracking on a previous commit.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
c3ff43b6de
13 changed files with 82 additions and 82 deletions
  1. +1
    -1
      adapters/standalone.cpp
  2. +2
    -2
      include/engine/Module.hpp
  3. +2
    -2
      include/plugin/Model.hpp
  4. +15
    -15
      include/system.hpp
  5. +2
    -2
      src/Window.cpp
  6. +1
    -1
      src/app/MenuBar.cpp
  7. +16
    -16
      src/app/ModuleWidget.cpp
  8. +3
    -3
      src/asset.cpp
  9. +4
    -4
      src/engine/Module.cpp
  10. +9
    -9
      src/patch.cpp
  11. +7
    -7
      src/plugin.cpp
  12. +2
    -2
      src/plugin/Model.cpp
  13. +18
    -18
      src/system.cpp

+ 1
- 1
adapters/standalone.cpp View File

@@ -157,7 +157,7 @@ int main(int argc, char* argv[]) {

// Check existence of the system res/ directory
std::string resDir = asset::system("res");
if (!system::isDir(resDir)) {
if (!system::isDirectory(resDir)) {
std::string message = string::f("Rack's resource directory \"%s\" does not exist. Make sure Rack is correctly installed and launched.", resDir.c_str());
osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, message.c_str());
exit(1);


+ 2
- 2
include/engine/Module.hpp View File

@@ -224,8 +224,8 @@ struct Module {
The Module must be added to Engine before this can be called, so it cannot be called in your Module constructor.
Override onAdd() instead.
*/
std::string createPatchStorageDir();
std::string getPatchStorageDir();
std::string createPatchStorageDirectory();
std::string getPatchStorageDirectory();

struct ProcessArgs {
/** The current sample rate in Hz. */


+ 2
- 2
include/plugin/Model.hpp View File

@@ -58,8 +58,8 @@ struct Model {
void fromJson(json_t* rootJ);
/** Returns the branded name of the model, e.g. VCV VCO-1. */
std::string getFullName();
std::string getFactoryPresetDir();
std::string getUserPresetDir();
std::string getFactoryPresetDirectory();
std::string getUserPresetDirectory();
};




+ 15
- 15
include/system.hpp View File

@@ -32,7 +32,7 @@ bool exists(const std::string& path);
/** Returns whether the given path is a file. */
bool isFile(const std::string& path);
/** Returns whether the given path is a directory. */
bool isDir(const std::string& path);
bool isDirectory(const std::string& path);
uint64_t getFileSize(const std::string& path);
/** Moves a file or directory.
Does not overwrite the destination. If this behavior is needed, use remove() or removeRecursively() before moving.
@@ -43,10 +43,10 @@ void copy(const std::string& srcPath, const std::string& destPath);
/** Creates a directory.
The parent directory must exist.
*/
bool createDir(const std::string& path);
bool createDirectory(const std::string& path);
/** Creates all directories up to the path.
*/
bool createDirs(const std::string& path);
bool createDirectories(const std::string& path);
/** Deletes a file or empty directory.
Returns whether the deletion was successful.
*/
@@ -55,9 +55,9 @@ bool remove(const std::string& path);
Returns the number of files and directories that were deleted.
*/
int removeRecursively(const std::string& path);
std::string getWorkingDir();
void setWorkingDir(const std::string& path);
std::string getTempDir();
std::string getWorkingDirectory();
void setWorkingDirectory(const std::string& path);
std::string getTempDirectory();
/** Returns the absolute path beginning with "/". */
std::string getAbsolute(const std::string& path);
/** Returns the canonical (unique) path, following symlinks and "." and ".." fake directories.
@@ -68,11 +68,11 @@ Examples:
std::string getCanonical(const std::string& path);
/** Extracts the parent directory of the path.
Examples:
getDir("/var/tmp/example.txt") // "/var/tmp"
getDir("/") // ""
getDir("/var/tmp/.") // "/var/tmp"
getDirectory("/var/tmp/example.txt") // "/var/tmp"
getDirectory("/") // ""
getDirectory("/var/tmp/.") // "/var/tmp"
*/
std::string getDir(const std::string& path);
std::string getDirectory(const std::string& path);
/** Extracts the filename of the path.
Examples:
getFilename("/foo/bar.txt") // "bar.txt"
@@ -112,15 +112,15 @@ An equivalent shell command is

ZSTD_CLEVEL=1 tar -cf archivePath --zstd -C dirPath .
*/
void archiveDir(const std::string& archivePath, const std::string& dirPath, int compressionLevel = 1);
std::vector<uint8_t> archiveDir(const std::string& dirPath, int compressionLevel = 1);
void archiveDirectory(const std::string& archivePath, const std::string& dirPath, int compressionLevel = 1);
std::vector<uint8_t> archiveDirectory(const std::string& dirPath, int compressionLevel = 1);
/** Extracts an archive into a directory.
An equivalent shell command is

tar -xf archivePath --zstd -C dirPath
*/
void unarchiveToDir(const std::string& archivePath, const std::string& dirPath);
void unarchiveToDir(const std::vector<uint8_t>& archiveData, const std::string& dirPath);
void unarchiveToDirectory(const std::string& archivePath, const std::string& dirPath);
void unarchiveToDirectory(const std::vector<uint8_t>& archiveData, const std::string& dirPath);


// Threading
@@ -151,7 +151,7 @@ May block, so open in a new thread.
*/
void openBrowser(const std::string& url);
/** Opens Windows Explorer, Finder, etc at a directory location. */
void openDir(const std::string& path);
void openDirectory(const std::string& path);
/** Runs an executable without blocking.
The launched process will continue running if the current process is closed.
*/


+ 2
- 2
src/Window.cpp View File

@@ -530,10 +530,10 @@ void Window::screenshot(const std::string& screenshotPath) {

void Window::screenshotModules(const std::string& screenshotsDir, float zoom) {
// Iterate plugins and create directories
system::createDirs(screenshotsDir);
system::createDirectories(screenshotsDir);
for (plugin::Plugin* p : plugin::plugins) {
std::string dir = system::join(screenshotsDir, p->slug);
system::createDir(dir);
system::createDirectory(dir);
for (plugin::Model* model : p->models) {
std::string filename = system::join(dir, model->slug + ".png");



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

@@ -74,7 +74,7 @@ struct DirItem : ui::MenuItem {
std::string path;
void onAction(const ActionEvent& e) override {
std::thread t([=] {
system::openDir(path);
system::openDirectory(path);
});
t.detach();
}


+ 16
- 16
src/app/ModuleWidget.cpp View File

@@ -41,7 +41,7 @@ struct ModuleDirItem : ui::MenuItem {
std::string path;
void onAction(const ActionEvent& e) override {
std::thread t([=]() {
system::openDir(path);
system::openDirectory(path);
});
t.detach();
}
@@ -288,14 +288,14 @@ struct ModulePresetDirItem : ui::MenuItem {
static void appendPresetItems(ui::Menu* menu, WeakPtr<ModuleWidget> moduleWidget, std::string presetDir) {
bool hasPresets = false;
// Note: This is not cached, so opening this menu each time might have a bit of latency.
if (system::isDir(presetDir)) {
if (system::isDirectory(presetDir)) {
for (const std::string& path : system::getEntries(presetDir)) {
std::string name = system::getStem(path);
// Remove "1_", "42_", "001_", etc at the beginning of preset filenames
std::regex r("^\\d*_");
name = std::regex_replace(name, r, "");

if (system::isDir(path)) {
if (system::isDirectory(path)) {
hasPresets = true;

ModulePresetDirItem* dirItem = new ModulePresetDirItem;
@@ -365,12 +365,12 @@ struct ModulePresetItem : ui::MenuItem {
// Scan `<user dir>/presets/<plugin slug>/<module slug>` for presets.
menu->addChild(new ui::MenuSeparator);
menu->addChild(createMenuLabel("User presets"));
appendPresetItems(menu, moduleWidget, moduleWidget->model->getUserPresetDir());
appendPresetItems(menu, moduleWidget, moduleWidget->model->getUserPresetDirectory());

// Scan `<plugin dir>/presets/<module slug>` for presets.
menu->addChild(new ui::MenuSeparator);
menu->addChild(createMenuLabel("Factory presets"));
appendPresetItems(menu, moduleWidget, moduleWidget->model->getFactoryPresetDir());
appendPresetItems(menu, moduleWidget, moduleWidget->model->getFactoryPresetDirectory());

return menu;
}
@@ -836,7 +836,7 @@ void ModuleWidget::loadAction(std::string filename) {
}

void ModuleWidget::loadTemplate() {
std::string templatePath = system::join(model->getUserPresetDir(), "template.vcvm");
std::string templatePath = system::join(model->getUserPresetDirectory(), "template.vcvm");
try {
load(templatePath);
}
@@ -846,14 +846,14 @@ void ModuleWidget::loadTemplate() {
}

void ModuleWidget::loadDialog() {
std::string presetDir = model->getUserPresetDir();
system::createDirs(presetDir);
std::string presetDir = model->getUserPresetDirectory();
system::createDirectories(presetDir);

// Delete directories if empty
DEFER({
try {
system::remove(presetDir);
system::remove(system::getDir(presetDir));
system::remove(system::getDirectory(presetDir));
}
catch (Exception& e) {
// Ignore exceptions if directory cannot be removed.
@@ -897,8 +897,8 @@ void ModuleWidget::save(std::string filename) {
}

void ModuleWidget::saveTemplate() {
std::string presetDir = model->getUserPresetDir();
system::createDirs(presetDir);
std::string presetDir = model->getUserPresetDirectory();
system::createDirectories(presetDir);
std::string templatePath = system::join(presetDir, "template.vcvm");
save(templatePath);
}
@@ -913,13 +913,13 @@ void ModuleWidget::saveTemplateDialog() {
}

bool ModuleWidget::hasTemplate() {
std::string presetDir = model->getUserPresetDir();
std::string presetDir = model->getUserPresetDirectory();
std::string templatePath = system::join(presetDir, "template.vcvm");
return system::exists(templatePath);;
}

void ModuleWidget::clearTemplate() {
std::string presetDir = model->getUserPresetDir();
std::string presetDir = model->getUserPresetDirectory();
std::string templatePath = system::join(presetDir, "template.vcvm");
system::remove(templatePath);
}
@@ -932,14 +932,14 @@ void ModuleWidget::clearTemplateDialog() {
}

void ModuleWidget::saveDialog() {
std::string presetDir = model->getUserPresetDir();
system::createDirs(presetDir);
std::string presetDir = model->getUserPresetDirectory();
system::createDirectories(presetDir);

// Delete directories if empty
DEFER({
try {
system::remove(presetDir);
system::remove(system::getDir(presetDir));
system::remove(system::getDirectory(presetDir));
}
catch (Exception& e) {
// Ignore exceptions if directory cannot be removed.


+ 3
- 3
src/asset.cpp View File

@@ -34,7 +34,7 @@ static void initSystemDir() {
return;

if (settings::devMode) {
systemDir = system::getWorkingDir();
systemDir = system::getWorkingDirectory();
return;
}

@@ -71,7 +71,7 @@ static void initSystemDir() {
#endif
#if defined ARCH_LIN
// Use the current working directory as the default path on Linux.
systemDir = system::getWorkingDir();
systemDir = system::getWorkingDirectory();
#endif
}

@@ -114,7 +114,7 @@ void init() {
initSystemDir();
initUserDir();

system::createDir(userDir);
system::createDirectory(userDir);
}




+ 4
- 4
src/engine/Module.cpp View File

@@ -82,14 +82,14 @@ void Module::config(int numParams, int numInputs, int numOutputs, int numLights)
}


std::string Module::createPatchStorageDir() {
std::string path = getPatchStorageDir();
system::createDirs(path);
std::string Module::createPatchStorageDirectory() {
std::string path = getPatchStorageDirectory();
system::createDirectories(path);
return path;
}


std::string Module::getPatchStorageDir() {
std::string Module::getPatchStorageDirectory() {
return system::join(APP->patch->autosavePath, "modules", std::to_string(id));
}



+ 9
- 9
src/patch.cpp View File

@@ -99,7 +99,7 @@ void PatchManager::save(std::string path) {

double startTime = system::getTime();
// Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked
system::archiveDir(path, autosavePath, 1);
system::archiveDirectory(path, autosavePath, 1);
double endTime = system::getTime();
INFO("Archived patch in %lf seconds", (endTime - startTime));
}
@@ -130,11 +130,11 @@ void PatchManager::saveAsDialog() {
std::string filename;
if (this->path == "") {
dir = asset::user("patches");
system::createDirs(dir);
system::createDirectories(dir);
filename = "Untitled.vcv";
}
else {
dir = system::getDir(this->path);
dir = system::getDirectory(this->path);
filename = system::getFilename(this->path);
}

@@ -195,7 +195,7 @@ void PatchManager::saveAutosave() {
DEFER({json_decref(rootJ);});

// Write to temporary path and then rename it to the correct path
system::createDirs(autosavePath);
system::createDirectories(autosavePath);
std::string tmpPath = patchPath + ".tmp";
FILE* file = std::fopen(tmpPath.c_str(), "w");
if (!file) {
@@ -213,7 +213,7 @@ void PatchManager::saveAutosave() {
void PatchManager::cleanAutosave() {
// Remove files and directories in the `autosave/modules` directory that doesn't match a module in the rack.
std::string modulesDir = system::join(autosavePath, "modules");
if (system::isDir(modulesDir)) {
if (system::isDirectory(modulesDir)) {
for (const std::string& entry : system::getEntries(modulesDir)) {
try {
int64_t moduleId = std::stol(system::getFilename(entry));
@@ -248,7 +248,7 @@ void PatchManager::load(std::string path) {
INFO("Loading patch %s", path.c_str());

system::removeRecursively(autosavePath);
system::createDirs(autosavePath);
system::createDirectories(autosavePath);

if (isPatchLegacyV1(path)) {
// Copy the .vcv file directly to "patch.json".
@@ -257,7 +257,7 @@ void PatchManager::load(std::string path) {
else {
// Extract the .vcv file as a .tar.zst archive.
double startTime = system::getTime();
system::unarchiveToDir(path, autosavePath);
system::unarchiveToDirectory(path, autosavePath);
double endTime = system::getTime();
INFO("Unarchived patch in %lf seconds", (endTime - startTime));
}
@@ -348,10 +348,10 @@ void PatchManager::loadDialog() {
std::string dir;
if (this->path == "") {
dir = asset::user("patches");
system::createDir(dir);
system::createDirectory(dir);
}
else {
dir = system::getDir(this->path);
dir = system::getDirectory(this->path);
}

osdialog_filters* filters = osdialog_filters_parse(PATCH_FILTERS);


+ 7
- 7
src/plugin.cpp View File

@@ -53,10 +53,10 @@ static void* loadLibrary(std::string libraryPath) {
}
#else
// As of Rack v2.0, plugins are linked with `-rpath=.` so change current directory so it can find libRack.
std::string cwd = system::getWorkingDir();
system::setWorkingDir(asset::systemDir);
std::string cwd = system::getWorkingDirectory();
system::setWorkingDirectory(asset::systemDir);
// Change it back when we're finished
DEFER({system::setWorkingDir(cwd);});
DEFER({system::setWorkingDirectory(cwd);});
// Load library with dlopen
void* handle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_LOCAL);
if (!handle)
@@ -166,7 +166,7 @@ static Plugin* loadPlugin(std::string path) {

static void loadPlugins(std::string path) {
for (std::string pluginPath : system::getEntries(path)) {
if (!system::isDir(pluginPath))
if (!system::isDirectory(pluginPath))
continue;
if (!loadPlugin(pluginPath)) {
// Ignore bad plugins. They are reported in the log.
@@ -187,7 +187,7 @@ static void extractPackages(std::string path) {
// Extract package
INFO("Extracting package %s", packagePath.c_str());
try {
system::unarchiveToDir(packagePath, path);
system::unarchiveToDirectory(packagePath, path);
}
catch (Exception& e) {
WARN("Plugin package %s failed to extract: %s", packagePath.c_str(), e.what());
@@ -221,7 +221,7 @@ void init() {
}

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

// Extract packages and load plugins
extractPackages(pluginsPath);
@@ -232,7 +232,7 @@ void init() {
std::string fundamentalDir = system::join(pluginsPath, "Fundamental");
if (!settings::devMode && !getPlugin("Fundamental") && system::isFile(fundamentalSrc)) {
INFO("Extracting bundled Fundamental package");
system::unarchiveToDir(fundamentalSrc.c_str(), pluginsPath.c_str());
system::unarchiveToDirectory(fundamentalSrc.c_str(), pluginsPath.c_str());
loadPlugin(fundamentalDir);
}
}


+ 2
- 2
src/plugin/Model.cpp View File

@@ -63,12 +63,12 @@ std::string Model::getFullName() {
}


std::string Model::getFactoryPresetDir() {
std::string Model::getFactoryPresetDirectory() {
return asset::plugin(plugin, system::join("presets", slug));
}


std::string Model::getUserPresetDir() {
std::string Model::getUserPresetDirectory() {
return asset::user(system::join("presets", plugin->slug, slug));
}



+ 18
- 18
src/system.cpp View File

@@ -100,7 +100,7 @@ bool isFile(const std::string& path) {
}


bool isDir(const std::string& path) {
bool isDirectory(const std::string& path) {
try {
return fs::is_directory(fs::u8path(path));
}
@@ -140,7 +140,7 @@ void copy(const std::string& srcPath, const std::string& destPath) {
}


bool createDir(const std::string& path) {
bool createDirectory(const std::string& path) {
try {
return fs::create_directory(fs::u8path(path));
}
@@ -150,7 +150,7 @@ bool createDir(const std::string& path) {
}


bool createDirs(const std::string& path) {
bool createDirectories(const std::string& path) {
try {
return fs::create_directories(fs::u8path(path));
}
@@ -180,7 +180,7 @@ int removeRecursively(const std::string& path) {
}


std::string getWorkingDir() {
std::string getWorkingDirectory() {
try {
return fs::current_path().generic_u8string();
}
@@ -190,7 +190,7 @@ std::string getWorkingDir() {
}


void setWorkingDir(const std::string& path) {
void setWorkingDirectory(const std::string& path) {
try {
fs::current_path(fs::u8path(path));
}
@@ -200,7 +200,7 @@ void setWorkingDir(const std::string& path) {
}


std::string getTempDir() {
std::string getTempDirectory() {
try {
return fs::temp_directory_path().generic_u8string();
}
@@ -230,7 +230,7 @@ std::string getCanonical(const std::string& path) {
}


std::string getDir(const std::string& path) {
std::string getDirectory(const std::string& path) {
try {
return fs::u8path(path).parent_path().generic_u8string();
}
@@ -300,7 +300,7 @@ static la_ssize_t archiveWriteVectorCallback(struct archive* a, void* client_dat
}


static void archiveDir(const std::string& archivePath, std::vector<uint8_t>* archiveData, const std::string& dirPath, int compressionLevel) {
static void archiveDirectory(const std::string& archivePath, std::vector<uint8_t>* archiveData, const std::string& dirPath, int compressionLevel) {
// Based on minitar.c create() in libarchive examples
int r;

@@ -394,13 +394,13 @@ static void archiveDir(const std::string& archivePath, std::vector<uint8_t>* arc
}
}

void archiveDir(const std::string& archivePath, const std::string& dirPath, int compressionLevel) {
archiveDir(archivePath, NULL, dirPath, compressionLevel);
void archiveDirectory(const std::string& archivePath, const std::string& dirPath, int compressionLevel) {
archiveDirectory(archivePath, NULL, dirPath, compressionLevel);
}

std::vector<uint8_t> archiveDir(const std::string& dirPath, int compressionLevel) {
std::vector<uint8_t> archiveDirectory(const std::string& dirPath, int compressionLevel) {
std::vector<uint8_t> archiveData;
archiveDir("", &archiveData, dirPath, compressionLevel);
archiveDirectory("", &archiveData, dirPath, compressionLevel);
return archiveData;
}

@@ -422,7 +422,7 @@ static la_ssize_t archiveReadVectorCallback(struct archive *a, void* client_data
return len;
}

static void unarchiveToDir(const std::string& archivePath, const std::vector<uint8_t>* archiveData, const std::string& dirPath) {
static void unarchiveToDirectory(const std::string& archivePath, const std::vector<uint8_t>* archiveData, const std::string& dirPath) {
// Based on minitar.c extract() in libarchive examples
int r;

@@ -510,12 +510,12 @@ static void unarchiveToDir(const std::string& archivePath, const std::vector<uin
}
}

void unarchiveToDir(const std::string& archivePath, const std::string& dirPath) {
unarchiveToDir(archivePath, NULL, dirPath);
void unarchiveToDirectory(const std::string& archivePath, const std::string& dirPath) {
unarchiveToDirectory(archivePath, NULL, dirPath);
}

void unarchiveToDir(const std::vector<uint8_t>& archiveData, const std::string& dirPath) {
unarchiveToDir("", &archiveData, dirPath);
void unarchiveToDirectory(const std::vector<uint8_t>& archiveData, const std::string& dirPath) {
unarchiveToDirectory("", &archiveData, dirPath);
}


@@ -689,7 +689,7 @@ void openBrowser(const std::string& url) {
}


void openDir(const std::string& path) {
void openDirectory(const std::string& path) {
#if defined ARCH_LIN
std::string command = "xdg-open \"" + path + "\"";
(void) std::system(command.c_str());


Loading…
Cancel
Save