From 1a5a4daa52b79ec1fd93e15703a80fc61c6e27c7 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Mon, 2 Feb 2009 15:02:57 +0000 Subject: [PATCH] When searching for resource files, allow them to be not only in the dictionary directory, but also in the dictionary-name.files/ subdirectory. --- src/dsl.cc | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/dsl.cc b/src/dsl.cc index bb2613e9..d0526834 100644 --- a/src/dsl.cc +++ b/src/dsl.cc @@ -380,7 +380,18 @@ string DslDictionary::nodeToHtml( ArticleDom::Node const & node ) try { - File::Class f( n, "r" ); + try + { + File::Class f( n, "rb" ); + } + catch( File::exCantOpen & ) + { + n = getDictionaryFilenames()[ 0 ] + ".files" + + FsEncoding::separator() + + FsEncoding::encode( filename ); + + File::Class f( n, "rb" ); + } search = false; } @@ -589,6 +600,19 @@ string DslDictionary::getArticle( wstring const & word, return result; } +void loadFromFile( string const & n, vector< char > & data ) +{ + File::Class f( n, "rb" ); + + f.seekEnd(); + + data.resize( f.tell() ); + + f.rewind(); + + f.read( &data.front(), data.size() ); +} + void DslDictionary::getResource( string const & name, vector< char > & data ) throw( Dictionary::exNoSuchResource, std::exception ) @@ -602,15 +626,18 @@ void DslDictionary::getResource( string const & name, try { - File::Class f( n, "rb" ); + try + { + loadFromFile( n, data ); + } + catch( File::exCantOpen & ) + { + n = getDictionaryFilenames()[ 0 ] + ".files" + + FsEncoding::separator() + + FsEncoding::encode( name ); - f.seekEnd(); - - data.resize( f.tell() ); - - f.rewind(); - - f.read( &data.front(), data.size() ); + loadFromFile( n, data ); + } if ( Filetype::isNameOfTiff( name ) ) {