diff --git a/include/util/common.hpp b/include/util/common.hpp index 2cb67495..6526abef 100644 --- a/include/util/common.hpp +++ b/include/util/common.hpp @@ -148,6 +148,7 @@ std::vector systemListEntries(std::string path); bool systemIsFile(std::string path); bool systemIsDirectory(std::string path); void systemCopy(std::string srcPath, std::string destPath); +void systemCreateDirectory(std::string path); /** Opens a URL, also happens to work with PDFs and folders. Shell injection is possible, so make sure the URL is trusted or hard coded. diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 033e1c02..fbdcb519 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -69,7 +69,14 @@ void RackWidget::reset() { } void RackWidget::openDialog() { - std::string dir = lastPath.empty() ? assetLocal("") : stringDirectory(lastPath); + std::string dir; + if (lastPath.empty()) { + dir = assetLocal("patches"); + systemCreateDirectory(dir); + } + else { + dir = stringDirectory(lastPath); + } char *path = osdialog_file(OSDIALOG_OPEN, dir.c_str(), NULL, NULL); if (path) { loadPatch(path); @@ -88,7 +95,14 @@ void RackWidget::saveDialog() { } void RackWidget::saveAsDialog() { - std::string dir = lastPath.empty() ? assetLocal("") : stringDirectory(lastPath); + std::string dir; + if (lastPath.empty()) { + dir = assetLocal("patches"); + systemCreateDirectory(dir); + } + else { + dir = stringDirectory(lastPath); + } char *path = osdialog_file(OSDIALOG_SAVE, dir.c_str(), "Untitled.vcv", NULL); if (path) { diff --git a/src/asset.cpp b/src/asset.cpp index 04f46a58..c6d71ce6 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -64,7 +64,6 @@ std::string assetLocal(std::string filename) { assert(pw); dir = pw->pw_dir; dir += "/Documents/Rack"; - mkdir(dir.c_str(), 0755); #endif #if ARCH_WIN // Get "My Documents" folder @@ -73,7 +72,6 @@ std::string assetLocal(std::string filename) { assert(result == S_OK); dir = buf; dir += "/Rack"; - CreateDirectory(dir.c_str(), NULL); #endif #if ARCH_LIN const char *home = getenv("HOME"); @@ -84,8 +82,8 @@ std::string assetLocal(std::string filename) { } dir = home; dir += "/.Rack"; - mkdir(dir.c_str(), 0755); #endif + systemCreateDirectory(dir); #else // RELEASE dir = "."; #endif // RELEASE diff --git a/src/util/system.cpp b/src/util/system.cpp index e4ef26ae..24aa9764 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -72,6 +72,14 @@ void systemCopy(std::string srcPath, std::string destPath) { } } +void systemCreateDirectory(std::string path) { +#if ARCH_WIN + CreateDirectory(path.c_str(), NULL); +#else + mkdir(path.c_str(), 0755); +#endif +} + void systemOpenBrowser(std::string url) { #if ARCH_LIN std::string command = "xdg-open " + url;