Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/psx/octoshock/file.h
2 views
1
#pragma once
2
3
#include <string>
4
5
class Stream;
6
7
#define MDFNFILE_EC_NOTFOUND 1
8
#define MDFNFILE_EC_OTHER 2
9
10
class MDFNFILE
11
{
12
public:
13
14
MDFNFILE(const char *path, const void *known_ext, const char *purpose = NULL);
15
~MDFNFILE();
16
17
void ApplyIPS(Stream *);
18
void Close(void) throw();
19
20
const int64 &size;
21
const uint8 * const &data;
22
const char * const &ext;
23
const char * const &fbase;
24
25
inline int64 Size(void)
26
{
27
return(f_size);
28
}
29
30
inline const uint8 *Data(void)
31
{
32
return(f_data);
33
}
34
35
uint64 fread(void *ptr, size_t size, size_t nmemb);
36
int fseek(int64 offset, int whence);
37
38
inline uint64 ftell(void)
39
{
40
return(location);
41
}
42
43
inline void rewind(void)
44
{
45
location = 0;
46
}
47
48
int read32le(uint32 *Bufo);
49
int read16le(uint16 *Bufo);
50
51
inline int fgetc(void)
52
{
53
if(location < f_size)
54
return f_data[location++];
55
56
return EOF;
57
}
58
59
inline int fisarchive(void)
60
{
61
return(0);
62
}
63
64
char *fgets(char *s, int size);
65
66
private:
67
68
uint8 *f_data;
69
int64 f_size;
70
char *f_ext;
71
char *f_fbase;
72
73
int64 location;
74
75
#ifdef HAVE_MMAP
76
bool is_mmap;
77
#endif
78
79
void Open(const char *path, const void *known_ext, const char *purpose = NULL);
80
void MakeMemWrap(void *tz, int type);
81
};
82
83
class PtrLengthPair
84
{
85
public:
86
87
inline PtrLengthPair(const void *new_data, const uint64 new_length)
88
{
89
data = new_data;
90
length = new_length;
91
}
92
93
~PtrLengthPair()
94
{
95
96
}
97
98
INLINE const void *GetData(void) const
99
{
100
return(data);
101
}
102
103
INLINE uint64 GetLength(void) const
104
{
105
return(length);
106
}
107
108
private:
109
const void *data;
110
uint64 length;
111
};
112
113
#include <vector>
114
115
// These functions should be used for data like save states and non-volatile backup memory.
116
// Until(if, even) we add LoadFromFile functions, for reading the files these functions generate, just use gzopen(), gzread(), etc.
117
// "compress" is set to the zlib compression level. 0 disables compression entirely, and dumps the file without a gzip header or footer.
118
// (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.)
119
120
bool MDFN_DumpToFile(const char *filename, int compress, const void *data, const uint64 length);
121
bool MDFN_DumpToFile(const char *filename, int compress, const std::vector<PtrLengthPair> &pearpairs);
122
123
124