mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 13:45:34 +00:00
Add a check if the requested file is not found
This commit is contained in:
parent
7f936ad18f
commit
19fbba080d
2 changed files with 10 additions and 8 deletions
|
@ -141,7 +141,7 @@ namespace Bsa
|
||||||
mIsLoaded = true;
|
mIsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BA2DX10File::FileRecord BA2DX10File::getFileRecord(const std::string& str) const
|
std::optional<BA2DX10File::FileRecord> BA2DX10File::getFileRecord(const std::string& str) const
|
||||||
{
|
{
|
||||||
for (const auto c : str)
|
for (const auto c : str)
|
||||||
{
|
{
|
||||||
|
@ -169,13 +169,13 @@ namespace Bsa
|
||||||
uint32_t folderHash = generateHash(folder);
|
uint32_t folderHash = generateHash(folder);
|
||||||
auto it = mFolders.find(folderHash);
|
auto it = mFolders.find(folderHash);
|
||||||
if (it == mFolders.end())
|
if (it == mFolders.end())
|
||||||
return FileRecord(); // folder not found, return default which has offset of sInvalidOffset
|
return std::nullopt; // folder not found
|
||||||
|
|
||||||
uint32_t fileHash = generateHash(fileName);
|
uint32_t fileHash = generateHash(fileName);
|
||||||
uint32_t extHash = *reinterpret_cast<const uint32_t*>(ext.data() + 1);
|
uint32_t extHash = *reinterpret_cast<const uint32_t*>(ext.data() + 1);
|
||||||
auto iter = it->second.find({ fileHash, extHash });
|
auto iter = it->second.find({ fileHash, extHash });
|
||||||
if (iter == it->second.end())
|
if (iter == it->second.end())
|
||||||
return FileRecord(); // file not found, return default which has offset of sInvalidOffset
|
return std::nullopt; // file not found
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,8 +221,9 @@ namespace Bsa
|
||||||
|
|
||||||
Files::IStreamPtr BA2DX10File::getFile(const FileStruct* file)
|
Files::IStreamPtr BA2DX10File::getFile(const FileStruct* file)
|
||||||
{
|
{
|
||||||
FileRecord fileRec = getFileRecord(file->name());
|
if (auto fileRec = getFileRecord(file->name()); fileRec)
|
||||||
return getFile(fileRec);
|
return getFile(*fileRec);
|
||||||
|
fail("File not found: " + std::string(file->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BA2DX10File::addFile(const std::string& filename, std::istream& file)
|
void BA2DX10File::addFile(const std::string& filename, std::istream& file)
|
||||||
|
@ -233,8 +234,9 @@ namespace Bsa
|
||||||
|
|
||||||
Files::IStreamPtr BA2DX10File::getFile(const char* file)
|
Files::IStreamPtr BA2DX10File::getFile(const char* file)
|
||||||
{
|
{
|
||||||
FileRecord fileRec = getFileRecord(file);
|
if (auto fileRec = getFileRecord(file); fileRec)
|
||||||
return getFile(fileRec);
|
return getFile(*fileRec);
|
||||||
|
fail("File not found: " + std::string(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const uint32_t DDSD_CAPS = 0x00000001;
|
constexpr const uint32_t DDSD_CAPS = 0x00000001;
|
||||||
|
|
|
@ -41,7 +41,7 @@ namespace Bsa
|
||||||
|
|
||||||
std::list<std::vector<char>> mFileNames;
|
std::list<std::vector<char>> mFileNames;
|
||||||
|
|
||||||
FileRecord getFileRecord(const std::string& str) const;
|
std::optional<FileRecord> getFileRecord(const std::string& str) const;
|
||||||
|
|
||||||
Files::IStreamPtr getFile(const FileRecord& fileRecord);
|
Files::IStreamPtr getFile(const FileRecord& fileRecord);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue