From 70b47e926618dd790240a912c74fa11721b155c0 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 7 Feb 2005 01:48:50 +0000 Subject: [PATCH] fixed several issues in testing --- include/util/filesys/filesys.h | 79 ++++++++++++++++++++++------------ src/util/filesys/filesys.cpp | 73 +++++++++++++++++++------------ 2 files changed, 96 insertions(+), 56 deletions(-) diff --git a/include/util/filesys/filesys.h b/include/util/filesys/filesys.h index 0d4ec63..c2360f2 100644 --- a/include/util/filesys/filesys.h +++ b/include/util/filesys/filesys.h @@ -5,10 +5,13 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: filesys.h,v 1.1 2005/02/06 21:30:10 cozman Exp $ +// $Id: filesys.h,v 1.2 2005/02/07 01:48:50 cozman Exp $ // // Revisions: // $Log: filesys.h,v $ +// Revision 1.2 2005/02/07 01:48:50 cozman +// fixed several issues in testing +// // Revision 1.1 2005/02/06 21:30:10 cozman // PhysFS initial integration // @@ -33,22 +36,6 @@ namespace util namespace filesys { -// Function: getDirSeparator -// Gets the system standard directory separator. -// (/ on unix, \\ on windows, : on MacOS) -// -// Returns: -// System directory separator. -std::string getDirSeparator(); - -// Function: permitSymbolicLinks -// Enables or disables symbolic linking. (which is off by default) -// -// Parameters: -// allow - true if you wish to enable linking, false if you wish to disable it -void permitSymbolicLinks(bool allow); - - // Group: System Directories /////////////////////////////////////////////////// // Function: getCDDirs @@ -73,7 +60,6 @@ std::string getBaseDir(); // Path to user's home directory. std::string getUserDir(); - // Group: Search Path ////////////////////////////////////////////////////////// // Function: addToSearchPath @@ -87,7 +73,7 @@ std::string getUserDir(); // See Also: // // -void addToSearchPath(std::string dir, bool append); +void addToSearchPath(const std::string& dir, bool append); // Function: removeFromSearchPath // Removes a directory from the search path, if it exists on the path. @@ -99,7 +85,7 @@ void addToSearchPath(std::string dir, bool append); // See Also: // // -void removeFromSearchPath(std::string dir); +void removeFromSearchPath(const std::string& dir); // Function: getSearchPath // Obtain the currently configured search path. @@ -114,6 +100,26 @@ std::vector getSearchPath(); // Group: Manipulation ///////////////////////////////////////////////////////// +// Function: setWriteDir +// Sets the writing directory, used by and . +// +// Parameters: +// dir - Directory to make writeable +// +// See Also: +// +void setWriteDir(const std::string& dir); + +// Function: getWriteDir +// Gets the writing directory. +// +// Returns: +// Writable directory, if set. +// +// See Also: +// +std::string getWriteDir(); + // Function: mkdir // Attempts to create a directory. // @@ -122,7 +128,7 @@ std::vector getSearchPath(); // // Returns: // true iff directory was created, false if not -bool mkdir(std::string dir); +bool mkdir(const std::string& dir); // Function: remove // Attempts to remove a file or directory. @@ -132,7 +138,7 @@ bool mkdir(std::string dir); // // Returns: // true iff file/directory was removed, false if not -bool remove(std::string item); +bool remove(const std::string& item); // Group: Searching //////////////////////////////////////////////////////////// @@ -144,7 +150,7 @@ bool remove(std::string item); // // Returns: // list of strings representing items found in 'dir' -std::vector listDir(std::string dir); +std::vector listDir(const std::string& dir); // Function: exists // Checks if a file/directory exists. @@ -154,9 +160,9 @@ std::vector listDir(std::string dir); // // Returns: // true iff file/directory exists, false if not -bool exists(std::string item); +bool exists(const std::string& item); -// Function: isDirectory +// Function: isDir // Checks if a name refers to a directory. // // Parameters: @@ -164,7 +170,7 @@ bool exists(std::string item); // // Returns: // true iff item is a directory, false if not -bool isDirectory(std::string item); +bool isDir(const std::string& item); // Function: isSymbolicLink // Checks if a name refers to a symbolic link. @@ -174,7 +180,24 @@ bool isDirectory(std::string item); // // Returns: // true iff item is a symbolic link, false if not -bool isSymbolicLink(std::string item); +bool isSymbolicLink(const std::string& item); + +// Group: Other //////////////////////////////////////////////////////////////// + +// Function: getDirSeparator +// Gets the system standard directory separator. +// (/ on unix, \\ on windows, : on MacOS) +// +// Returns: +// System directory separator. +std::string getDirSeparator(); + +// Function: permitSymbolicLinks +// Enables or disables symbolic linking. (which is off by default) +// +// Parameters: +// allow - true if you wish to enable linking, false if you wish to disable it +void permitSymbolicLinks(bool allow); // Function: getModTime // Gets last modification time for a file. @@ -184,7 +207,7 @@ bool isSymbolicLink(std::string item); // // Returns: // Last modification time of a file in seconds since the epoch. -PHYSFS_sint64 getModTime(std::string item); +PHYSFS_sint64 getModTime(const std::string& item); } } diff --git a/src/util/filesys/filesys.cpp b/src/util/filesys/filesys.cpp index c330b79..5c26c35 100644 --- a/src/util/filesys/filesys.cpp +++ b/src/util/filesys/filesys.cpp @@ -5,10 +5,13 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: filesys.cpp,v 1.1 2005/02/06 21:30:10 cozman Exp $ +// $Id: filesys.cpp,v 1.2 2005/02/07 01:48:51 cozman Exp $ // // Revisions: // $Log: filesys.cpp,v $ +// Revision 1.2 2005/02/07 01:48:51 cozman +// fixed several issues in testing +// // Revision 1.1 2005/02/06 21:30:10 cozman // PhysFS initial integration // @@ -24,16 +27,6 @@ namespace util namespace filesys { -std::string getDirSeparator() -{ - return PHYSFS_getDirSeparator(); -} - -void permitSymbolicLinks(bool allow) -{ - PHYSFS_permitSymbolicLinks(allow); -} - std::vector getCDDirs() { std::vector dirs; @@ -66,21 +59,17 @@ std::string getUserDir() return PHYSFS_getUserDir(); } -void addToSearchPath(std::string dir, bool append) +void addToSearchPath(const std::string& dir, bool append) { - //only attempt if dir exists - if(exists(dir)) + int success = PHYSFS_addToSearchPath(dir.c_str(), append); + if(!success) { - int success = PHYSFS_addToSearchPath(dir.c_str(), append); - if(!success) - { - throw APIError(std::string("addToSearchPath failed (") + - PHYSFS_getLastError() + ")"); - } + throw APIError(std::string("addToSearchPath failed (") + + PHYSFS_getLastError() + ")"); } } -void removeFromSearchPath(std::string dir) +void removeFromSearchPath(const std::string& dir) { //ignore return value (useless) PHYSFS_removeFromSearchPath(dir.c_str()); @@ -108,17 +97,35 @@ std::vector getSearchPath() return dirs; } -bool mkdir(std::string dir) +void setWriteDir(const std::string& dir) +{ + //set write dir to either NULL (disabled) or the directory passed in + if(PHYSFS_setWriteDir( dir.empty() ? 0 : dir.c_str() ) == 0) + { + throw APIError(std::string("setWriteDir failed (") + + PHYSFS_getLastError() + ")"); + } +} + +std::string getWriteDir() +{ + const char* dir = PHYSFS_getWriteDir(); + + //return name of directory or empty string if dir is null + return dir != 0 ? dir : std::string(); +} + +bool mkdir(const std::string& dir) { return PHYSFS_mkdir(dir.c_str()) != 0; } -bool remove(std::string item) +bool remove(const std::string& item) { return PHYSFS_delete(item.c_str()) != 0; } -std::vector listDir(std::string dir) +std::vector listDir(const std::string& dir) { std::vector files; char** buf( PHYSFS_enumerateFiles(dir.c_str()) ); @@ -140,22 +147,32 @@ std::vector listDir(std::string dir) return files; } -bool exists(std::string item) +bool exists(const std::string& item) { return PHYSFS_exists(item.c_str()) != 0; } -bool isDirectory(std::string item) +bool isDir(const std::string& item) { return PHYSFS_isDirectory(item.c_str()) != 0; } -bool isSymbolicLink(std::string item) +bool isSymbolicLink(const std::string& item) { return PHYSFS_isSymbolicLink(item.c_str()) != 0; } -PHYSFS_sint64 getModTime(std::string item) +std::string getDirSeparator() +{ + return PHYSFS_getDirSeparator(); +} + +void permitSymbolicLinks(bool allow) +{ + PHYSFS_permitSymbolicLinks(allow); +} + +PHYSFS_sint64 getModTime(const std::string& item) { return PHYSFS_getLastModTime(item.c_str()); }