Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# deFileSystem.hpp

Go to the documentation of this file.

    00001 ///////////////////////////////////////////////////////////////////////////////
    00002 /// @file deFileSystem.hpp
    00003 ///
    00004 /// @brief base file system interface header
    00005 ///
    00006 /// @author Lightning
    00007 ///
    00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
    00009 /// contents of this file is subject to the Destiny3D Member License which
    00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
    00011 ///
    00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
    00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
    00014 /// for any particular purpose.
    00015 ///
    00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
    00017 ///
    00018 /// <hr>
    00019 ///                                 Change History
    00020 /// <hr>
    00021 ///
    00022 /// @date Nov 2001
    00023 /// @author Lightning
    00024 /// @remarks Creation
    00025 ///
    00026 /// @date Dec 2002
    00027 /// @author kurifu
    00028 /// @remarks File finding handles
    00029 ///
    00030 ///////////////////////////////////////////////////////////////////////////////
    00031
    00032 #ifndef DE_FILESYSTEM_HPP
    00033 #define DE_FILESYSTEM_HPP
    00034
    00035 #include "deGlobalTypes.hpp"
    00036
    00037 #if defined(DEFILE_DLL_EXPORTS) || defined(DESTINY3D_EXPORT_ALL)
    00038 #   define DEFILESYSTEM_API extern "C" DEDLL_EXPORT
    00039 #elif defined(DESTINY3D_STATIC_LINK)
    00040 #   define DEFILESYSTEM_API extern "C"
    00041 #else
    00042 #   define DEFILESYSTEM_API extern "C" DEDLL_IMPORT
    00043 #endif
    00044
    00045 #ifdef USING_DESTINY3D
    00046 #ifdef _DEBUG
    00047 #   ifdef DESTINY3D_STATIC_LINK
    00048 #       pragma comment(lib, "deFile_sd")
    00049 #   else
    00050 #       pragma comment(lib, "deFiled")
    00051 #   endif //DESTINY3D_STATIC_LINK
    00052 #else
    00053 #   ifdef DESTINY3D_STATIC_LINK
    00054 #       pragma comment(lib, "deFile_s")
    00055 #   else
    00056 #       pragma comment(lib, "deFile")
    00057 #   endif //DESTINY3D_STATIC_LINK
    00058 #endif //_DEBUG
    00059 #endif //USING_DESTINY3D
    00060
    00061
    00062 //-------------------------------------------
    00063 // Classes Declared
    00064 //-------------------------------------------
    00065 class IdeFileSystem;
    00066 class IdeFSReal;
    00067 class IdeFSVirtual;
    00068 class IdeFile;
    00069 struct deFileProperties;
    00070
    00071 class IdeFile;
    00072 struct deFileProperties;
    00073
    00074 //-------------------------------------------
    00075 // Factory functions
    00076 //-------------------------------------------
    00077 extern "C"
    00078 {
    00079     /// create a "real" filesystem - one that's disk-based through the operating system
    00080     DEFILESYSTEM_API IdeFSReal*     IdeFileSystem_CreateFSReal();
    00081     /// create a "virtual" filesystem - one that exists within another file
    00082     DEFILESYSTEM_API IdeFSVirtual*  IdeFileSystem_CreateFSVirtual();
    00083 }
    00084
    00085 //-------------------------------------------
    00086 // Defines
    00087 //-------------------------------------------
    00088
    00089 // get rid of the annoying diamond-inheritance warning
    00090 #pragma warning (disable : 4250)
    00091
    00092 //a callback procedure used during move or copying of files to tell of the status
    00093 typedef DWORD (*deFSPROGRESS)(s64 BytesCopied, s64 FileSize, DWORD FileStatus, const char *SourceFile, const char *DestinationFile);
    00094
    00095 //possible return values of the callback
    00096 #define deFSPROGRESS_CONTINUE       0x00000001  //continue the operation in question
    00097
    00098 #define deFSPROGRESS_CANCEL         0x00000002  //cancel the operation that is happening. If a file is moved, it is erased
    00099                                                 //if a file is copied, the destination file is removed
    00100
    00101 #define deFSPROGRESS_CANCELCURRENT  0x00000004  //cancel just the current file operation, continue on to the next file. Valid
    00102                                                 //on any command. Current file is handled as if Cancel is passed
    00103
    00104 #define deFSPROGRESS_QUIET          0x00000010  //stop sending messages
    00105
    00106 //possible values for the file status in the callback
    00107 #define deFSCALLBACK_FINISHED       0x00000001  //finished the operation on the specified file
    00108
    00109 #define deFSCALLBACK_ERROREXISTS    0x00000002  //error occurred due to an existing file or directory. Continue operation or Cancel?
    00110                                                 //cancel will stop the operation completely. Continue will skip the file/directory
    00111
    00112 #define deFSCALLBACK_ERROROPENED    0x00000003  //error occurred due to the specified file currently being opened. Continue operation?
    00113                                                 //cancel will stop the operation completely. Continue will skip the file/directory
    00114
    00115 #define deFSCALLBACK_ERRORFATAL     0x00000004  //a fatal error during the operation (probably memory related). The operation WILL be
    00116                                                 //canceled. It is possible for SourceFile and DestinationFile to be null
    00117
    00118 #define deFSCALLBACK_STARTING       0x00000005  //returned each time a new file has an operation started on it
    00119
    00120 #define deFSCALLBACK_BLOCKMOVED     0x00000006  //a block of data was moved. If Cancel is returned, the resulting file is removed.
    00121                                                 //if during a move operation, the current file is deleted and no more files are moved.
    00122
    00123 #define deFSCALLBACK_RECURSE        0x00000007  //should the sub directory be recursed into during a copy? Cancel stops
    00124                                                 //recursive copy, Continue allows it.
    00125
    00126 //callback returns specific to the VFS
    00127 #define deFSCALLBACK_VFSLARGEMOVE   0x00010000  //a file is done moving. the VFS is being shifted to cover the file's original spot
    00128                                                 //FileSize and BytesCopied will represent the total number of bytes and bytes left
    00129                                                 //to move in the VFS
    00130
    00131 //-------------------------------------------
    00132 // Structures
    00133 //-------------------------------------------
    00134
    00135 typedef void* deFSFindHandle;
    00136
    00137 //-------------------------------------------
    00138 // Classes
    00139 //-------------------------------------------
    00140
    00141 /// base interface class for all filesystems.
    00142 //class IdeFileSystem : virtual public IdeRefCountBase
    00143 DE3D_INTERFACE(IdeFileSystem, IdeRefCountBase)
    00144 {
    00145     public:
    00146
    00147     protected:
    00148         virtual ~IdeFileSystem() {}
    00149     public:
    00150         ///Possible interfaces for the filesystem
    00151         enum interface_t
    00152         {
    00153             iface_IdeFileSystem = 0,
    00154             iface_IdeFSReal,        ///Real files
    00155             iface_IdeFSMemory,      ///Files stored in memory
    00156             iface_IdeFSVirtual,     ///Virtual File System
    00157             iface_force_32bit = 0x7FFFFFFF
    00158         };
    00159         ///Function to obtain the proper interface for the filesystem
    00160         ///@param[in] i Input for the type of interface to return
    00161         ///@return Returns a pointer to the requested interface or NULL if an invalid interface
    00162         virtual void* GetInterface(IdeFileSystem::interface_t i) = 0;
    00163
    00164         ///Open a file
    00165         ///@param[in] Filename Filename to open
    00166         ///@param[in] OpenFlags flags for opening the filesystem
    00167         ///@arg deFile_Open_Create Create a file, fail if it exists
    00168         ///@arg deFile_Open_Existing Open an existing file, fail it if does not exist
    00169         ///@arg deFile_Open_Always Always open the file, create if it does not exist or open existing
    00170         ///@arg deFile_Open_CreateAlways Always open the file, override if the file already exists
    00171         ///@return Return a pointer to an IdeFile class if valid
    00172         virtual IdeFile* Open(const char *Filename, long OpenFlags) = 0;
    00173
    00174         ///Get the current directoriy
    00175         virtual const char *GetDirectory() = 0;
    00176         ///Set the current directory
    00177         virtual deBoolean SetDirectory(const char *Directory) = 0;
    00178
    00179         ///Rename a file
    00180         ///@param[in] OldFilename Original file to rename
    00181         ///@param[in] NewFilename New name for the file
    00182         ///@return True/False if the rename was successful
    00183         virtual deBoolean Rename(const char *OldFilename, const char *NewFilename) = 0;
    00184
    00185         ///Delete a file
    00186         ///@param[in] Filename File to Delete
    00187         ///@param[in] StatusCallback Pointer to a function to call while deleting, pass a NULL for no callbacks
    00188         ///@return True/False if the delete was successful
    00189         virtual deBoolean Delete(const char *Filename, deFSPROGRESS StatusCallback) = 0;
    00190
    00191         ///Move a file
    00192         ///@param[in] Filename File to move
    00193         ///@param[in] StatusCallback Pointer to a function to call while moving, pass a NULL for no callbacks
    00194         ///@return True/False if the move was successful
    00195         virtual deBoolean Move(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback) = 0;
    00196
    00197         ///Copy a file
    00198         ///@param[in] Filename File to copy
    00199         ///@param[in] StatusCallback Pointer to a function to call while copying, pass a NULL for no callbacks
    00200         ///@return True/False if the copy was successful
    00201         virtual deBoolean Copy(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback) = 0;
    00202
    00203         ///Create a directory
    00204         ///@param[in] Directory The name of the directory
    00205         virtual deBoolean AddDirectory(const char *Directory) = 0;
    00206
    00207         ///Delete a directory
    00208         ///@param[in] Name of the directory to delete
    00209         ///@param[in] StatusCallback Pointer to a function to call while deleting, pass a NULL for no callbacks
    00210         ///@return True/False if the delete was successful
    00211         virtual deBoolean DeleteDirectory(const char *Directory, deFSPROGRESS StatusCallback) = 0;
    00212
    00213         ///Start a find on the filesystem
    00214         ///@param[in] Pattern Pattern to match the files to. ? to match 1 character, * for multiple character matching
    00215         ///@param[out] Properties Information about the first file found that matches
    00216         ///@return A value used to identify the find for later finds
    00217         virtual void* FindFirst(const char *Pattern, deFileProperties *Properties) = 0;
    00218
    00219         ///Find the next file in the list that matches
    00220         ///@param[in] Handle Value returned by FindFirst
    00221         ///@param[out] Properties Information about the file found that matches
    00222         ///@return True if a file was found, False if no more files exist
    00223         virtual deBoolean FindNext(void* Handle, deFileProperties *Properties) = 0;
    00224
    00225         ///Finish a find and cleanup any memory usage
    00226         ///@param[in] Handle Find to finish
    00227         ///@return True if the find is done, False if there was a problem
    00228         virtual deBoolean FindEnd(void* Handle) = 0;
    00229
    00230 };
    00231
    00232 /// class for the real FS.
    00233 /// Related functions: IdeFileSystem_CreateFSReal.
    00234 /// Related classes: IdeFileReal
    00235 //class IdeFSReal : virtual public IdeFileSystem
    00236 DE3D_INTERFACE(IdeFSReal, IdeFileSystem)
    00237 {
    00238     protected:
    00239         ~IdeFSReal() {}
    00240 };
    00241
    00242 /// class for the virtual fs.
    00243 /// Related functions: IdeFileSystem_CreateFSVirtual.
    00244 /// Related classes: IdeFileVirtual.
    00245 //class IdeFSVirtual : virtual public IdeFileSystem
    00246 DE3D_INTERFACE(IdeFSVirtual, IdeFileSystem)
    00247 {
    00248     protected:
    00249         ~IdeFSVirtual() {}
    00250
    00251     public:
    00252
    00253         //functions to open/close the base file
    00254         virtual deBoolean OpenBaseFile(IdeFile *BaseFile, long OpenFlags) = 0;
    00255         virtual deBoolean OpenBaseFilename(const char *Filename, long OpenFlags) = 0;
    00256         virtual deBoolean CloseBaseFile() = 0;
    00257 };
    00258
    00259
    00260
    00261 #endif