version 1.1, 2001/01/14 19:51:35
|
version 1.2, 2001/02/11 05:42:33
|
|
|
// Author: | // Author: |
// | // |
// $Log$ | // $Log$ |
// Revision 1.1 2001/01/14 19:51:35 mike |
// Revision 1.2 2001/02/11 05:42:33 mike |
// Initial revision |
// new |
|
// |
|
// Revision 1.1.1.1 2001/01/14 19:51:35 mike |
|
// Pegasus import |
// | // |
// | // |
//END_HISTORY | //END_HISTORY |
|
|
#include <cstdio> | #include <cstdio> |
#include "Destroyer.h" | #include "Destroyer.h" |
#include "FileSystem.h" | #include "FileSystem.h" |
|
#include "Dir.h" |
| |
// ATTN-B: porting! | // ATTN-B: porting! |
| |
|
|
#endif | #endif |
} | } |
| |
|
Boolean FileSystem::existsIgnoreCase(const String& path, String& realPath) |
|
{ |
|
realPath.clear(); |
|
Destroyer<char> destroyer(_clonePath(path)); |
|
char* p = destroyer.getPointer(); |
|
|
|
char* dirPath; |
|
char* fileName; |
|
char* slash = strrchr(p, '/'); |
|
|
|
if (slash) |
|
{ |
|
*slash = '\0'; |
|
fileName = slash + 1; |
|
dirPath = p; |
|
if (*fileName == '\0') |
|
return false; |
|
} |
|
else |
|
{ |
|
fileName = p; |
|
dirPath = "."; |
|
} |
|
|
|
for (Dir dir(dirPath); dir.more(); dir.next()) |
|
{ |
|
#ifdef PEGASUS_OS_TYPE_WINDOWS |
|
if (stricmp(fileName, dir.getName()) == 0) |
|
#else |
|
if (strcasecmp(fileName, dir.getName()) == 0) |
|
#endif |
|
{ |
|
if (strcmp(dirPath, ".") == 0) |
|
realPath = dir.getName(); |
|
else |
|
{ |
|
realPath = dirPath; |
|
realPath += '/'; |
|
realPath += dir.getName(); |
|
} |
|
return true; |
|
} |
|
} |
|
|
|
return false; |
|
} |
|
|
Boolean FileSystem::canRead(const String& path) | Boolean FileSystem::canRead(const String& path) |
{ | { |
Destroyer<char> p(_clonePath(path)); | Destroyer<char> p(_clonePath(path)); |
|
|
{ | { |
paths.clear(); | paths.clear(); |
| |
#ifdef PEGASUS_OS_TYPE_WINDOWS |
for (Dir dir(path); dir.more(); dir.next()) |
|
|
String tmp = path; |
|
tmp += "/*"; |
|
Destroyer<char> p(tmp.allocateCString()); |
|
|
|
long file; |
|
struct _finddata_t findData; |
|
|
|
if ((file = _findfirst(p.getPointer(), &findData)) == -1L) |
|
return false; |
|
|
|
do |
|
{ | { |
const char* name = findData.name; |
String name = dir.getName(); |
| |
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) |
if (name == "." || name == "..") |
continue; |
|
|
|
paths.append(name); |
|
|
|
} while (_findnext(file, &findData) == 0); |
|
|
|
_findclose(file); |
|
|
|
#else |
|
|
|
Destroyer<char> p(_clonePath(path)); |
|
DIR* dir = opendir(p.getPointer()); |
|
|
|
if (!dir) |
|
return false; |
|
|
|
struct dirent* entry; |
|
|
|
while ((entry = readdir(dir)) != NULL) |
|
{ |
|
const char* name = entry->d_name; |
|
|
|
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) |
|
continue; | continue; |
| |
paths.append(name); | paths.append(name); |
} | } |
| |
closedir(dir); |
|
#endif |
|
|
|
return true; | return true; |
} | } |
| |