| 1 | #ifndef MDFN_FILE_H |
| 2 | #define MDFN_FILE_H |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | #include <boolean.h> |
| 7 | |
| 8 | #define MDFNFILE_EC_NOTFOUND 1 |
| 9 | #define MDFNFILE_EC_OTHER 2 |
| 10 | |
| 11 | class MDFNFILE |
| 12 | { |
| 13 | public: |
| 14 | |
| 15 | MDFNFILE(); |
| 16 | // WIP constructors: |
| 17 | MDFNFILE(const char *path, const void *known_ext, const char *purpose = NULL); |
| 18 | |
| 19 | ~MDFNFILE(); |
| 20 | |
| 21 | bool Open(const char *path, const void *known_ext, const char *purpose = NULL, const bool suppress_notfound_pe = false); |
| 22 | INLINE bool Open(const std::string &path, const void *known_ext, const char *purpose = NULL, const bool suppress_notfound_pe = false) |
| 23 | { |
| 24 | return(Open(path.c_str(), known_ext, purpose, suppress_notfound_pe)); |
| 25 | } |
| 26 | |
| 27 | bool Close(void); |
| 28 | |
| 29 | uint64 fread(void *ptr, size_t size, size_t nmemb); |
| 30 | int fseek(int64 offset, int whence); |
| 31 | |
| 32 | inline uint64 ftell(void) |
| 33 | { |
| 34 | return(location); |
| 35 | } |
| 36 | |
| 37 | inline void rewind(void) |
| 38 | { |
| 39 | location = 0; |
| 40 | } |
| 41 | |
| 42 | int read32le(uint32 *Bufo); |
| 43 | int read16le(uint16 *Bufo); |
| 44 | |
| 45 | inline int _fgetc(void) |
| 46 | { |
| 47 | if(location < f_size) |
| 48 | return f_data[location++]; |
| 49 | |
| 50 | return EOF; |
| 51 | } |
| 52 | |
| 53 | inline int fisarchive(void) |
| 54 | { |
| 55 | return(0); |
| 56 | } |
| 57 | |
| 58 | uint8 *f_data; |
| 59 | int64 f_size; |
| 60 | char *f_ext; |
| 61 | |
| 62 | private: |
| 63 | |
| 64 | int64 location; |
| 65 | |
| 66 | bool MakeMemWrapAndClose(void *tz); |
| 67 | }; |
| 68 | |
| 69 | class PtrLengthPair |
| 70 | { |
| 71 | public: |
| 72 | |
| 73 | inline PtrLengthPair(const void *new_data, const uint64 new_length) |
| 74 | { |
| 75 | data = new_data; |
| 76 | length = new_length; |
| 77 | } |
| 78 | |
| 79 | ~PtrLengthPair() |
| 80 | { |
| 81 | |
| 82 | } |
| 83 | |
| 84 | INLINE const void *GetData(void) const |
| 85 | { |
| 86 | return(data); |
| 87 | } |
| 88 | |
| 89 | INLINE uint64 GetLength(void) const |
| 90 | { |
| 91 | return(length); |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | const void *data; |
| 96 | uint64 length; |
| 97 | }; |
| 98 | |
| 99 | #include <vector> |
| 100 | |
| 101 | // These functions should be used for data like save states and non-volatile backup memory. |
| 102 | // Until(if, even) we add LoadFromFile functions, for reading the files these functions generate, just use gzopen(), gzread(), etc. |
| 103 | // "compress" is set to the zlib compression level. 0 disables compression entirely, and dumps the file without a gzip header or footer. |
| 104 | // (Note: There is a setting that will force compress to 0 in the internal DumpToFile logic, for hackers who don't want to ungzip save files.) |
| 105 | |
| 106 | bool MDFN_DumpToFile(const char *filename, int compress, const void *data, const uint64 length); |
| 107 | |
| 108 | #endif |