mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +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 )
|
static bool tryPossibleName( string const & name, string & copyTo )
|
||||||
{
|
{
|
||||||
try
|
if ( File::exists( name ) )
|
||||||
{
|
{
|
||||||
File::Class f( name, "rb" );
|
|
||||||
|
|
||||||
copyTo = name;
|
copyTo = name;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch( ... )
|
else
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vector< sptr< Dictionary::Class > > makeDictionaries(
|
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 )
|
static bool tryPossibleName( string const & name, string & copyTo )
|
||||||
{
|
{
|
||||||
try
|
if ( File::exists( name ) )
|
||||||
{
|
{
|
||||||
File::Class f( name, "rb" );
|
|
||||||
|
|
||||||
copyTo = name;
|
copyTo = name;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch( ... )
|
else
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
15
src/file.cc
15
src/file.cc
|
@ -6,6 +6,10 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace File {
|
namespace File {
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -15,6 +19,17 @@ enum
|
||||||
WriteBufferSize = 65536
|
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 )
|
void Class::open( char const * filename, char const * mode ) throw( exCantOpen )
|
||||||
{
|
{
|
||||||
f = fopen( filename, mode );
|
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( exWriteError, "Error writing to the file", Ex )
|
||||||
DEF_EX( exSeekError, "File seek error", 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
|
class Class
|
||||||
{
|
{
|
||||||
FILE * f;
|
FILE * f;
|
||||||
|
|
|
@ -815,18 +815,14 @@ Ifo::Ifo( File::Class & f ):
|
||||||
|
|
||||||
static bool tryPossibleName( string const & name, string & copyTo )
|
static bool tryPossibleName( string const & name, string & copyTo )
|
||||||
{
|
{
|
||||||
try
|
if ( File::exists( name ) )
|
||||||
{
|
{
|
||||||
File::Class f( name, "rb" );
|
|
||||||
|
|
||||||
copyTo = name;
|
copyTo = name;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch( ... )
|
else
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void findCorrespondingFiles( string const & ifo,
|
static void findCorrespondingFiles( string const & ifo,
|
||||||
|
|
Loading…
Reference in a new issue