mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
+ Introduce File::exists() and use that instead of trying to just open the file.
This commit is contained in:
parent
ba9b13d9e6
commit
ecc3d39fdb
|
@ -301,18 +301,14 @@ sptr< Dictionary::DataRequest > DictdDictionary::getArticle( wstring const & wor
|
|||
|
||||
static bool tryPossibleName( string const & name, string & copyTo )
|
||||
{
|
||||
try
|
||||
if ( File::exists( name ) )
|
||||
{
|
||||
File::Class f( name, "rb" );
|
||||
|
||||
copyTo = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
vector< sptr< Dictionary::Class > > makeDictionaries(
|
||||
|
|
|
@ -1276,18 +1276,14 @@ sptr< Dictionary::DataRequest > DslDictionary::getResource( string const & name
|
|||
|
||||
static bool tryPossibleName( string const & name, string & copyTo )
|
||||
{
|
||||
try
|
||||
if ( File::exists( name ) )
|
||||
{
|
||||
File::Class f( name, "rb" );
|
||||
|
||||
copyTo = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
|
15
src/file.cc
15
src/file.cc
|
@ -6,6 +6,10 @@
|
|||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace File {
|
||||
|
||||
enum
|
||||
|
@ -15,6 +19,17 @@ enum
|
|||
WriteBufferSize = 65536
|
||||
};
|
||||
|
||||
bool exists( char const * filename ) throw()
|
||||
{
|
||||
#ifdef __WIN32
|
||||
struct _stat buf;
|
||||
return _stat( filename, &buf ) == 0;
|
||||
#else
|
||||
struct stat buf;
|
||||
return stat( filename, &buf ) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Class::open( char const * filename, char const * mode ) throw( exCantOpen )
|
||||
{
|
||||
f = fopen( filename, mode );
|
||||
|
|
|
@ -19,6 +19,12 @@ DEF_EX( exReadError, "Error reading from the file", Ex )
|
|||
DEF_EX( exWriteError, "Error writing to the file", Ex )
|
||||
DEF_EX( exSeekError, "File seek error", Ex )
|
||||
|
||||
/// Checks if the file exists or not.
|
||||
bool exists( char const * filename ) throw();
|
||||
|
||||
inline bool exists( std::string const & filename ) throw()
|
||||
{ return exists( filename.c_str() ); }
|
||||
|
||||
class Class
|
||||
{
|
||||
FILE * f;
|
||||
|
|
|
@ -815,18 +815,14 @@ Ifo::Ifo( File::Class & f ):
|
|||
|
||||
static bool tryPossibleName( string const & name, string & copyTo )
|
||||
{
|
||||
try
|
||||
if ( File::exists( name ) )
|
||||
{
|
||||
File::Class f( name, "rb" );
|
||||
|
||||
copyTo = name;
|
||||
|
||||
return true;
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void findCorrespondingFiles( string const & ifo,
|
||||
|
|
Loading…
Reference in a new issue