00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __DISKFILE_H__
00027 #define __DISKFILE_H__
00028
00029
00030
00031
00032 class DiskFile
00033 {
00034 public:
00035 DiskFile(void);
00036 ~DiskFile(void);
00037
00038
00039 bool Create(string filename, u64 filesize);
00040
00041
00042 bool Write(u64 offset, const void *buffer, size_t length);
00043
00044
00045 bool Open(void);
00046 bool Open(string filename);
00047 bool Open(string filename, u64 filesize);
00048
00049
00050 #ifdef WIN32
00051 bool IsOpen(void) const {return hFile != INVALID_HANDLE_VALUE;}
00052 #else
00053 bool IsOpen(void) const {return file != 0;}
00054 #endif
00055
00056
00057 bool Read(u64 offset, void *buffer, size_t length);
00058
00059
00060 void Close(void);
00061
00062
00063 u64 FileSize(void) const {return filesize;}
00064
00065
00066 string FileName(void) const {return filename;}
00067
00068
00069 bool Exists(void) const {return exists;}
00070
00071
00072 bool Rename(void);
00073 bool Rename(string filename);
00074
00075
00076 bool Delete(void);
00077
00078 public:
00079 static string GetCanonicalPathname(string filename);
00080
00081 static void SplitFilename(string filename, string &path, string &name);
00082 static string TranslateFilename(string filename);
00083
00084 static bool FileExists(string filename);
00085 static u64 GetFileSize(string filename);
00086
00087
00088
00089 static list* FindFiles(string path, string wildcard);
00090
00091 protected:
00092 string filename;
00093 u64 filesize;
00094
00095
00096 #ifdef WIN32
00097 HANDLE hFile;
00098 #else
00099 FILE *file;
00100 #endif
00101
00102
00103 u64 offset;
00104
00105
00106 bool exists;
00107
00108 protected:
00109 #ifdef WIN32
00110 static string ErrorMessage(DWORD error);
00111 #endif
00112 };
00113
00114
00115
00116
00117 class DiskFileMap
00118 {
00119 public:
00120 DiskFileMap(void);
00121 ~DiskFileMap(void);
00122
00123 bool Insert(DiskFile *diskfile);
00124 void Remove(DiskFile *diskfile);
00125 DiskFile* Find(string filename) const;
00126
00127 protected:
00128 map diskfilemap;
00129 };
00130
00131 #endif // __DISKFILE_H__