diff --git a/components/files/multidircollection.cpp b/components/files/multidircollection.cpp index b44c42986..347de96a6 100644 --- a/components/files/multidircollection.cpp +++ b/components/files/multidircollection.cpp @@ -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(); diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index e8abeb45d..3b420d677 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -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. diff --git a/components/translation/translation.cpp b/components/translation/translation.cpp index feda76f6f..b559c6c1c 100644 --- a/components/translation/translation.cpp +++ b/components/translation/translation.cpp @@ -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(); } }