Add dirExists() member function in FileSystemModule.

This commit is contained in:
David Capello 2010-09-26 18:26:38 -03:00
parent a3616cec54
commit aa397c4fbf
3 changed files with 17 additions and 18 deletions

View File

@ -369,6 +369,18 @@ IFileItem* FileSystemModule::getFileItemFromPath(const jstring& path)
return fileitem;
}
bool FileSystemModule::dirExists(const jstring& path)
{
struct al_ffblk info;
int ret;
jstring path2 = path / "*.*";
ret = al_findfirst(path2.c_str(), &info, FA_ALL);
al_findclose(&info);
return (ret == 0);
}
// ======================================================================
// FileItem class (IFileItem implementation)
// ======================================================================
@ -1005,7 +1017,7 @@ static FileItem* get_fileitem_by_path(const jstring& path, bool create_if_not)
// get the attributes of the file
int attrib = 0;
if (!file_exists(path.c_str(), FA_ALL, &attrib)) {
if (!ji_dir_exists(path.c_str()))
if (!FileSystemModule::instance()->dirExists(path))
return NULL;
attrib = FA_DIREC;
}

View File

@ -43,6 +43,9 @@ public:
IFileItem* getRootFileItem();
IFileItem* getFileItemFromPath(const jstring& path);
bool dirExists(const jstring& path);
};
class IFileItem

View File

@ -76,22 +76,6 @@ static void on_exit_delete_navigation_history()
jlist_free(navigation_history);
}
static bool dir_exists(const char *filename)
{
struct al_ffblk info;
char buf[1024];
int ret;
ustrcpy(buf, filename);
put_backslash(buf);
ustrcat(buf, "*.*");
ret = al_findfirst(buf, &info, FA_ALL);
al_findclose(&info);
return (ret == 0);
}
/**
* Shows the dialog to select a file in ASE.
*
@ -129,7 +113,7 @@ jstring ase_file_selector(const jstring& message,
// is the folder find?
if (!start_folder) {
// if the `path' doesn't exist...
if (path.empty() || (!dir_exists(path.c_str()))) {
if (path.empty() || (!FileSystemModule::instance()->dirExists(path))) {
// we can get the current `path' from the system
#ifdef HAVE_DRIVES
int drive = _al_getdrive();