commit 7fc6a3801e66279653cba356b566f395d92c06ac
parent d59ab4160942f7904360deab6041ea7a495e34e2
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sat, 17 Jun 2017 17:51:39 -0400
core: report an error when folders cannot be created in the resource directory
Diffstat:
4 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/filesystem.cpp b/src/filesystem.cpp
@@ -55,7 +55,8 @@ bool FS::open(ifstream &stream, const Path &path)
bool FS::open(ofstream &stream, const Path &path)
{
- mkdir(path.dirname());
+ if(!mkdir(path.dirname()))
+ return false;
const Path &fullPath = Path::prefixRoot(path);
stream.open(make_autostring(fullPath.join()), ios_base::binary);
@@ -169,10 +170,13 @@ bool FS::exists(const Path &path)
return file_exists(fullPath.join().c_str());
}
-void FS::mkdir(const Path &path)
+bool FS::mkdir(const Path &path)
{
+ if(exists(path))
+ return true;
+
const Path &fullPath = Path::prefixRoot(path);
- RecursiveCreateDirectory(fullPath.join().c_str(), 0);
+ return RecursiveCreateDirectory(fullPath.join().c_str(), 0) == 0;
}
string FS::lastError()
diff --git a/src/filesystem.hpp b/src/filesystem.hpp
@@ -34,7 +34,7 @@ namespace FS {
bool removeRecursive(const Path &);
bool mtime(const Path &, time_t *);
bool exists(const Path &);
- void mkdir(const Path &);
+ bool mkdir(const Path &);
std::string lastError();
};
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -85,7 +85,7 @@ ReaPack::ReaPack(REAPER_PLUGIN_HINSTANCE instance)
DownloadContext::GlobalInit();
RichEdit::Init();
- FS::mkdir(Path::CACHE);
+ createDirectories();
m_config = new Config;
m_config->read(Path::prefixRoot(Path::CONFIG));
@@ -385,6 +385,25 @@ void ReaPack::refreshBrowser()
m_browser->refresh();
}
+void ReaPack::createDirectories()
+{
+ const Path &path = Path::CACHE;
+
+ if(FS::mkdir(path))
+ return;
+
+ const auto_string &desc = make_autostring(FS::lastError());
+
+ auto_char msg[255];
+ auto_snprintf(msg, auto_size(msg),
+ AUTO_STR("ReaPack could not create %s! ")
+ AUTO_STR("Please investigate or report this issue.\n\n")
+ AUTO_STR("Error description: %s"),
+ make_autostring(Path::prefixRoot(path).join()).c_str(), desc.c_str());
+
+ MessageBox(Splash_GetWnd(), msg, AUTO_STR("ReaPack"), MB_OK);
+}
+
void ReaPack::registerSelf()
{
// hard-coding galore!
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -82,6 +82,7 @@ public:
Config *config() const { return m_config; }
private:
+ void createDirectories();
void registerSelf();
void teardownTransaction();