[Libufo-commits] ufo-0.5/src/util ufilearchive.cpp,1.9,1.10
Status: Beta
Brought to you by:
schmidtjf
|
From: Johannes S. <sch...@us...> - 2005-10-17 15:35:02
|
Update of /cvsroot/libufo/ufo-0.5/src/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5300/src/util Modified Files: ufilearchive.cpp Log Message: Added isDirectory, dirName. Removed createFileStream, destroyFileStream. Index: ufilearchive.cpp =================================================================== RCS file: /cvsroot/libufo/ufo-0.5/src/util/ufilearchive.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ufilearchive.cpp 13 Feb 2005 18:00:13 -0000 1.9 --- ufilearchive.cpp 17 Oct 2005 15:34:48 -0000 1.10 *************** *** 38,41 **** --- 38,42 ---- #include <cstring> #include <dirent.h> + #include <sys/stat.h> #endif *************** *** 60,64 **** } ! // this code is shamelessly stolen from the LGPL'ed PhysicsFS // by Ryan C. Gordon -- http://icculus.org/physfs/ std::vector<std::string> --- 61,65 ---- } ! // this code is inspired PhysicsFS // by Ryan C. Gordon -- http://icculus.org/physfs/ std::vector<std::string> *************** *** 79,100 **** break; } ! if (strcmp(ent->d_name, ".") == 0) { continue; } ! if (strcmp(ent->d_name, "..") == 0) { continue; } ! /* FIXME ! ! following sym links might compromise the system security ! if (omitSymLinks) { ! char *p; ! int len = strlen(ent->d_name) + dlen + 1; ! if (len > bufsize) { ! p = realloc(buf, len); ! if (p == NULL) { continue; } ! buf = p; ! bufsize = len; ! } // if ! ! strcpy(buf + dlen, ent->d_name); ! if (__PHYSFS_platformIsSymLink(buf)) { continue; } ! } // if ! */ ret.push_back(ent->d_name); } // while --- 80,89 ---- break; } ! if (strcmp(ent->d_name, ".") == 0 || ! strcmp(ent->d_name, "..") == 0) { ! // omit . and .. ! continue; ! } ! // FIXME: should we omit sym links? ret.push_back(ent->d_name); } // while *************** *** 120,126 **** do { ! if (strcmp(ent.cFileName, ".") == 0) { continue; } ! if (strcmp(ent.cFileName, "..") == 0) { continue; } ! ret.push_back(ent.cFileName); --- 109,117 ---- do { ! if (strcmp(ent.cFileName, ".") == 0 || ! strcmp(ent.cFileName, "..") == 0) { ! // omit . and .. ! continue; ! } ret.push_back(ent.cFileName); *************** *** 132,135 **** --- 123,160 ---- } + std::string + UFileArchive::dirName(const std::string & path) { + std::string::size_type pos = path.size(); + // eliminate trailing slashes + if (path[path.size() - 1] == '/') { + pos = path.find_last_not_of('/'); + } + // search directory slash + pos = path.find_last_of('/', pos); + // eliminate all slashes + pos = path.find_last_not_of('/', pos); + + if (pos == std::string::npos) { + return "/"; + } + return path.substr(0, pos + 1); + } + + bool + UFileArchive::isDirectory(const std::string & path) { + #if defined(UFO_OS_UNIX) + struct stat statbuf; + if (stat(path, &statbuf) == -1) { + // FIXME: process strerror(errno)? + return false; + } + return S_ISDIR(statbuf.st_mode); + #elif defined(UFO_OS_WIN32) // !UFO_OS_UNIX + return ((GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY) != 0); + #else + return false; + #endif + } + // // c'tors *************** *** 205,215 **** bool UFileArchive::existsInArchive(const std::string & fileName) { ! std::ifstream * stream = createFileStream(fileName); ! if (*stream) { ! stream->close(); ! delete(stream); ! return true; ! } ! return false; } --- 230,234 ---- bool UFileArchive::existsInArchive(const std::string & fileName) { ! return (getAbsolutePath(fileName) != ""); } *************** *** 228,264 **** } - std::ifstream * - UFileArchive::createFileStream(const std::string & fileNameA, - std::ios_base::openmode modeA) { - std::ifstream * file = NULL; - for (std::vector<std::string>::const_iterator iter = m_archives.begin(); - iter != m_archives.end(); ++iter) { - std::string newFileName(*iter); - newFileName += '/'; - newFileName.append(fileNameA); - - file = new std::ifstream(newFileName.c_str(), modeA); - - if (file) { - if (*file) { // valid file stream - return file; - } else { // free memory - delete (file); - } - } - } - file = new std::ifstream(fileNameA.c_str(), modeA); - // This may be invalid - return file; - } - - void - UFileArchive::destroyFileStream(std::ifstream * fstream) { - if (fstream) { - fstream->close(); - delete (fstream); - } - } - // FIXME // we can't create this instance at the very beginning of the run time --- 247,250 ---- |