fixed several issues in testing

This commit is contained in:
James Turk 2005-02-07 01:48:50 +00:00
parent a93ed25bcc
commit 70b47e9266
2 changed files with 96 additions and 56 deletions

View File

@ -5,10 +5,13 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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: // Revisions:
// $Log: filesys.h,v $ // $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 // Revision 1.1 2005/02/06 21:30:10 cozman
// PhysFS initial integration // PhysFS initial integration
// //
@ -33,22 +36,6 @@ namespace util
namespace filesys 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 /////////////////////////////////////////////////// // Group: System Directories ///////////////////////////////////////////////////
// Function: getCDDirs // Function: getCDDirs
@ -73,7 +60,6 @@ std::string getBaseDir();
// Path to user's home directory. // Path to user's home directory.
std::string getUserDir(); std::string getUserDir();
// Group: Search Path ////////////////////////////////////////////////////////// // Group: Search Path //////////////////////////////////////////////////////////
// Function: addToSearchPath // Function: addToSearchPath
@ -87,7 +73,7 @@ std::string getUserDir();
// See Also: // See Also:
// <removeFromSearchPath> // <removeFromSearchPath>
// <getSearchPath> // <getSearchPath>
void addToSearchPath(std::string dir, bool append); void addToSearchPath(const std::string& dir, bool append);
// Function: removeFromSearchPath // Function: removeFromSearchPath
// Removes a directory from the search path, if it exists on the path. // 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: // See Also:
// <addToSearchPath> // <addToSearchPath>
// <getSearchPath> // <getSearchPath>
void removeFromSearchPath(std::string dir); void removeFromSearchPath(const std::string& dir);
// Function: getSearchPath // Function: getSearchPath
// Obtain the currently configured search path. // Obtain the currently configured search path.
@ -114,6 +100,26 @@ std::vector<std::string> getSearchPath();
// Group: Manipulation ///////////////////////////////////////////////////////// // Group: Manipulation /////////////////////////////////////////////////////////
// Function: setWriteDir
// Sets the writing directory, used by <mkdir> and <remove>.
//
// Parameters:
// dir - Directory to make writeable
//
// See Also:
// <getWriteDir>
void setWriteDir(const std::string& dir);
// Function: getWriteDir
// Gets the writing directory.
//
// Returns:
// Writable directory, if set.
//
// See Also:
// <setWriteDir>
std::string getWriteDir();
// Function: mkdir // Function: mkdir
// Attempts to create a directory. // Attempts to create a directory.
// //
@ -122,7 +128,7 @@ std::vector<std::string> getSearchPath();
// //
// Returns: // Returns:
// true iff directory was created, false if not // true iff directory was created, false if not
bool mkdir(std::string dir); bool mkdir(const std::string& dir);
// Function: remove // Function: remove
// Attempts to remove a file or directory. // Attempts to remove a file or directory.
@ -132,7 +138,7 @@ bool mkdir(std::string dir);
// //
// Returns: // Returns:
// true iff file/directory was removed, false if not // true iff file/directory was removed, false if not
bool remove(std::string item); bool remove(const std::string& item);
// Group: Searching //////////////////////////////////////////////////////////// // Group: Searching ////////////////////////////////////////////////////////////
@ -144,7 +150,7 @@ bool remove(std::string item);
// //
// Returns: // Returns:
// list of strings representing items found in 'dir' // list of strings representing items found in 'dir'
std::vector<std::string> listDir(std::string dir); std::vector<std::string> listDir(const std::string& dir);
// Function: exists // Function: exists
// Checks if a file/directory exists. // Checks if a file/directory exists.
@ -154,9 +160,9 @@ std::vector<std::string> listDir(std::string dir);
// //
// Returns: // Returns:
// true iff file/directory exists, false if not // 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. // Checks if a name refers to a directory.
// //
// Parameters: // Parameters:
@ -164,7 +170,7 @@ bool exists(std::string item);
// //
// Returns: // Returns:
// true iff item is a directory, false if not // true iff item is a directory, false if not
bool isDirectory(std::string item); bool isDir(const std::string& item);
// Function: isSymbolicLink // Function: isSymbolicLink
// Checks if a name refers to a symbolic link. // Checks if a name refers to a symbolic link.
@ -174,7 +180,24 @@ bool isDirectory(std::string item);
// //
// Returns: // Returns:
// true iff item is a symbolic link, false if not // 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 // Function: getModTime
// Gets last modification time for a file. // Gets last modification time for a file.
@ -184,7 +207,7 @@ bool isSymbolicLink(std::string item);
// //
// Returns: // Returns:
// Last modification time of a file in seconds since the epoch. // Last modification time of a file in seconds since the epoch.
PHYSFS_sint64 getModTime(std::string item); PHYSFS_sint64 getModTime(const std::string& item);
} }
} }

View File

@ -5,10 +5,13 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // 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: // Revisions:
// $Log: filesys.cpp,v $ // $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 // Revision 1.1 2005/02/06 21:30:10 cozman
// PhysFS initial integration // PhysFS initial integration
// //
@ -24,16 +27,6 @@ namespace util
namespace filesys namespace filesys
{ {
std::string getDirSeparator()
{
return PHYSFS_getDirSeparator();
}
void permitSymbolicLinks(bool allow)
{
PHYSFS_permitSymbolicLinks(allow);
}
std::vector<std::string> getCDDirs() std::vector<std::string> getCDDirs()
{ {
std::vector<std::string> dirs; std::vector<std::string> dirs;
@ -66,21 +59,17 @@ std::string getUserDir()
return PHYSFS_getUserDir(); return PHYSFS_getUserDir();
} }
void addToSearchPath(std::string dir, bool append) void addToSearchPath(const std::string& dir, bool append)
{ {
//only attempt if dir exists int success = PHYSFS_addToSearchPath(dir.c_str(), append);
if(exists(dir)) if(!success)
{ {
int success = PHYSFS_addToSearchPath(dir.c_str(), append); throw APIError(std::string("addToSearchPath failed (") +
if(!success) 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) //ignore return value (useless)
PHYSFS_removeFromSearchPath(dir.c_str()); PHYSFS_removeFromSearchPath(dir.c_str());
@ -108,17 +97,35 @@ std::vector<std::string> getSearchPath()
return dirs; 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; 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; return PHYSFS_delete(item.c_str()) != 0;
} }
std::vector<std::string> listDir(std::string dir) std::vector<std::string> listDir(const std::string& dir)
{ {
std::vector<std::string> files; std::vector<std::string> files;
char** buf( PHYSFS_enumerateFiles(dir.c_str()) ); char** buf( PHYSFS_enumerateFiles(dir.c_str()) );
@ -140,22 +147,32 @@ std::vector<std::string> listDir(std::string dir)
return files; return files;
} }
bool exists(std::string item) bool exists(const std::string& item)
{ {
return PHYSFS_exists(item.c_str()) != 0; 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; 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; 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()); return PHYSFS_getLastModTime(item.c_str());
} }