00001 //--------------------------------------------------------------------------- 00002 /// \file CATFileSystem_Win32.h 00003 /// \brief File system functions for Win32 platform 00004 /// \ingroup CAT 00005 /// 00006 /// Copyright (c) 2003-2008 by Michael Ellison. 00007 /// See COPYING.txt for the \ref gaslicense License (MIT License). 00008 /// 00009 // $Author: mikeellison $ 00010 // $Date: 2008-01-21 08:33:12 -0600 (Mon, 21 Jan 2008) $ 00011 // $Revision: $ 00012 // $NoKeywords: $ 00013 00014 #ifndef CATFileSystem_Win32_H_ 00015 #define CATFileSystem_Win32_H_ 00016 00017 #include "CATInternal.h" 00018 #include "CATFileSystem.h" 00019 #include "CATPlatform.h" 00020 #include <map> 00021 00022 /// \class CATFileSystem_Win32 CATFileSystem_Win32.h 00023 /// \brief File system functions for Win32 platform 00024 /// \ingroup CAT 00025 class CATFileSystem_Win32 : public CATFileSystem 00026 { 00027 // Use CATPlatform for instantiation! 00028 friend CATPlatform; 00029 00030 public: 00031 /// Initialize must be called prior to using CATFileSystem! 00032 /// \return CATResult - CAT_SUCCESS 00033 virtual CATResult Initialize(); 00034 00035 /// FileExists should return a successful result if the file exists, 00036 /// or an error otherwise. 00037 /// 00038 /// Note: FileExists() fails if a directory of that name is present. 00039 /// 00040 /// \param pathname - path to file to check for existance. 00041 /// \return CATResult - successful result if the file is found. 00042 virtual CATResult FileExists( const CATString& pathname ); 00043 00044 /// DirExists should return a successful result if the dir exists, 00045 /// or an error otherwise. 00046 /// 00047 /// Note: DirExists() fails if a file of the specified name exists. 00048 /// 00049 /// \param pathname - path to dir to check for existance. 00050 /// \return CATResult - successful result if the file is found. 00051 virtual CATResult DirExists ( const CATString& pathname ); 00052 00053 00054 /// CreateDir creates the directory if necessary. 00055 /// 00056 /// \param pathname - path to dir to check for existance and create if not 00057 /// present. 00058 /// \return CATResult - CAT_SUCCESS if successful. 00059 virtual CATResult CreateDir ( const CATString& pathname ); 00060 00061 /// PathExists should return a successful result if a dir or a file 00062 /// of that name exists. 00063 /// 00064 /// If it is a file, returns CAT_STAT_PATH_IS_FILE. 00065 /// IF it is a dir, returns CAT_STAT_PATH_IS_DIRECTORY 00066 /// 00067 /// Note: DirExists() fails if a file of the specified name exists. 00068 /// 00069 /// \param pathname - path to dir to check for existance. 00070 /// \return CATResult - successful result if the file is found. 00071 virtual CATResult PathExists( const CATString& pathname ); 00072 00073 /// FindFirst() finds the first matching file or directory and 00074 /// returns it in firstFile. 00075 /// 00076 /// FindFirst *must* be called prior to FindNext(). You must call 00077 /// FindEnd() when done. 00078 /// 00079 /// \param searchMask - path/mask for performing searches with 00080 /// \param firstFile - ref to a string that receives the filename 00081 /// on success. 00082 /// \param findHandle - ref to handle returned on success. 00083 /// \return CATResult - CAT_STAT_PATH_IS_DIRECTORY if entry is a directory. 00084 /// CAT_STAT_PATH_IS_FILE if it's a file. 00085 /// CAT_ERR_FIND_NO_MATCHES if no matches are found. 00086 /// \sa FindNext(), FindEnd() 00087 virtual CATResult FindFirst ( const CATString& searchMask, 00088 CATString& firstFile, 00089 CATFINDHANDLE& findHandle); 00090 00091 /// FindNext() finds the next matching file or directory and 00092 /// returns it in nextFile. 00093 /// 00094 /// You should pass the findHandle returned by a previous call 00095 /// to FindFirst(). 00096 /// 00097 /// \param nextFile - ref to string to receive path of next file 00098 /// \param findHandle - handle for search. 00099 /// \return CATResult - CAT_STAT_PATH_IS_DIRECTORY if entry is a directory. 00100 /// CAT_STAT_PATH_IS_FILE if it's a file. 00101 /// CAT_ERR_FIND_END if no more files are available. 00102 /// \sa FindFirst(), FindEnd() 00103 virtual CATResult FindNext ( CATString& nextFile, 00104 CATFINDHANDLE findHandle); 00105 00106 /// FindEnd() ends a find operation and performs any necessary cleanup. 00107 /// 00108 /// The handle will be set to 0. 00109 /// 00110 /// \param findHandle - handle of find from FindFirst() 00111 /// \return CATResult - CAT_SUCCESS on success. 00112 /// \sa FindFirst(), FindNext() 00113 virtual CATResult FindEnd (CATFINDHANDLE& findHandle); 00114 00115 /// OpenFile() opens or creates a file. 00116 /// 00117 /// \param filename - path to file. 00118 /// \param mode - open mode for the file 00119 /// \param stream - ref to receive opened file stream 00120 /// \sa ReleaseStream() 00121 virtual CATResult OpenFile( const CATString& filename, 00122 CATStream::OPEN_MODE mode, 00123 CATStream*& stream); 00124 00125 /// OpenCachedFile() opens a file into a memory stream if possible. 00126 /// By default, it just routes to OpenFile, but child classes 00127 /// may override. 00128 /// 00129 /// \param filename - path to file. 00130 /// \param stream - ref to receive opened file stream 00131 /// \return CATResult - CAT_SUCCESS on success. 00132 /// \sa ReleaseStream() 00133 virtual CATResult OpenCachedFile( const CATString& filename, 00134 CATStream*& stream); 00135 00136 /// ReleaseFile() releases a stream opened with OpenFile(). 00137 /// 00138 /// \param stream - reference to stream pointer. Set to 0 when closed. 00139 /// \return CATResult - CAT_SUCCESS on success. 00140 /// \sa OpenFile() 00141 virtual CATResult ReleaseFile(CATStream*& stream); 00142 00143 /// IsFileReadOnly() returns true if the file is read-only, and false 00144 /// if not or if it doesn't exist. 00145 virtual bool IsFileReadOnly(const CATString& path); 00146 protected: 00147 // Constructor / destructor are protected. 00148 // Use CATPlatform::GetFileSystem() / Release() for creation and destruction! 00149 CATFileSystem_Win32(const CATString& basePath = ""); 00150 virtual ~CATFileSystem_Win32(); 00151 00152 std::map<CATFINDHANDLE,CATString> fFindPaths; 00153 }; 00154 00155 00156 #endif // CATFileSystem_Win32_H_ 00157 00158