1 #ifndef MDFN_FILE_H
2 #define MDFN_FILE_H
3 
4 #include <string>
5 
6 #define MDFNFILE_EC_NOTFOUND	1
7 #define MDFNFILE_EC_OTHER	2
8 
9 class MDFNFILE
10 {
11 	public:
12 
13 	MDFNFILE();
14 	// WIP constructors:
15 	MDFNFILE(const char *path, const void *known_ext, const char *purpose = NULL);
16 
17 	~MDFNFILE();
18 
19 	bool Open(const char *path, const void *known_ext, const char *purpose = NULL, const bool suppress_notfound_pe = FALSE);
20 	INLINE bool Open(const std::string &path, const void *known_ext, const char *purpose = NULL, const bool suppress_notfound_pe = FALSE)
21 	{
22 	 return(Open(path.c_str(), known_ext, purpose, suppress_notfound_pe));
23 	}
24 
25    bool ApplyIPS(void*);
26 	bool Close(void);
27 
28 	uint64 fread(void *ptr, size_t size, size_t nmemb);
29 	int fseek(int64 offset, int whence);
30 
ftell(void)31 	inline uint64 ftell(void)
32 	{
33 	 return(location);
34 	}
35 
rewind(void)36 	inline void rewind(void)
37 	{
38 	 location = 0;
39 	}
40 
41 	int read32le(uint32 *Bufo);
42 	int read16le(uint16 *Bufo);
43 
fgetc(void)44 	inline int fgetc(void)
45 	{
46 	 if(location < f_size)
47 	  return f_data[location++];
48 
49 	 return EOF;
50 	}
51 
fisarchive(void)52 	inline int fisarchive(void)
53 	{
54 	 return(0);
55 	}
56 
57 	char *fgets(char *s, int size);
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 
PtrLengthPair(const void * new_data,const uint64 new_length)73  inline PtrLengthPair(const void *new_data, const uint64 new_length)
74  {
75   data = new_data;
76   length = new_length;
77  }
78 
~PtrLengthPair()79  ~PtrLengthPair()
80  {
81 
82  }
83 
GetData(void)84  INLINE const void *GetData(void) const
85  {
86   return(data);
87  }
88 
GetLength(void)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 bool MDFN_DumpToFile(const char *filename, int compress, const std::vector<PtrLengthPair> &pearpairs);
108 
109 #endif
110