mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 18:19:55 +00:00
improved error handling
This commit is contained in:
parent
afc2e840ae
commit
e9ba7339f3
3 changed files with 17 additions and 13 deletions
|
@ -95,6 +95,11 @@ namespace Files
|
|||
return iter->second;
|
||||
}
|
||||
|
||||
bool MultiDirCollection::doesExist (const std::string& file) const
|
||||
{
|
||||
return mFiles.find (file)!=mFiles.end();
|
||||
}
|
||||
|
||||
MultiDirCollection::TIter MultiDirCollection::begin() const
|
||||
{
|
||||
return mFiles.begin();
|
||||
|
|
|
@ -73,6 +73,9 @@ namespace Files
|
|||
/// If the file does not exist, an exception is thrown. \a file must include
|
||||
/// the extension.
|
||||
|
||||
bool doesExist (const std::string& file) const;
|
||||
///< \return Does a file with the given name exist?
|
||||
|
||||
TIter begin() const;
|
||||
///< Return iterator pointing to the first file.
|
||||
|
||||
|
|
|
@ -24,22 +24,18 @@ namespace Translation
|
|||
const std::string& extension,
|
||||
const Files::Collections& dataFileCollections)
|
||||
{
|
||||
std::string path;
|
||||
try
|
||||
{
|
||||
path = dataFileCollections.getCollection(extension).getPath(fileNameNoExtension + extension).string();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
//no file
|
||||
return;
|
||||
}
|
||||
std::string fileName = fileNameNoExtension + extension;
|
||||
|
||||
std::ifstream stream(path);
|
||||
if (stream.is_open())
|
||||
if (dataFileCollections.getCollection (extension).doesExist (fileName))
|
||||
{
|
||||
std::string path = dataFileCollections.getCollection (extension).getPath (fileName).string();
|
||||
|
||||
std::ifstream stream (path);
|
||||
|
||||
if (!stream.is_open())
|
||||
throw std::runtime_error ("failed to open translation file: " + fileName);
|
||||
|
||||
loadDataFromStream(container, stream);
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue