1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Show error message if vcmi unable to access data directory instead of

silent crash
This commit is contained in:
Ivan Savenko 2024-06-19 18:25:54 +00:00
parent 0e4be8c776
commit 2b7131cfea
3 changed files with 20 additions and 3 deletions

View File

@ -208,7 +208,14 @@ int main(int argc, char * argv[])
logGlobal->info("The log file will be saved to %s", logPath); logGlobal->info("The log file will be saved to %s", logPath);
// Init filesystem and settings // Init filesystem and settings
preinitDLL(::console, false); try
{
preinitDLL(::console, false);
}
catch (const DataLoadingException & e)
{
handleFatalError(e.what(), true);
}
Settings session = settings.write["session"]; Settings session = settings.write["session"];
auto setSettingBool = [&](std::string key, std::string arg) { auto setSettingBool = [&](std::string key, std::string arg) {

View File

@ -10,6 +10,8 @@
#include "StdInc.h" #include "StdInc.h"
#include "CFileInputStream.h" #include "CFileInputStream.h"
#include "../ExceptionsCommon.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size) CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 start, si64 size)
@ -18,7 +20,7 @@ CFileInputStream::CFileInputStream(const boost::filesystem::path & file, si64 st
fileStream{file.c_str(), std::ios::in | std::ios::binary} fileStream{file.c_str(), std::ios::in | std::ios::binary}
{ {
if (fileStream.fail()) if (fileStream.fail())
throw std::runtime_error("File " + file.string() + " isn't available."); throw DataLoadingException("Failed to open file '" + file.string() + "'. Reason: " + strerror(errno) );
if (dataSize == 0) if (dataSize == 0)
{ {

View File

@ -12,14 +12,22 @@
#include "CFileInputStream.h" #include "CFileInputStream.h"
#include "../ExceptionsCommon.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial): CFilesystemLoader::CFilesystemLoader(std::string _mountPoint, boost::filesystem::path baseDirectory, size_t depth, bool initial):
baseDirectory(std::move(baseDirectory)), baseDirectory(std::move(baseDirectory)),
mountPoint(std::move(_mountPoint)), mountPoint(std::move(_mountPoint)),
fileList(listFiles(mountPoint, depth, initial)),
recursiveDepth(depth) recursiveDepth(depth)
{ {
try {
fileList = listFiles(mountPoint, depth, initial);
}
catch (const boost::filesystem::filesystem_error & e) {
throw DataLoadingException("Failed to load content of '" + baseDirectory.string() + "'. Reason: " + e.what());
}
logGlobal->trace("File system loaded, %d files found", fileList.size()); logGlobal->trace("File system loaded, %d files found", fileList.size());
} }