Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Loaders.h
5650 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#pragma once
19
20
#include <string>
21
#include <memory>
22
23
#include "Common/CommonTypes.h"
24
#include "Common/File/Path.h"
25
#include "Common/File/VFS/ZipFileReader.h"
26
27
enum class IdentifiedFileType {
28
ERROR_IDENTIFYING,
29
30
PSP_PBP_DIRECTORY,
31
32
PSP_PBP,
33
PSP_ELF,
34
PSP_ISO,
35
PSP_ISO_NP,
36
37
PSP_DISC_DIRECTORY,
38
39
// Try to reduce support emails...
40
ARCHIVE_RAR,
41
ARCHIVE_ZIP,
42
ARCHIVE_7Z,
43
PSP_PS1_PBP,
44
PSX_ISO,
45
PS2_ISO,
46
PS3_ISO,
47
PSP_UMD_VIDEO_ISO,
48
49
UNKNOWN_BIN,
50
UNKNOWN_ELF,
51
UNKNOWN_ISO,
52
53
NORMAL_DIRECTORY,
54
55
PSP_SAVEDATA_DIRECTORY,
56
PPSSPP_SAVESTATE,
57
58
PPSSPP_GE_DUMP,
59
60
UNKNOWN,
61
};
62
63
const char *IdentifiedFileTypeToString(IdentifiedFileType type);
64
65
// NB: It is a REQUIREMENT that implementations of this class are entirely thread safe!
66
// TOOD: actually, is it really?
67
class FileLoader {
68
public:
69
enum class Flags {
70
NONE,
71
// Not necessary to read from / store into cache.
72
HINT_UNCACHED,
73
};
74
75
virtual ~FileLoader() {}
76
77
virtual bool IsRemote() {
78
return false;
79
}
80
virtual bool Exists() = 0;
81
virtual bool ExistsFast() {
82
return Exists();
83
}
84
virtual bool IsDirectory() = 0;
85
virtual s64 FileSize() = 0;
86
virtual Path GetPath() const = 0;
87
virtual std::string GetFileExtension() const {
88
return GetPath().GetFileExtension();
89
}
90
virtual size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) = 0;
91
virtual size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) {
92
return ReadAt(absolutePos, 1, bytes, data, flags);
93
}
94
95
// Cancel any operations that might block, if possible.
96
virtual void Cancel() {}
97
98
virtual std::string LatestError() const {
99
return "";
100
}
101
};
102
103
class ProxiedFileLoader : public FileLoader {
104
public:
105
ProxiedFileLoader(FileLoader *backend) : backend_(backend) {}
106
~ProxiedFileLoader() {
107
// Takes ownership.
108
delete backend_;
109
}
110
bool IsRemote() override {
111
return backend_->IsRemote();
112
}
113
bool Exists() override {
114
return backend_->Exists();
115
}
116
bool ExistsFast() override {
117
return backend_->ExistsFast();
118
}
119
bool IsDirectory() override {
120
return backend_->IsDirectory();
121
}
122
s64 FileSize() override {
123
return backend_->FileSize();
124
}
125
Path GetPath() const override {
126
return backend_->GetPath();
127
}
128
void Cancel() override {
129
backend_->Cancel();
130
}
131
std::string LatestError() const override {
132
return backend_->LatestError();
133
}
134
size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
135
return backend_->ReadAt(absolutePos, bytes, count, data, flags);
136
}
137
size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override {
138
return backend_->ReadAt(absolutePos, bytes, data, flags);
139
}
140
FileLoader *Steal() {
141
FileLoader *backend = backend_;
142
backend_ = nullptr;
143
return backend;
144
}
145
146
protected:
147
FileLoader *backend_;
148
};
149
150
inline u32 operator & (const FileLoader::Flags &a, const FileLoader::Flags &b) {
151
return (u32)a & (u32)b;
152
}
153
154
FileLoader *ConstructFileLoader(const Path &filename);
155
// Identifies the file and resolves to the target binary, ISO, or other file (e.g. from a directory.)
156
FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader, IdentifiedFileType *fileType, std::string *errorString);
157
158
Path ResolvePBPDirectory(const Path &filename);
159
Path ResolvePBPFile(const Path &filename);
160
161
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString);
162
163
bool UmdReplace(const Path &filepath, FileLoader **fileLoader, std::string &error);
164
165
166
enum class ZipFileContents {
167
NOT_A_ZIP_FILE = 0,
168
UNKNOWN,
169
PSP_GAME_DIR,
170
ISO_FILE,
171
TEXTURE_PACK,
172
SAVE_DATA,
173
FRAME_DUMP,
174
EXTRACTED_GAME,
175
SAVE_STATES,
176
};
177
178
struct ZipFileInfo {
179
ZipFileContents contents;
180
int numFiles;
181
int stripChars; // for PSP game - how much to strip from the path.
182
int isoFileIndex; // for ISO
183
int textureIniIndex; // for textures
184
bool ignoreMetaFiles;
185
std::string gameTitle; // from PARAM.SFO if available
186
std::string savedataTitle;
187
std::string savedataDetails;
188
std::string savedataDir;
189
std::string mTime;
190
s64 totalFileSize;
191
192
std::string contentName;
193
};
194
195
ZipContainer ZipOpenPath(const Path &fileName);
196
void ZipClose(ZipContainer &z);
197
198
bool DetectZipFileContents(const Path &fileName, ZipFileInfo *info);
199
void DetectZipFileContents(zip_t *z, ZipFileInfo *info);
200
201