@@ -157,7 +157,7 @@ int main(int argc, char* argv[]) { | |||||
// Check existence of the system res/ directory | // Check existence of the system res/ directory | ||||
std::string resDir = asset::system("res"); | std::string resDir = asset::system("res"); | ||||
if (!system::isDirectory(resDir)) { | |||||
if (!system::isDir(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()); | 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()); | osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, message.c_str()); | ||||
exit(1); | exit(1); | ||||
@@ -26,10 +26,10 @@ std::string system(std::string filename = ""); | |||||
/** Returns the path of a user asset. Can read and write files to this location. */ | /** Returns the path of a user asset. Can read and write files to this location. */ | ||||
std::string user(std::string filename = ""); | std::string user(std::string filename = ""); | ||||
/** Returns the path of a asset in the plugin's folder. | |||||
/** Returns the path of a asset in the plugin's dir. | |||||
Plugin assets should be read-only by plugins. | Plugin assets should be read-only by plugins. | ||||
Examples: | Examples: | ||||
asset::plugin(pluginInstance, "samples/00.wav") // "/path/to/Rack/user/folder/plugins/MyPlugin/samples/00.wav" | |||||
asset::plugin(pluginInstance, "samples/00.wav") // "/path/to/Rack/user/dir/plugins/MyPlugin/samples/00.wav" | |||||
*/ | */ | ||||
std::string plugin(plugin::Plugin* plugin, std::string filename = ""); | std::string plugin(plugin::Plugin* plugin, std::string filename = ""); | ||||
@@ -218,8 +218,11 @@ struct Module { | |||||
bypassRoutes.push_back(br); | bypassRoutes.push_back(br); | ||||
} | } | ||||
/** Creates and returns the module's patch storage folder path. | |||||
Since the folder is created when this is called, do not call it frequently or in an audio/engine thread such as process(). | |||||
/** Creates and returns the module's patch storage directory path. | |||||
Since the directory is created when this is called, do not call it frequently or in an audio/engine thread such as process(). | |||||
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 createPatchStorageDir(); | ||||
std::string getPatchStorageDir(); | std::string getPatchStorageDir(); | ||||
@@ -13,7 +13,7 @@ struct PatchManager { | |||||
/** The currently loaded patch file path */ | /** The currently loaded patch file path */ | ||||
std::string path; | std::string path; | ||||
/** Path to autosave folder */ | |||||
/** Path to autosave dir */ | |||||
std::string autosavePath; | std::string autosavePath; | ||||
/** Path to user template patch */ | /** Path to user template patch */ | ||||
std::string templatePath; | std::string templatePath; | ||||
@@ -28,7 +28,7 @@ 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 */ | |||||
/** Path to plugins installation dir */ | |||||
extern std::string pluginsPath; | extern std::string pluginsPath; | ||||
extern std::vector<Plugin*> plugins; | extern std::vector<Plugin*> plugins; | ||||
@@ -32,21 +32,21 @@ bool exists(const std::string& path); | |||||
/** Returns whether the given path is a file. */ | /** Returns whether the given path is a file. */ | ||||
bool isFile(const std::string& path); | bool isFile(const std::string& path); | ||||
/** Returns whether the given path is a directory. */ | /** Returns whether the given path is a directory. */ | ||||
bool isDirectory(const std::string& path); | |||||
bool isDir(const std::string& path); | |||||
uint64_t getFileSize(const std::string& path); | uint64_t getFileSize(const std::string& path); | ||||
/** Moves a file or folder. | |||||
/** Moves a file or directory. | |||||
Does not overwrite the destination. If this behavior is needed, use remove() or removeRecursively() before moving. | Does not overwrite the destination. If this behavior is needed, use remove() or removeRecursively() before moving. | ||||
*/ | */ | ||||
void rename(const std::string& srcPath, const std::string& destPath); | void rename(const std::string& srcPath, const std::string& destPath); | ||||
/** Copies a file or folder recursively. */ | |||||
/** Copies a file or directory recursively. */ | |||||
void copy(const std::string& srcPath, const std::string& destPath); | void copy(const std::string& srcPath, const std::string& destPath); | ||||
/** Creates a directory. | /** Creates a directory. | ||||
The parent directory must exist. | The parent directory must exist. | ||||
*/ | */ | ||||
bool createDirectory(const std::string& path); | |||||
bool createDir(const std::string& path); | |||||
/** Creates all directories up to the path. | /** Creates all directories up to the path. | ||||
*/ | */ | ||||
bool createDirectories(const std::string& path); | |||||
bool createDirs(const std::string& path); | |||||
/** Deletes a file or empty directory. | /** Deletes a file or empty directory. | ||||
Returns whether the deletion was successful. | Returns whether the deletion was successful. | ||||
*/ | */ | ||||
@@ -55,8 +55,8 @@ bool remove(const std::string& path); | |||||
Returns the number of files and directories that were deleted. | Returns the number of files and directories that were deleted. | ||||
*/ | */ | ||||
int removeRecursively(const std::string& path); | int removeRecursively(const std::string& path); | ||||
std::string getWorkingDirectory(); | |||||
void setWorkingDirectory(const std::string& path); | |||||
std::string getWorkingDir(); | |||||
void setWorkingDir(const std::string& path); | |||||
std::string getTempDir(); | std::string getTempDir(); | ||||
/** Returns the absolute path beginning with "/". */ | /** Returns the absolute path beginning with "/". */ | ||||
std::string getAbsolute(const std::string& path); | std::string getAbsolute(const std::string& path); | ||||
@@ -68,11 +68,11 @@ Examples: | |||||
std::string getCanonical(const std::string& path); | std::string getCanonical(const std::string& path); | ||||
/** Extracts the parent directory of the path. | /** Extracts the parent directory of the path. | ||||
Examples: | Examples: | ||||
getDirectory("/var/tmp/example.txt") // "/var/tmp" | |||||
getDirectory("/") // "" | |||||
getDirectory("/var/tmp/.") // "/var/tmp" | |||||
getDir("/var/tmp/example.txt") // "/var/tmp" | |||||
getDir("/") // "" | |||||
getDir("/var/tmp/.") // "/var/tmp" | |||||
*/ | */ | ||||
std::string getDirectory(const std::string& path); | |||||
std::string getDir(const std::string& path); | |||||
/** Extracts the filename of the path. | /** Extracts the filename of the path. | ||||
Examples: | Examples: | ||||
getFilename("/foo/bar.txt") // "bar.txt" | getFilename("/foo/bar.txt") // "bar.txt" | ||||
@@ -87,9 +87,9 @@ Examples: | |||||
std::string getFilename(const std::string& path); | std::string getFilename(const std::string& path); | ||||
/** Extracts the portion of a filename without the extension. | /** Extracts the portion of a filename without the extension. | ||||
Examples: | Examples: | ||||
getExtension("/foo/bar.txt") // "bar" | |||||
getExtension("/foo/.bar") // "" | |||||
getExtension("/foo/foo.bar.baz.tar") // "foo.bar.baz" | |||||
getStem("/foo/bar.txt") // "bar" | |||||
getStem("/foo/.bar") // "" | |||||
getStem("/foo/foo.tar.ztd") // "foo.tar" | |||||
*/ | */ | ||||
std::string getStem(const std::string& path); | std::string getStem(const std::string& path); | ||||
/** Extracts the extension of a filename, including the dot. | /** Extracts the extension of a filename, including the dot. | ||||
@@ -106,21 +106,21 @@ Examples: | |||||
*/ | */ | ||||
std::string getExtension(const std::string& path); | std::string getExtension(const std::string& path); | ||||
/** Compresses the contents of a folder (recursively) to an archive. | |||||
/** Compresses the contents of a directory (recursively) to an archive. | |||||
Uses the Unix Standard TAR + Zstandard format (.tar.zst). | Uses the Unix Standard TAR + Zstandard format (.tar.zst). | ||||
An equivalent shell command is | An equivalent shell command is | ||||
ZSTD_CLEVEL=1 tar -cf archivePath --zstd -C folderPath . | |||||
ZSTD_CLEVEL=1 tar -cf archivePath --zstd -C dirPath . | |||||
*/ | */ | ||||
void archiveFolder(const std::string& archivePath, const std::string& folderPath, int compressionLevel = 1); | |||||
std::vector<uint8_t> archiveFolder(const std::string& folderPath, int compressionLevel = 1); | |||||
/** Extracts an archive into a folder. | |||||
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); | |||||
/** Extracts an archive into a directory. | |||||
An equivalent shell command is | An equivalent shell command is | ||||
tar -xf archivePath --zstd -C folderPath | |||||
tar -xf archivePath --zstd -C dirPath | |||||
*/ | */ | ||||
void unarchiveToFolder(const std::string& archivePath, const std::string& folderPath); | |||||
void unarchiveToFolder(const std::vector<uint8_t>& archiveData, const std::string& folderPath); | |||||
void unarchiveToDir(const std::string& archivePath, const std::string& dirPath); | |||||
void unarchiveToDir(const std::vector<uint8_t>& archiveData, const std::string& dirPath); | |||||
// Threading | // Threading | ||||
@@ -145,13 +145,13 @@ std::string getOperatingSystemInfo(); | |||||
// Applications | // Applications | ||||
/** Opens a URL, also happens to work with PDFs and folders. | |||||
/** Opens a URL in a browser. | |||||
Shell injection is possible, so make sure the URL is trusted or hard coded. | Shell injection is possible, so make sure the URL is trusted or hard coded. | ||||
May block, so open in a new thread. | May block, so open in a new thread. | ||||
*/ | */ | ||||
void openBrowser(const std::string& url); | void openBrowser(const std::string& url); | ||||
/** Opens Windows Explorer, Finder, etc at the folder location. */ | |||||
void openFolder(const std::string& path); | |||||
/** Opens Windows Explorer, Finder, etc at a directory location. */ | |||||
void openDir(const std::string& path); | |||||
/** Runs an executable without blocking. | /** Runs an executable without blocking. | ||||
The launched process will continue running if the current process is closed. | The launched process will continue running if the current process is closed. | ||||
*/ | */ | ||||
@@ -70,11 +70,11 @@ struct UrlItem : ui::MenuItem { | |||||
} | } | ||||
}; | }; | ||||
struct FolderItem : ui::MenuItem { | |||||
struct DirItem : ui::MenuItem { | |||||
std::string path; | std::string path; | ||||
void onAction(const ActionEvent& e) override { | void onAction(const ActionEvent& e) override { | ||||
std::thread t([=] { | std::thread t([=] { | ||||
system::openFolder(path); | |||||
system::openDir(path); | |||||
}); | }); | ||||
t.detach(); | t.detach(); | ||||
} | } | ||||
@@ -1041,14 +1041,15 @@ struct HelpButton : MenuButton { | |||||
menu->addChild(checkAppUpdateItem); | menu->addChild(checkAppUpdateItem); | ||||
} | } | ||||
FolderItem* folderItem = new FolderItem; | |||||
folderItem->text = "Open user folder"; | |||||
folderItem->path = asset::user(""); | |||||
menu->addChild(folderItem); | |||||
DirItem* dirItem = new DirItem; | |||||
dirItem->text = "Open user folder"; | |||||
dirItem->path = asset::user(""); | |||||
menu->addChild(dirItem); | |||||
menu->addChild(new ui::MenuSeparator); | menu->addChild(new ui::MenuSeparator); | ||||
menu->addChild(createMenuLabel(APP_VARIANT)); | menu->addChild(createMenuLabel(APP_VARIANT)); | ||||
menu->addChild(createMenuLabel(APP_VERSION)); | menu->addChild(createMenuLabel(APP_VERSION)); | ||||
} | } | ||||
@@ -29,16 +29,20 @@ static const char PRESET_FILTERS[] = "VCV Rack module preset (.vcvm):vcvm"; | |||||
struct ModuleUrlItem : ui::MenuItem { | struct ModuleUrlItem : ui::MenuItem { | ||||
std::string url; | std::string url; | ||||
void onAction(const ActionEvent& e) override { | void onAction(const ActionEvent& e) override { | ||||
std::thread t(system::openBrowser, url); | |||||
std::thread t([=]() { | |||||
system::openBrowser(url); | |||||
}); | |||||
t.detach(); | t.detach(); | ||||
} | } | ||||
}; | }; | ||||
struct ModuleFolderItem : ui::MenuItem { | |||||
struct ModuleDirItem : ui::MenuItem { | |||||
std::string path; | std::string path; | ||||
void onAction(const ActionEvent& e) override { | void onAction(const ActionEvent& e) override { | ||||
std::thread t(system::openFolder, path); | |||||
std::thread t([=]() { | |||||
system::openDir(path); | |||||
}); | |||||
t.detach(); | t.detach(); | ||||
} | } | ||||
}; | }; | ||||
@@ -147,7 +151,7 @@ struct ModuleInfoItem : ui::MenuItem { | |||||
// plugin folder | // plugin folder | ||||
if (model->plugin->path != "") { | if (model->plugin->path != "") { | ||||
ModuleFolderItem* pathItem = new ModuleFolderItem; | |||||
ModuleDirItem* pathItem = new ModuleDirItem; | |||||
pathItem->text = "Open plugin folder"; | pathItem->text = "Open plugin folder"; | ||||
pathItem->path = model->plugin->path; | pathItem->path = model->plugin->path; | ||||
menu->addChild(pathItem); | menu->addChild(pathItem); | ||||
@@ -284,14 +288,14 @@ struct ModulePresetDirItem : ui::MenuItem { | |||||
static void appendPresetItems(ui::Menu* menu, WeakPtr<ModuleWidget> moduleWidget, std::string presetDir) { | static void appendPresetItems(ui::Menu* menu, WeakPtr<ModuleWidget> moduleWidget, std::string presetDir) { | ||||
bool hasPresets = false; | bool hasPresets = false; | ||||
// Note: This is not cached, so opening this menu each time might have a bit of latency. | // Note: This is not cached, so opening this menu each time might have a bit of latency. | ||||
if (system::isDirectory(presetDir)) { | |||||
if (system::isDir(presetDir)) { | |||||
for (const std::string& path : system::getEntries(presetDir)) { | for (const std::string& path : system::getEntries(presetDir)) { | ||||
std::string name = system::getStem(path); | std::string name = system::getStem(path); | ||||
// Remove "1_", "42_", "001_", etc at the beginning of preset filenames | // Remove "1_", "42_", "001_", etc at the beginning of preset filenames | ||||
std::regex r("^\\d*_"); | std::regex r("^\\d*_"); | ||||
name = std::regex_replace(name, r, ""); | name = std::regex_replace(name, r, ""); | ||||
if (system::isDirectory(path)) { | |||||
if (system::isDir(path)) { | |||||
hasPresets = true; | hasPresets = true; | ||||
ModulePresetDirItem* dirItem = new ModulePresetDirItem; | ModulePresetDirItem* dirItem = new ModulePresetDirItem; | ||||
@@ -843,13 +847,13 @@ void ModuleWidget::loadTemplate() { | |||||
void ModuleWidget::loadDialog() { | void ModuleWidget::loadDialog() { | ||||
std::string presetDir = model->getUserPresetDir(); | std::string presetDir = model->getUserPresetDir(); | ||||
system::createDirectories(presetDir); | |||||
system::createDirs(presetDir); | |||||
// Delete directories if empty | // Delete directories if empty | ||||
DEFER({ | DEFER({ | ||||
try { | try { | ||||
system::remove(presetDir); | system::remove(presetDir); | ||||
system::remove(system::getDirectory(presetDir)); | |||||
system::remove(system::getDir(presetDir)); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
// Ignore exceptions if directory cannot be removed. | // Ignore exceptions if directory cannot be removed. | ||||
@@ -894,7 +898,7 @@ void ModuleWidget::save(std::string filename) { | |||||
void ModuleWidget::saveTemplate() { | void ModuleWidget::saveTemplate() { | ||||
std::string presetDir = model->getUserPresetDir(); | std::string presetDir = model->getUserPresetDir(); | ||||
system::createDirectories(presetDir); | |||||
system::createDirs(presetDir); | |||||
std::string templatePath = system::join(presetDir, "template.vcvm"); | std::string templatePath = system::join(presetDir, "template.vcvm"); | ||||
save(templatePath); | save(templatePath); | ||||
} | } | ||||
@@ -929,13 +933,13 @@ void ModuleWidget::clearTemplateDialog() { | |||||
void ModuleWidget::saveDialog() { | void ModuleWidget::saveDialog() { | ||||
std::string presetDir = model->getUserPresetDir(); | std::string presetDir = model->getUserPresetDir(); | ||||
system::createDirectories(presetDir); | |||||
system::createDirs(presetDir); | |||||
// Delete directories if empty | // Delete directories if empty | ||||
DEFER({ | DEFER({ | ||||
try { | try { | ||||
system::remove(presetDir); | system::remove(presetDir); | ||||
system::remove(system::getDirectory(presetDir)); | |||||
system::remove(system::getDir(presetDir)); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
// Ignore exceptions if directory cannot be removed. | // Ignore exceptions if directory cannot be removed. | ||||
@@ -34,7 +34,7 @@ static void initSystemDir() { | |||||
return; | return; | ||||
if (settings::devMode) { | if (settings::devMode) { | ||||
systemDir = system::getWorkingDirectory(); | |||||
systemDir = system::getWorkingDir(); | |||||
return; | return; | ||||
} | } | ||||
@@ -65,13 +65,13 @@ static void initSystemDir() { | |||||
wchar_t moduleBufW[MAX_PATH] = L""; | wchar_t moduleBufW[MAX_PATH] = L""; | ||||
DWORD length = GetModuleFileNameW(NULL, moduleBufW, LENGTHOF(moduleBufW)); | DWORD length = GetModuleFileNameW(NULL, moduleBufW, LENGTHOF(moduleBufW)); | ||||
assert(length > 0); | assert(length > 0); | ||||
// Get folder of executable | |||||
// Get directory of executable | |||||
PathRemoveFileSpecW(moduleBufW); | PathRemoveFileSpecW(moduleBufW); | ||||
systemDir = string::UTF16toUTF8(moduleBufW); | systemDir = string::UTF16toUTF8(moduleBufW); | ||||
#endif | #endif | ||||
#if defined ARCH_LIN | #if defined ARCH_LIN | ||||
// Use the current working directory as the default path on Linux. | // Use the current working directory as the default path on Linux. | ||||
systemDir = system::getWorkingDirectory(); | |||||
systemDir = system::getWorkingDir(); | |||||
#endif | #endif | ||||
} | } | ||||
@@ -86,7 +86,7 @@ static void initUserDir() { | |||||
} | } | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// Get "My Documents" folder | |||||
// Get "My Documents" path | |||||
wchar_t documentsBufW[MAX_PATH] = L"."; | wchar_t documentsBufW[MAX_PATH] = L"."; | ||||
HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW); | HRESULT result = SHGetFolderPathW(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBufW); | ||||
assert(result == S_OK); | assert(result == S_OK); | ||||
@@ -114,7 +114,7 @@ void init() { | |||||
initSystemDir(); | initSystemDir(); | ||||
initUserDir(); | initUserDir(); | ||||
system::createDirectory(userDir); | |||||
system::createDir(userDir); | |||||
} | } | ||||
@@ -84,7 +84,7 @@ void Module::config(int numParams, int numInputs, int numOutputs, int numLights) | |||||
std::string Module::createPatchStorageDir() { | std::string Module::createPatchStorageDir() { | ||||
std::string path = getPatchStorageDir(); | std::string path = getPatchStorageDir(); | ||||
system::createDirectories(path); | |||||
system::createDirs(path); | |||||
return path; | return path; | ||||
} | } | ||||
@@ -100,7 +100,7 @@ void PatchManager::save(std::string path) { | |||||
double startTime = system::getTime(); | double startTime = system::getTime(); | ||||
// Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked | // Set compression level to 1 so that a 500MB/s SSD is almost bottlenecked | ||||
system::archiveFolder(path, autosavePath, 1); | |||||
system::archiveDir(path, autosavePath, 1); | |||||
double endTime = system::getTime(); | double endTime = system::getTime(); | ||||
INFO("Archived patch in %lf seconds", (endTime - startTime)); | INFO("Archived patch in %lf seconds", (endTime - startTime)); | ||||
} | } | ||||
@@ -131,11 +131,11 @@ void PatchManager::saveAsDialog() { | |||||
std::string filename; | std::string filename; | ||||
if (this->path == "") { | if (this->path == "") { | ||||
dir = asset::user("patches"); | dir = asset::user("patches"); | ||||
system::createDirectories(dir); | |||||
system::createDirs(dir); | |||||
filename = "Untitled.vcv"; | filename = "Untitled.vcv"; | ||||
} | } | ||||
else { | else { | ||||
dir = system::getDirectory(this->path); | |||||
dir = system::getDir(this->path); | |||||
filename = system::getFilename(this->path); | filename = system::getFilename(this->path); | ||||
} | } | ||||
@@ -196,7 +196,7 @@ void PatchManager::saveAutosave() { | |||||
DEFER({json_decref(rootJ);}); | DEFER({json_decref(rootJ);}); | ||||
// Write to temporary path and then rename it to the correct path | // Write to temporary path and then rename it to the correct path | ||||
system::createDirectories(autosavePath); | |||||
system::createDirs(autosavePath); | |||||
std::string tmpPath = patchPath + ".tmp"; | std::string tmpPath = patchPath + ".tmp"; | ||||
FILE* file = std::fopen(tmpPath.c_str(), "w"); | FILE* file = std::fopen(tmpPath.c_str(), "w"); | ||||
if (!file) { | if (!file) { | ||||
@@ -212,9 +212,9 @@ void PatchManager::saveAutosave() { | |||||
void PatchManager::cleanAutosave() { | void PatchManager::cleanAutosave() { | ||||
// Remove files and folders in the `autosave/modules` folder that doesn't match a module in the rack. | |||||
// 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"); | std::string modulesDir = system::join(autosavePath, "modules"); | ||||
if (system::isDirectory(modulesDir)) { | |||||
if (system::isDir(modulesDir)) { | |||||
for (const std::string& entry : system::getEntries(modulesDir)) { | for (const std::string& entry : system::getEntries(modulesDir)) { | ||||
try { | try { | ||||
int64_t moduleId = std::stol(system::getFilename(entry)); | int64_t moduleId = std::stol(system::getFilename(entry)); | ||||
@@ -249,7 +249,7 @@ void PatchManager::load(std::string path) { | |||||
INFO("Loading patch %s", path.c_str()); | INFO("Loading patch %s", path.c_str()); | ||||
system::removeRecursively(autosavePath); | system::removeRecursively(autosavePath); | ||||
system::createDirectories(autosavePath); | |||||
system::createDirs(autosavePath); | |||||
if (isPatchLegacyV1(path)) { | if (isPatchLegacyV1(path)) { | ||||
// Copy the .vcv file directly to "patch.json". | // Copy the .vcv file directly to "patch.json". | ||||
@@ -258,7 +258,7 @@ void PatchManager::load(std::string path) { | |||||
else { | else { | ||||
// Extract the .vcv file as a .tar.zst archive. | // Extract the .vcv file as a .tar.zst archive. | ||||
double startTime = system::getTime(); | double startTime = system::getTime(); | ||||
system::unarchiveToFolder(path, autosavePath); | |||||
system::unarchiveToDir(path, autosavePath); | |||||
double endTime = system::getTime(); | double endTime = system::getTime(); | ||||
INFO("Unarchived patch in %lf seconds", (endTime - startTime)); | INFO("Unarchived patch in %lf seconds", (endTime - startTime)); | ||||
} | } | ||||
@@ -349,10 +349,10 @@ void PatchManager::loadDialog() { | |||||
std::string dir; | std::string dir; | ||||
if (this->path == "") { | if (this->path == "") { | ||||
dir = asset::user("patches"); | dir = asset::user("patches"); | ||||
system::createDirectory(dir); | |||||
system::createDir(dir); | |||||
} | } | ||||
else { | else { | ||||
dir = system::getDirectory(this->path); | |||||
dir = system::getDir(this->path); | |||||
} | } | ||||
osdialog_filters* filters = osdialog_filters_parse(PATCH_FILTERS); | osdialog_filters* filters = osdialog_filters_parse(PATCH_FILTERS); | ||||
@@ -53,10 +53,10 @@ static void* loadLibrary(std::string libraryPath) { | |||||
} | } | ||||
#else | #else | ||||
// As of Rack v2.0, plugins are linked with `-rpath=.` so change current directory so it can find libRack. | // As of Rack v2.0, plugins are linked with `-rpath=.` so change current directory so it can find libRack. | ||||
std::string cwd = system::getWorkingDirectory(); | |||||
system::setWorkingDirectory(asset::systemDir); | |||||
std::string cwd = system::getWorkingDir(); | |||||
system::setWorkingDir(asset::systemDir); | |||||
// Change it back when we're finished | // Change it back when we're finished | ||||
DEFER({system::setWorkingDirectory(cwd);}); | |||||
DEFER({system::setWorkingDir(cwd);}); | |||||
// Load library with dlopen | // Load library with dlopen | ||||
void* handle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_LOCAL); | void* handle = dlopen(libraryPath.c_str(), RTLD_NOW | RTLD_LOCAL); | ||||
if (!handle) | if (!handle) | ||||
@@ -166,7 +166,7 @@ static Plugin* loadPlugin(std::string path) { | |||||
static void loadPlugins(std::string path) { | static void loadPlugins(std::string path) { | ||||
for (std::string pluginPath : system::getEntries(path)) { | for (std::string pluginPath : system::getEntries(path)) { | ||||
if (!system::isDirectory(pluginPath)) | |||||
if (!system::isDir(pluginPath)) | |||||
continue; | continue; | ||||
if (!loadPlugin(pluginPath)) { | if (!loadPlugin(pluginPath)) { | ||||
// Ignore bad plugins. They are reported in the log. | // Ignore bad plugins. They are reported in the log. | ||||
@@ -187,7 +187,7 @@ static void extractPackages(std::string path) { | |||||
// Extract package | // Extract package | ||||
INFO("Extracting package %s", packagePath.c_str()); | INFO("Extracting package %s", packagePath.c_str()); | ||||
try { | try { | ||||
system::unarchiveToFolder(packagePath, path); | |||||
system::unarchiveToDir(packagePath, path); | |||||
} | } | ||||
catch (Exception& e) { | catch (Exception& e) { | ||||
WARN("Plugin package %s failed to extract: %s", packagePath.c_str(), e.what()); | WARN("Plugin package %s failed to extract: %s", packagePath.c_str(), e.what()); | ||||
@@ -221,7 +221,7 @@ void init() { | |||||
} | } | ||||
// Get user plugins directory | // Get user plugins directory | ||||
system::createDirectory(pluginsPath); | |||||
system::createDir(pluginsPath); | |||||
// Extract packages and load plugins | // Extract packages and load plugins | ||||
extractPackages(pluginsPath); | extractPackages(pluginsPath); | ||||
@@ -232,7 +232,7 @@ void init() { | |||||
std::string fundamentalDir = system::join(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(), pluginsPath.c_str()); | |||||
system::unarchiveToDir(fundamentalSrc.c_str(), pluginsPath.c_str()); | |||||
loadPlugin(fundamentalDir); | loadPlugin(fundamentalDir); | ||||
} | } | ||||
} | } | ||||
@@ -100,7 +100,7 @@ bool isFile(const std::string& path) { | |||||
} | } | ||||
bool isDirectory(const std::string& path) { | |||||
bool isDir(const std::string& path) { | |||||
try { | try { | ||||
return fs::is_directory(fs::u8path(path)); | return fs::is_directory(fs::u8path(path)); | ||||
} | } | ||||
@@ -140,7 +140,7 @@ void copy(const std::string& srcPath, const std::string& destPath) { | |||||
} | } | ||||
bool createDirectory(const std::string& path) { | |||||
bool createDir(const std::string& path) { | |||||
try { | try { | ||||
return fs::create_directory(fs::u8path(path)); | return fs::create_directory(fs::u8path(path)); | ||||
} | } | ||||
@@ -150,7 +150,7 @@ bool createDirectory(const std::string& path) { | |||||
} | } | ||||
bool createDirectories(const std::string& path) { | |||||
bool createDirs(const std::string& path) { | |||||
try { | try { | ||||
return fs::create_directories(fs::u8path(path)); | return fs::create_directories(fs::u8path(path)); | ||||
} | } | ||||
@@ -180,7 +180,7 @@ int removeRecursively(const std::string& path) { | |||||
} | } | ||||
std::string getWorkingDirectory() { | |||||
std::string getWorkingDir() { | |||||
try { | try { | ||||
return fs::current_path().generic_u8string(); | return fs::current_path().generic_u8string(); | ||||
} | } | ||||
@@ -190,7 +190,7 @@ std::string getWorkingDirectory() { | |||||
} | } | ||||
void setWorkingDirectory(const std::string& path) { | |||||
void setWorkingDir(const std::string& path) { | |||||
try { | try { | ||||
fs::current_path(fs::u8path(path)); | fs::current_path(fs::u8path(path)); | ||||
} | } | ||||
@@ -230,7 +230,7 @@ std::string getCanonical(const std::string& path) { | |||||
} | } | ||||
std::string getDirectory(const std::string& path) { | |||||
std::string getDir(const std::string& path) { | |||||
try { | try { | ||||
return fs::u8path(path).parent_path().generic_u8string(); | 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 archiveFolder(const std::string& archivePath, std::vector<uint8_t>* archiveData, const std::string& folderPath, int compressionLevel) { | |||||
static void archiveDir(const std::string& archivePath, std::vector<uint8_t>* archiveData, const std::string& dirPath, int compressionLevel) { | |||||
// Based on minitar.c create() in libarchive examples | // Based on minitar.c create() in libarchive examples | ||||
int r; | int r; | ||||
@@ -330,19 +330,19 @@ static void archiveFolder(const std::string& archivePath, std::vector<uint8_t>* | |||||
} | } | ||||
DEFER({archive_write_close(a);}); | DEFER({archive_write_close(a);}); | ||||
// Open folder for reading | |||||
// Open dir for reading | |||||
struct archive* disk = archive_read_disk_new(); | struct archive* disk = archive_read_disk_new(); | ||||
DEFER({archive_read_free(disk);}); | DEFER({archive_read_free(disk);}); | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
r = archive_read_disk_open_w(disk, string::UTF8toUTF16(folderPath).c_str()); | |||||
r = archive_read_disk_open_w(disk, string::UTF8toUTF16(dirPath).c_str()); | |||||
#else | #else | ||||
r = archive_read_disk_open(disk, folderPath.c_str()); | |||||
r = archive_read_disk_open(disk, dirPath.c_str()); | |||||
#endif | #endif | ||||
if (r < ARCHIVE_OK) | if (r < ARCHIVE_OK) | ||||
throw Exception("Archiver could not open folder %s for reading: %s", folderPath.c_str(), archive_error_string(a)); | |||||
throw Exception("Archiver could not open dir %s for reading: %s", dirPath.c_str(), archive_error_string(a)); | |||||
DEFER({archive_read_close(a);}); | DEFER({archive_read_close(a);}); | ||||
// Iterate folder | |||||
// Iterate dir | |||||
for (;;) { | for (;;) { | ||||
struct archive_entry* entry = archive_entry_new(); | struct archive_entry* entry = archive_entry_new(); | ||||
DEFER({archive_entry_free(entry);}); | DEFER({archive_entry_free(entry);}); | ||||
@@ -363,7 +363,7 @@ static void archiveFolder(const std::string& archivePath, std::vector<uint8_t>* | |||||
#else | #else | ||||
entryPath = archive_entry_pathname(entry); | entryPath = archive_entry_pathname(entry); | ||||
#endif | #endif | ||||
entryPath = getRelativePath(entryPath, folderPath); | |||||
entryPath = getRelativePath(entryPath, dirPath); | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// FIXME This doesn't seem to set UTF-8 paths on Windows. | // FIXME This doesn't seem to set UTF-8 paths on Windows. | ||||
archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str()); | archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str()); | ||||
@@ -392,13 +392,13 @@ static void archiveFolder(const std::string& archivePath, std::vector<uint8_t>* | |||||
} | } | ||||
} | } | ||||
void archiveFolder(const std::string& archivePath, const std::string& folderPath, int compressionLevel) { | |||||
archiveFolder(archivePath, NULL, folderPath, compressionLevel); | |||||
void archiveDir(const std::string& archivePath, const std::string& dirPath, int compressionLevel) { | |||||
archiveDir(archivePath, NULL, dirPath, compressionLevel); | |||||
} | } | ||||
std::vector<uint8_t> archiveFolder(const std::string& folderPath, int compressionLevel) { | |||||
std::vector<uint8_t> archiveDir(const std::string& dirPath, int compressionLevel) { | |||||
std::vector<uint8_t> archiveData; | std::vector<uint8_t> archiveData; | ||||
archiveFolder("", &archiveData, folderPath, compressionLevel); | |||||
archiveDir("", &archiveData, dirPath, compressionLevel); | |||||
return archiveData; | return archiveData; | ||||
} | } | ||||
@@ -420,7 +420,7 @@ static la_ssize_t archiveReadVectorCallback(struct archive *a, void* client_data | |||||
return len; | return len; | ||||
} | } | ||||
static void unarchiveToFolder(const std::string& archivePath, const std::vector<uint8_t>* archiveData, const std::string& folderPath) { | |||||
static void unarchiveToDir(const std::string& archivePath, const std::vector<uint8_t>* archiveData, const std::string& dirPath) { | |||||
// Based on minitar.c extract() in libarchive examples | // Based on minitar.c extract() in libarchive examples | ||||
int r; | int r; | ||||
@@ -450,7 +450,7 @@ static void unarchiveToFolder(const std::string& archivePath, const std::vector< | |||||
} | } | ||||
DEFER({archive_read_close(a);}); | DEFER({archive_read_close(a);}); | ||||
// Open folder for writing | |||||
// Open dir for writing | |||||
struct archive* disk = archive_write_disk_new(); | struct archive* disk = archive_write_disk_new(); | ||||
DEFER({archive_write_free(disk);}); | DEFER({archive_write_free(disk);}); | ||||
int flags = ARCHIVE_EXTRACT_TIME; | int flags = ARCHIVE_EXTRACT_TIME; | ||||
@@ -467,11 +467,11 @@ static void unarchiveToFolder(const std::string& archivePath, const std::vector< | |||||
if (r < ARCHIVE_OK) | if (r < ARCHIVE_OK) | ||||
throw Exception("Unarchiver could not read entry from archive: %s", archive_error_string(a)); | throw Exception("Unarchiver could not read entry from archive: %s", archive_error_string(a)); | ||||
// Convert relative pathname to absolute based on folderPath | |||||
// Convert relative pathname to absolute based on dirPath | |||||
std::string entryPath = archive_entry_pathname(entry); | std::string entryPath = archive_entry_pathname(entry); | ||||
if (!fs::u8path(entryPath).is_relative()) | if (!fs::u8path(entryPath).is_relative()) | ||||
throw Exception("Unarchiver does not support absolute tar paths: %s", entryPath.c_str()); | throw Exception("Unarchiver does not support absolute tar paths: %s", entryPath.c_str()); | ||||
entryPath = (fs::u8path(folderPath) / fs::u8path(entryPath)).generic_u8string(); | |||||
entryPath = (fs::u8path(dirPath) / fs::u8path(entryPath)).generic_u8string(); | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str()); | archive_entry_copy_pathname_w(entry, string::UTF8toUTF16(entryPath).c_str()); | ||||
#else | #else | ||||
@@ -481,7 +481,7 @@ static void unarchiveToFolder(const std::string& archivePath, const std::vector< | |||||
// Write entry to disk | // Write entry to disk | ||||
r = archive_write_header(disk, entry); | r = archive_write_header(disk, entry); | ||||
if (r < ARCHIVE_OK) | if (r < ARCHIVE_OK) | ||||
throw Exception("Unarchiver could not write file to folder: %s", archive_error_string(disk)); | |||||
throw Exception("Unarchiver could not write file to dir: %s", archive_error_string(disk)); | |||||
// Copy data to file | // Copy data to file | ||||
for (;;) { | for (;;) { | ||||
@@ -508,12 +508,12 @@ static void unarchiveToFolder(const std::string& archivePath, const std::vector< | |||||
} | } | ||||
} | } | ||||
void unarchiveToFolder(const std::string& archivePath, const std::string& folderPath) { | |||||
unarchiveToFolder(archivePath, NULL, folderPath); | |||||
void unarchiveToDir(const std::string& archivePath, const std::string& dirPath) { | |||||
unarchiveToDir(archivePath, NULL, dirPath); | |||||
} | } | ||||
void unarchiveToFolder(const std::vector<uint8_t>& archiveData, const std::string& folderPath) { | |||||
unarchiveToFolder("", &archiveData, folderPath); | |||||
void unarchiveToDir(const std::vector<uint8_t>& archiveData, const std::string& dirPath) { | |||||
unarchiveToDir("", &archiveData, dirPath); | |||||
} | } | ||||
@@ -687,7 +687,7 @@ void openBrowser(const std::string& url) { | |||||
} | } | ||||
void openFolder(const std::string& path) { | |||||
void openDir(const std::string& path) { | |||||
#if defined ARCH_LIN | #if defined ARCH_LIN | ||||
std::string command = "xdg-open \"" + path + "\""; | std::string command = "xdg-open \"" + path + "\""; | ||||
(void) std::system(command.c_str()); | (void) std::system(command.c_str()); | ||||
@@ -507,10 +507,10 @@ void Window::screenshot(const std::string& screenshotPath) { | |||||
void Window::screenshotModules(const std::string& screenshotsDir, float zoom) { | void Window::screenshotModules(const std::string& screenshotsDir, float zoom) { | ||||
// Iterate plugins and create directories | // Iterate plugins and create directories | ||||
system::createDirectories(screenshotsDir); | |||||
system::createDirs(screenshotsDir); | |||||
for (plugin::Plugin* p : plugin::plugins) { | for (plugin::Plugin* p : plugin::plugins) { | ||||
std::string dir = system::join(screenshotsDir, p->slug); | std::string dir = system::join(screenshotsDir, p->slug); | ||||
system::createDirectory(dir); | |||||
system::createDir(dir); | |||||
for (plugin::Model* model : p->models) { | for (plugin::Model* model : p->models) { | ||||
std::string filename = system::join(dir, model->slug + ".png"); | std::string filename = system::join(dir, model->slug + ".png"); | ||||