cpp_photon/include/util/filesys/filesys.hpp

238 lines
6.5 KiB
C++
Raw Normal View History

2005-02-06 21:30:09 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-11-13 07:59:48 +00:00
// $Id: filesys.hpp,v 1.5 2005/11/13 07:59:48 cozman Exp $
2005-02-06 21:30:09 +00:00
2005-02-13 22:12:02 +00:00
#ifndef PHOTON_UTIL_FILESYS_FILESYS_HPP
#define PHOTON_UTIL_FILESYS_FILESYS_HPP
2005-02-06 21:30:09 +00:00
2005-02-13 22:12:02 +00:00
#include "exceptions.hpp"
2005-02-06 21:30:09 +00:00
#include "physfs.h"
#include <string>
#include <vector>
2005-03-02 08:39:03 +00:00
// Title: filesys::
2005-11-13 07:59:48 +00:00
// The util::filesys:: namespace is a group of functions all related to dealing
// with the filesystem. Photon uses PhysFS (http://physfs.icculus.org) to
// provide this functionality.
//
// The Search Path:
// The search path is an important concept in Photon, due to the nature of
// PhysFS when a file is referenced Photon attempts to resolve it by checking
// for it within the search path. By default the search path only includes
// the directory where the application resides. Nothing which is not within
// this directory or a directory within it can be accessed.
//
// It is possible to add other directories to the search path using
// <addToSearchPath>. Keep in mind that the search path is a list of
// directories which will be searched in order for any requested files.
// In other words if you wish to store your game media in a format like:
// | game/
// | bin/
// | images/
// | audio/
// | user-audio/
// |
//
// You will need to add images/ and audio/ to the search path since they
// do not reside within bin (where the game is stored). Also assuming
// users are allowed to place custom audio files within user-audio/ you must
// also add it to the path. If you wish for files within it to override
// existing audio files, it should preceed audio/ in the search path, otherwise
// it should come be placed in the search path after audio/.
2005-02-06 21:30:09 +00:00
namespace photon
{
namespace util
{
namespace filesys
{
// Group: System Directories ///////////////////////////////////////////////////
// Function: getCDDirs
// Gets a listing of the CD directories on a system (not supported on all
2005-11-13 07:59:48 +00:00
// systems) On Windows it would return something like D:/ or E:/, whereas on
// Linux it would return something like /media/cdrom0.
2005-02-06 21:30:09 +00:00
//
// Returns:
// A vector of strings containing the path to the CD directories.
std::vector<std::string> getCDDirs();
// Function: getBaseDir
2005-11-13 07:59:48 +00:00
// Get the path of the directory that the application is running in.
2005-02-06 21:30:09 +00:00
//
// Returns:
// Path to directory that application is running from.
std::string getBaseDir();
// Function: getUserDir
2005-11-13 07:59:48 +00:00
// Get the path of the directory that the OS specifies for the user's home.
// On Windows would resemble C:/Documents and Settings/User, on Linux something
// like /home/user/
2005-02-06 21:30:09 +00:00
//
// Returns:
// Path to user's home directory.
std::string getUserDir();
// Group: Search Path //////////////////////////////////////////////////////////
// Function: addToSearchPath
// Attempts to add a directory to the search path.
//
// Parameters:
// dir - Directory to add to the search path
2005-07-20 07:30:13 +00:00
// append - optional: if true, directory will be added to end of path (default)
2005-02-06 21:30:09 +00:00
// if false, directory will be added to front of path
//
// See Also:
// <removeFromSearchPath>
// <getSearchPath>
2005-07-20 07:30:13 +00:00
void addToSearchPath(const std::string& dir, bool append=true);
2005-02-06 21:30:09 +00:00
// Function: removeFromSearchPath
// Removes a directory from the search path, if it exists on the path.
//
// Parameters:
2005-11-13 07:59:48 +00:00
// dir - Directory to remove from the search path. Ignored if nonexistant.
2005-02-06 21:30:09 +00:00
//
// See Also:
// <addToSearchPath>
// <getSearchPath>
2005-02-07 01:48:50 +00:00
void removeFromSearchPath(const std::string& dir);
2005-02-06 21:30:09 +00:00
// Function: getSearchPath
// Obtain the currently configured search path.
//
// Returns:
// List of strings in search path.
//
// See Also:
// <addToSearchPath>
// <removeFromSearchPath>
std::vector<std::string> getSearchPath();
// Group: Manipulation /////////////////////////////////////////////////////////
2005-02-07 01:48:50 +00:00
// Function: setWriteDir
2005-11-13 07:59:48 +00:00
// Sets the writing directory, used by <mkdir> and <remove>. Unlike search
// path only one writable directory can be set at once.
2005-02-07 01:48:50 +00:00
//
// 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();
2005-02-06 21:30:09 +00:00
// Function: mkdir
// Attempts to create a directory.
//
// Parameters:
// dir - name of directory to create
//
// Returns:
// true iff directory was created, false if not
2005-02-07 01:48:50 +00:00
bool mkdir(const std::string& dir);
2005-02-06 21:30:09 +00:00
// Function: remove
// Attempts to remove a file or directory.
//
// Parameters:
// remove - name of file or directory to remove
//
// Returns:
// true iff file/directory was removed, false if not
2005-02-07 01:48:50 +00:00
bool remove(const std::string& item);
2005-02-06 21:30:09 +00:00
// Group: Searching ////////////////////////////////////////////////////////////
// Function: listDir
// Lists the contents of a directory.
//
// Parameters:
// dir - name of directory to get contents of
//
// Returns:
// list of strings representing items found in 'dir'
2005-02-07 01:48:50 +00:00
std::vector<std::string> listDir(const std::string& dir);
2005-02-06 21:30:09 +00:00
// Function: exists
// Checks if a file/directory exists.
//
// Parameters:
// item - file/directory to check existance of
//
// Returns:
// true iff file/directory exists, false if not
2005-02-07 01:48:50 +00:00
bool exists(const std::string& item);
2005-02-06 21:30:09 +00:00
2005-02-07 01:48:50 +00:00
// Function: isDir
2005-02-06 21:30:09 +00:00
// Checks if a name refers to a directory.
//
// Parameters:
// item - name to check
//
// Returns:
// true iff item is a directory, false if not
2005-02-07 01:48:50 +00:00
bool isDir(const std::string& item);
2005-02-06 21:30:09 +00:00
// Function: isSymbolicLink
// Checks if a name refers to a symbolic link.
//
// Parameters:
// item - name to check
//
// Returns:
// true iff item is a symbolic link, false if not
2005-02-07 01:48:50 +00:00
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);
2005-02-06 21:30:09 +00:00
// Function: getModTime
// Gets last modification time for a file.
//
// Parameters:
// item - name of item to get last modification time of
//
// Returns:
// Last modification time of a file in seconds since the epoch.
2005-02-07 01:48:50 +00:00
PHYSFS_sint64 getModTime(const std::string& item);
2005-02-06 21:30:09 +00:00
}
}
}
2005-02-13 22:12:02 +00:00
#endif //PHOTON_UTIL_FILESYS_FILESYS_HPP