|
|
@@ -1,10 +1,21 @@
|
|
|
+#include <sys/stat.h>
|
|
|
+
|
|
|
#include "CDirectory.h"
|
|
|
+#include "CAssetLoadException.h"
|
|
|
|
|
|
using namespace WallpaperEngine::Assets;
|
|
|
|
|
|
CDirectory::CDirectory (std::string basepath) :
|
|
|
m_basepath (std::move (basepath))
|
|
|
{
|
|
|
+ // ensure the specified path exists
|
|
|
+ struct stat buffer;
|
|
|
+
|
|
|
+ if (stat (this->m_basepath.c_str (), &buffer) != 0)
|
|
|
+ throw std::runtime_error ("Cannot find " + this->m_basepath + ". This folder is required for wallpaper engine to work");
|
|
|
+
|
|
|
+ if (!S_ISDIR(buffer.st_mode))
|
|
|
+ throw std::runtime_error ("Cannot find " + this->m_basepath + ". There's an assets file in it's place");
|
|
|
}
|
|
|
|
|
|
CDirectory::~CDirectory ()
|
|
|
@@ -30,7 +41,7 @@ void* CDirectory::readFile (std::string filename, uint32_t* length)
|
|
|
FILE* fp = fopen (final.c_str (), "rb");
|
|
|
|
|
|
if (fp == nullptr)
|
|
|
- throw std::runtime_error ("Cannot find requested file");
|
|
|
+ throw CAssetLoadException(filename, "Cannot find file");
|
|
|
|
|
|
// go to the end, get the position and return to the beginning
|
|
|
fseek (fp, 0, SEEK_END);
|
|
|
@@ -43,7 +54,7 @@ void* CDirectory::readFile (std::string filename, uint32_t* length)
|
|
|
if (fread (contents, size, 1, fp) != 1)
|
|
|
{
|
|
|
delete[] contents;
|
|
|
- throw std::runtime_error ("Unexpected error when reading the file");
|
|
|
+ throw CAssetLoadException (filename, "Unexpected error when reading the file");
|
|
|
}
|
|
|
|
|
|
// store it in the cache too
|