Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/Loaders.cpp
5673 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
#include <algorithm>
19
20
#include "Common/File/FileUtil.h"
21
#include "Common/File/Path.h"
22
#include "Common/StringUtils.h"
23
#include "Common/Data/Text/I18n.h"
24
#include "Core/FileLoaders/CachingFileLoader.h"
25
#include "Core/FileLoaders/DiskCachingFileLoader.h"
26
#include "Core/FileLoaders/HTTPFileLoader.h"
27
#include "Core/FileLoaders/LocalFileLoader.h"
28
#include "Core/FileLoaders/RetryingFileLoader.h"
29
#include "Core/FileLoaders/ZipFileLoader.h"
30
#include "Core/FileSystems/MetaFileSystem.h"
31
#include "Core/FileSystems/BlockDevices.h"
32
#include "Core/FileSystems/ISOFileSystem.h"
33
#include "Core/PSPLoaders.h"
34
#include "Core/MemMap.h"
35
#include "Core/Loaders.h"
36
#include "Core/Core.h"
37
#include "Core/System.h"
38
#include "Core/ELF/PBPReader.h"
39
#include "Core/ELF/ParamSFO.h"
40
#include "Core/Util/GameManager.h"
41
42
struct PVD {
43
u8 type;
44
char identifier[5];
45
char version;
46
char pad0;
47
char systemId[32]; // PSP GAME normally
48
char volumeId[32]; // In PSP games, this sometimes has the name of the game but far from always.
49
};
50
51
FileLoader *ConstructFileLoader(const Path &filename) {
52
if (filename.Type() == PathType::HTTP) {
53
FileLoader *baseLoader = new RetryingFileLoader(new HTTPFileLoader(filename));
54
// For headless, avoid disk caching since it's usually used for tests that might mutate.
55
if (!PSP_CoreParameter().headLess) {
56
baseLoader = new DiskCachingFileLoader(baseLoader);
57
}
58
return new CachingFileLoader(baseLoader);
59
}
60
return new LocalFileLoader(filename);
61
}
62
63
// TODO : improve, look in the file more
64
// Does not take ownership.
65
IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorString) {
66
errorString->clear();
67
if (fileLoader == nullptr) {
68
*errorString = "Invalid fileLoader";
69
return IdentifiedFileType::ERROR_IDENTIFYING;
70
}
71
if (fileLoader->GetPath().size() == 0) {
72
*errorString = "Invalid filename " + fileLoader->GetPath().ToString();
73
return IdentifiedFileType::ERROR_IDENTIFYING;
74
}
75
76
if (!fileLoader->Exists()) {
77
*errorString = "IdentifyFile: File doesn't exist: " + fileLoader->GetPath().ToString();
78
return IdentifiedFileType::ERROR_IDENTIFYING;
79
}
80
81
std::string extension = fileLoader->GetFileExtension();
82
83
bool isDiscImage = false;
84
85
if (extension == ".iso" || extension == ".cso" || extension == ".chd") {
86
isDiscImage = true;
87
} else if (extension == ".ppst") {
88
return IdentifiedFileType::PPSSPP_SAVESTATE;
89
} else if (extension == ".ppdmp") {
90
char data[8]{};
91
fileLoader->ReadAt(0, 8, data);
92
if (memcmp(data, "PPSSPPGE", 8) == 0) {
93
return IdentifiedFileType::PPSSPP_GE_DUMP;
94
}
95
}
96
97
// First, check if it's a directory with an EBOOT.PBP in it.
98
if (!isDiscImage && fileLoader->IsDirectory()) {
99
Path filename = fileLoader->GetPath();
100
if (filename.size() > 4) {
101
// Check for existence of EBOOT.PBP, as required for "Directory games".
102
if (File::Exists(filename / "EBOOT.PBP")) {
103
return IdentifiedFileType::PSP_PBP_DIRECTORY;
104
}
105
106
// check if it's a disc directory
107
if (File::Exists(filename / "PSP_GAME")) {
108
return IdentifiedFileType::PSP_DISC_DIRECTORY;
109
}
110
111
// Not that, okay, let's guess it's a savedata directory if it has a param.sfo...
112
if (File::Exists(filename / "PARAM.SFO")) {
113
return IdentifiedFileType::PSP_SAVEDATA_DIRECTORY;
114
}
115
}
116
117
return IdentifiedFileType::NORMAL_DIRECTORY;
118
}
119
120
// OK, quick methods of identification for common types failed. Moving on to more expensive methods,
121
// starting by reading the first few bytes.
122
// This can be necessary for weird Android content storage path types, see issue #17462
123
if (isDiscImage || fileLoader->FileSize() >= 0x8800) {
124
// Do the quick check for PSP ISOs here.
125
std::string bdError;
126
std::unique_ptr<BlockDevice> bd(ConstructBlockDevice(fileLoader, &bdError));
127
if (bd) {
128
u8 block16[2048]{};
129
bd->ReadBlock(16, (u8 *)block16);
130
PVD pvd;
131
memcpy(&pvd, block16, sizeof(PVD));
132
if (!memcmp(pvd.identifier, "CD001", 5)) {
133
// It's a valid DVD-style ISO file. Let's see which type.
134
if (!memcmp(pvd.systemId, "PSP GAME", 8) || !memcmp(pvd.systemId, "\"PSP GAME\"", 10)) {
135
// Yes, a known proper PSP game, let's get it going.
136
return IdentifiedFileType::PSP_ISO;
137
} else if (!memcmp(pvd.systemId, "UMD VIDEO", 9) || !memcmp(pvd.systemId, "UMD AUDIO", 9)) {
138
// This is rare so being slightly slow here shouldn't be a problem. Let's go check for the presence of
139
// actual game data.
140
SequentialHandleAllocator hAlloc;
141
ISOFileSystem umd(&hAlloc, bd.release());
142
if (umd.GetFileInfo("/PSP_GAME").exists) {
143
INFO_LOG(Log::Loader, "Found an UMD VIDEO disc with game data. Treating as game.");
144
*errorString = "UMD Video with PSP GAME data";
145
return IdentifiedFileType::PSP_ISO;
146
}
147
148
// UMD AUDIO exists technically, but in reality, not really? Let's map it to VIDEO since we support neither.
149
return IdentifiedFileType::PSP_UMD_VIDEO_ISO;
150
} else if (!memcmp(pvd.systemId, "PS3", 3)) {
151
*errorString = "PS3 ISO";
152
return IdentifiedFileType::PS3_ISO;
153
} else if (!memcmp(pvd.systemId, "PLAYSTATION", 11)) {
154
// Just do a size heuristic here to differentiate. There are better ways but slower.
155
if (bd->GetUncompressedSize() > 800LL * 1024LL * 1024LL) {
156
*errorString = "PS2 ISO";
157
return IdentifiedFileType::PS2_ISO;
158
}
159
*errorString = "PSX ISO?";
160
return IdentifiedFileType::PSX_ISO;
161
} else {
162
// Let's go check for PSP game data.
163
SequentialHandleAllocator hAlloc;
164
ISOFileSystem umd(&hAlloc, bd.release());
165
if (umd.GetFileInfo("/PSP_GAME").exists) {
166
INFO_LOG(Log::Loader, "PSP ISO with unknown system ID: %.32s: %s", pvd.systemId, fileLoader->GetPath().c_str());
167
return IdentifiedFileType::PSP_ISO;
168
}
169
170
INFO_LOG(Log::Loader, "Unknown ISO with unknown system ID: %.32s: %s", pvd.systemId, fileLoader->GetPath().c_str());
171
*errorString = StringFromFormat("ISO with unknown system ID: %.32s", pvd.systemId);
172
return IdentifiedFileType::UNKNOWN_ISO;
173
}
174
}
175
176
// Do extra check for PSX ISO
177
// may be a psx iso, they have 2352 byte sectors. You never know what some people try to open
178
if ((fileLoader->FileSize() % 2352) == 0) {
179
unsigned char sync[12];
180
fileLoader->ReadAt(0, 12, sync);
181
182
// each sector in a mode2 image starts with these 12 bytes
183
if (memcmp(sync, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00", 12) == 0) {
184
*errorString = "ISO is a CD - likely PSX"; // Mode 2 CDs are used for PSX games
185
return IdentifiedFileType::PSX_ISO;
186
}
187
}
188
}
189
190
if (isDiscImage) {
191
if (!bdError.empty()) {
192
*errorString = bdError;
193
} else {
194
auto sy = GetI18NCategory(I18NCat::SYSTEM);
195
*errorString = sy->T("Not a PSP game");
196
}
197
return IdentifiedFileType::UNKNOWN_ISO;
198
}
199
}
200
201
u32 id;
202
203
size_t readSize = fileLoader->ReadAt(0, 4, 1, &id);
204
if (readSize != 1) {
205
*errorString = "Failed to read identification bytes";
206
return IdentifiedFileType::ERROR_IDENTIFYING;
207
}
208
209
u32_le psar_offset = 0, psar_id = 0;
210
if (!memcmp(&id, "PK\x03\x04", 4) || !memcmp(&id, "PK\x05\x06", 4) || !memcmp(&id, "PK\x07\x08", 4)) {
211
return IdentifiedFileType::ARCHIVE_ZIP;
212
} else if (!memcmp(&id, "\x00PBP", 4)) {
213
fileLoader->ReadAt(0x24, 4, 1, &psar_offset);
214
fileLoader->ReadAt(psar_offset, 4, 1, &psar_id);
215
// Fall through to the below if chain.
216
} else if (!memcmp(&id, "Rar!", 4)) {
217
return IdentifiedFileType::ARCHIVE_RAR;
218
} else if (!memcmp(&id, "\x37\x7A\xBC\xAF", 4)) {
219
return IdentifiedFileType::ARCHIVE_7Z;
220
}
221
222
if (id == 'FLE\x7F') {
223
Path filename = fileLoader->GetPath();
224
// There are a few elfs misnamed as pbp (like Trig Wars), accept that. Also accept extension-less paths.
225
if (extension == ".plf" || strstr(filename.GetFilename().c_str(), "BOOT.BIN") ||
226
extension == ".elf" || extension == ".prx" || extension == ".pbp" || extension == "") {
227
return IdentifiedFileType::PSP_ELF;
228
}
229
return IdentifiedFileType::UNKNOWN_ELF;
230
} else if (id == 'PBP\x00') {
231
// Do this PS1 eboot check FIRST before checking other eboot types.
232
// It seems like some are malformed and slip through the PSAR check below.
233
PBPReader pbp(fileLoader);
234
if (pbp.IsValid() && !pbp.IsELF()) {
235
std::vector<u8> sfoData;
236
if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
237
ParamSFOData paramSFO;
238
paramSFO.ReadSFO(sfoData);
239
// PS1 Eboots are supposed to use "ME" as their PARAM SFO category.
240
// If they don't, and they're still malformed (e.g. PSISOIMG0000 isn't found), there's nothing we can do.
241
if (paramSFO.GetValueString("CATEGORY") == "ME")
242
return IdentifiedFileType::PSP_PS1_PBP;
243
}
244
}
245
246
if (psar_id == 'MUPN') {
247
return IdentifiedFileType::PSP_ISO_NP;
248
}
249
// PS1 PSAR begins with "PSISOIMG0000"
250
if (psar_id == 'SISP') {
251
return IdentifiedFileType::PSP_PS1_PBP;
252
}
253
254
// Let's check if we got pointed to a PBP within such a directory.
255
// If so we just move up and return the directory itself as the game.
256
// If loading from memstick...
257
if (fileLoader->GetPath().FilePathContainsNoCase("PSP/GAME/")) {
258
return IdentifiedFileType::PSP_PBP_DIRECTORY;
259
}
260
return IdentifiedFileType::PSP_PBP;
261
} else if (extension == ".pbp") {
262
ERROR_LOG(Log::Loader, "A PBP with the wrong magic number?");
263
return IdentifiedFileType::PSP_PBP;
264
} else if (extension == ".bin") {
265
return IdentifiedFileType::UNKNOWN_BIN;
266
} else if (extension == ".zip") {
267
return IdentifiedFileType::ARCHIVE_ZIP;
268
} else if (extension == ".rar") {
269
return IdentifiedFileType::ARCHIVE_RAR;
270
} else if (extension == ".r00") {
271
return IdentifiedFileType::ARCHIVE_RAR;
272
} else if (extension == ".r01") {
273
return IdentifiedFileType::ARCHIVE_RAR;
274
} else if (extension == ".7z") {
275
return IdentifiedFileType::ARCHIVE_7Z;
276
}
277
return IdentifiedFileType::UNKNOWN;
278
}
279
280
FileLoader *ResolveFileLoaderTarget(FileLoader *fileLoader, IdentifiedFileType *fileType, std::string *errorString) {
281
*fileType = Identify_File(fileLoader, errorString);
282
if (*fileType == IdentifiedFileType::PSP_PBP_DIRECTORY) {
283
const Path ebootFilename = ResolvePBPFile(fileLoader->GetPath());
284
if (ebootFilename != fileLoader->GetPath()) {
285
// Switch fileLoader to the actual EBOOT.
286
delete fileLoader;
287
fileLoader = ConstructFileLoader(ebootFilename);
288
// Re-identify the file.
289
*fileType = Identify_File(fileLoader, errorString);
290
}
291
} else if (*fileType == IdentifiedFileType::ARCHIVE_ZIP) {
292
// Handle zip files, take automatic action depending on contents.
293
// Can also return nullptr.
294
ZipFileLoader *zipLoader = new ZipFileLoader(fileLoader);
295
296
ZipFileInfo zipFileInfo{};
297
DetectZipFileContents(zipLoader->GetZip(), &zipFileInfo);
298
299
switch (zipFileInfo.contents) {
300
case ZipFileContents::ISO_FILE:
301
case ZipFileContents::FRAME_DUMP:
302
{
303
zipLoader->Initialize(zipFileInfo.isoFileIndex);
304
// Re-identify the file.
305
*fileType = Identify_File(zipLoader, errorString);
306
return zipLoader;
307
}
308
default:
309
{
310
// Nothing runnable in file. Take the original loader back and return it.
311
fileLoader = zipLoader->Steal();
312
delete zipLoader;
313
return fileLoader;
314
}
315
}
316
}
317
return fileLoader;
318
}
319
320
Path ResolvePBPDirectory(const Path &filename) {
321
if (filename.GetFilename() == "EBOOT.PBP") {
322
return filename.NavigateUp();
323
} else {
324
return filename;
325
}
326
}
327
328
Path ResolvePBPFile(const Path &filename) {
329
if (filename.GetFilename() != "EBOOT.PBP") {
330
return filename / "EBOOT.PBP";
331
} else {
332
return filename;
333
}
334
}
335
336
bool UmdReplace(const Path &filepath, FileLoader **fileLoader, std::string &error) {
337
IFileSystem *currentUMD = pspFileSystem.GetSystem("disc0:");
338
339
if (!currentUMD) {
340
error = "has no disc";
341
return false;
342
}
343
344
FileLoader *loadedFile = ConstructFileLoader(filepath);
345
346
if (!loadedFile || !loadedFile->Exists()) {
347
error = loadedFile ? (loadedFile->GetPath().ToVisualString() + " doesn't exist") : "no loaded file";
348
delete loadedFile;
349
return false;
350
}
351
UpdateLoadedFile(loadedFile);
352
353
std::string errorString;
354
IdentifiedFileType fileType;
355
loadedFile = ResolveFileLoaderTarget(loadedFile, &fileType, &errorString);
356
357
*fileLoader = loadedFile;
358
359
switch (fileType) {
360
case IdentifiedFileType::PSP_ISO:
361
case IdentifiedFileType::PSP_ISO_NP:
362
case IdentifiedFileType::PSP_DISC_DIRECTORY:
363
if (!MountGameISO(loadedFile, &error)) {
364
error = "mounting the replaced ISO failed: " + error;
365
return false;
366
}
367
break;
368
default:
369
error = "Unsupported file type: " + std::string(IdentifiedFileTypeToString(fileType)) + " " + errorString;
370
return false;
371
break;
372
}
373
return true;
374
}
375
376
// Close the return value with ZipClose (if non-null, of course).
377
ZipContainer ZipOpenPath(const Path &fileName) {
378
ZipContainer z(fileName);
379
if (z == nullptr) {
380
ERROR_LOG(Log::HLE, "Failed to open ZIP file '%s'", fileName.c_str());
381
}
382
return z;
383
}
384
385
void ZipClose(ZipContainer &z) {
386
z.close();
387
}
388
389
bool DetectZipFileContents(const Path &fileName, ZipFileInfo *info) {
390
ZipContainer z = ZipOpenPath(fileName);
391
if (!z) {
392
info->contents = ZipFileContents::UNKNOWN;
393
return false;
394
}
395
DetectZipFileContents(z, info);
396
return true;
397
}
398
399
static int countSlashes(const std::string &fileName, int *slashLocation) {
400
int slashCount = 0;
401
int lastSlashLocation = -1;
402
if (slashLocation) {
403
*slashLocation = -1;
404
}
405
for (size_t i = 0; i < fileName.size(); i++) {
406
if (fileName[i] == '/') {
407
slashCount++;
408
if (slashLocation) {
409
*slashLocation = lastSlashLocation;
410
lastSlashLocation = (int)i;
411
}
412
}
413
}
414
415
return slashCount;
416
}
417
418
inline char asciitolower(char in) {
419
if (in <= 'Z' && in >= 'A')
420
return in - ('Z' - 'z');
421
return in;
422
}
423
424
static bool ZipExtractFileToMemory(struct zip *z, int fileIndex, std::string *data) {
425
struct zip_stat zstat;
426
zip_stat_index(z, fileIndex, 0, &zstat);
427
if (zstat.size == 0) {
428
data->clear();
429
return true;
430
}
431
432
size_t readSize = zstat.size;
433
data->resize(readSize);
434
435
zip_file *zf = zip_fopen_index(z, fileIndex, 0);
436
if (!zf) {
437
ERROR_LOG(Log::HLE, "Failed to zip_fopen_index file %d from zip", fileIndex);
438
return false;
439
}
440
441
zip_int64_t retval = zip_fread(zf, data->data(), readSize);
442
zip_fclose(zf);
443
444
if (retval < 0 || retval < (int)readSize) {
445
ERROR_LOG(Log::HLE, "Failed to read %d bytes from zip (%d) - archive corrupt?", (int)readSize, (int)retval);
446
return false;
447
} else {
448
return true;
449
}
450
}
451
452
void DetectZipFileContents(zip_t *z, ZipFileInfo *info) {
453
int numFiles = zip_get_num_files(z);
454
_dbg_assert_(numFiles >= 0);
455
456
// Verify that this is a PSP zip file with the correct layout. We also try
457
// to detect simple zipped ISO files, those we'll just "install" to the current
458
// directory of the Games tab (where else?).
459
bool isPSPMemstickGame = false;
460
bool isZippedISO = false;
461
bool isTexturePack = false;
462
bool isSaveStates = false;
463
bool isFrameDump = false;
464
int stripChars = 0;
465
int isoFileIndex = -1;
466
int stripCharsTexturePack = -1;
467
int textureIniIndex = -1;
468
int filesInRoot = 0;
469
int directoriesInRoot = 0;
470
bool hasParamSFO = false;
471
bool isExtractedISO = false;
472
bool hasIcon0PNG = false;
473
s64 totalFileSize = 0;
474
475
// TODO: It might be cleaner to write separate detection functions, but this big loop doing it all at once
476
// is quite convenient and makes it easy to add shared heuristics.
477
for (int i = 0; i < numFiles; i++) {
478
const char *fn = zip_get_name(z, i, 0);
479
480
zip_stat_t stat{};
481
zip_stat_index(z, i, 0, &stat);
482
totalFileSize += stat.size;
483
484
std::string zippedName = fn;
485
std::transform(zippedName.begin(), zippedName.end(), zippedName.begin(),
486
[](unsigned char c) { return asciitolower(c); }); // Not using std::tolower to avoid Turkish I->ı conversion.
487
// Ignore macos metadata stuff
488
if (startsWith(zippedName, "__macosx/")) {
489
continue;
490
}
491
if (endsWith(zippedName, "/")) {
492
// A directory. Not all zips bother including these.
493
continue;
494
}
495
496
int prevSlashLocation = -1;
497
int slashCount = countSlashes(zippedName, &prevSlashLocation);
498
if (zippedName.find("eboot.pbp") != std::string::npos) {
499
if (slashCount >= 1 && (!isPSPMemstickGame || prevSlashLocation < stripChars + 1)) {
500
stripChars = prevSlashLocation + 1;
501
isPSPMemstickGame = true;
502
} else {
503
INFO_LOG(Log::HLE, "Wrong number of slashes (%i) in '%s'", slashCount, fn);
504
}
505
// TODO: Extract icon and param.sfo from the pbp to be able to display it on the install screen.
506
} else if (endsWith(zippedName, ".iso") || endsWith(zippedName, ".cso") || endsWith(zippedName, ".chd")) {
507
if (slashCount <= 1) {
508
// We only do this if the ISO file is in the root or one level down.
509
isZippedISO = true;
510
INFO_LOG(Log::HLE, "ISO found in zip: %s", zippedName.c_str());
511
if (isoFileIndex != -1) {
512
INFO_LOG(Log::HLE, "More than one ISO file found in zip. Ignoring additional ones.");
513
} else {
514
isoFileIndex = i;
515
info->contentName = zippedName;
516
}
517
}
518
} else if (zippedName.find("textures.ini") != std::string::npos) {
519
int slashLocation = (int)zippedName.find_last_of('/');
520
if (stripCharsTexturePack == -1 || slashLocation < stripCharsTexturePack + 1) {
521
stripCharsTexturePack = slashLocation + 1;
522
isTexturePack = true;
523
textureIniIndex = i;
524
}
525
} else if (endsWith(zippedName, ".ppdmp")) {
526
isFrameDump = true;
527
isoFileIndex = i;
528
info->contentName = zippedName;
529
} else if (endsWith(zippedName, ".ppst")) {
530
int slashLocation = (int)zippedName.find_last_of('/');
531
if (stripChars == 0 || slashLocation < stripChars + 1) {
532
stripChars = slashLocation + 1;
533
}
534
isSaveStates = true;
535
info->gameTitle = fn;
536
} else if (endsWith(zippedName, "psp_game/sysdir/eboot.bin") || endsWith(zippedName, "psp_game/sysdir/boot.bin")) {
537
isExtractedISO = true;
538
} else if (endsWith(zippedName, "/param.sfo")) {
539
// Get the game name so we can display it.
540
std::string paramSFOContents;
541
if (ZipExtractFileToMemory(z, i, &paramSFOContents)) {
542
ParamSFOData sfo;
543
if (sfo.ReadSFO((const u8 *)paramSFOContents.data(), paramSFOContents.size())) {
544
if (sfo.HasKey("TITLE")) {
545
info->gameTitle = sfo.GetValueString("TITLE");
546
info->savedataTitle = sfo.GetValueString("SAVEDATA_TITLE");
547
char buff[20];
548
strftime(buff, 20, "%Y-%m-%d %H:%M:%S", localtime(&stat.mtime));
549
info->mTime = buff;
550
info->savedataDetails = sfo.GetValueString("SAVEDATA_DETAIL");
551
info->savedataDir = sfo.GetValueString("SAVEDATA_DIRECTORY"); // should also be parsable from the path.
552
hasParamSFO = true;
553
}
554
}
555
}
556
} else if (endsWith(zippedName, "/icon0.png")) {
557
hasIcon0PNG = true;
558
}
559
if (slashCount == 0) {
560
filesInRoot++;
561
}
562
}
563
564
info->stripChars = stripChars;
565
info->numFiles = numFiles;
566
info->isoFileIndex = isoFileIndex;
567
info->textureIniIndex = textureIniIndex;
568
info->ignoreMetaFiles = false;
569
info->totalFileSize = totalFileSize;
570
571
// Priority ordering for detecting the various kinds of zip file content.s
572
if (isPSPMemstickGame) {
573
info->contents = ZipFileContents::PSP_GAME_DIR;
574
} else if (isZippedISO) {
575
info->contents = ZipFileContents::ISO_FILE;
576
} else if (isTexturePack) {
577
info->stripChars = stripCharsTexturePack;
578
info->ignoreMetaFiles = true;
579
info->contents = ZipFileContents::TEXTURE_PACK;
580
} else if (stripChars == 0 && filesInRoot == 0 && hasParamSFO && hasIcon0PNG && !isExtractedISO) {
581
// As downloaded from GameFAQs, for example.
582
info->contents = ZipFileContents::SAVE_DATA;
583
} else if (isFrameDump) {
584
info->contents = ZipFileContents::FRAME_DUMP;
585
} else if (isSaveStates) {
586
info->contents = ZipFileContents::SAVE_STATES;
587
} else if (isExtractedISO && hasParamSFO) {
588
info->contents = ZipFileContents::EXTRACTED_GAME;
589
} else {
590
info->contents = ZipFileContents::UNKNOWN;
591
}
592
}
593
594
const char *IdentifiedFileTypeToString(IdentifiedFileType type) {
595
switch (type) {
596
case IdentifiedFileType::ERROR_IDENTIFYING: return "ERROR_IDENTIFYING";
597
case IdentifiedFileType::PSP_PBP_DIRECTORY: return "PSP_PBP_DIRECTORY";
598
case IdentifiedFileType::PSP_PBP: return "PSP_PBP";
599
case IdentifiedFileType::PSP_ELF: return "PSP_ELF";
600
case IdentifiedFileType::PSP_ISO: return "PSP_ISO";
601
case IdentifiedFileType::PSP_ISO_NP: return "PSP_ISO_NP";
602
case IdentifiedFileType::PSP_DISC_DIRECTORY: return "PSP_DISC_DIRECTORY";
603
case IdentifiedFileType::UNKNOWN_BIN: return "UNKNOWN_BIN";
604
case IdentifiedFileType::UNKNOWN_ELF: return "UNKNOWN_ELF";
605
case IdentifiedFileType::UNKNOWN_ISO: return "UNKNOWN_ISO";
606
case IdentifiedFileType::ARCHIVE_RAR: return "ARCHIVE_RAR";
607
case IdentifiedFileType::ARCHIVE_ZIP: return "ARCHIVE_ZIP";
608
case IdentifiedFileType::ARCHIVE_7Z: return "ARCHIVE_7Z";
609
case IdentifiedFileType::PSP_PS1_PBP: return "PSP_PS1_PBP";
610
case IdentifiedFileType::PSX_ISO: return "PSX_ISO";
611
case IdentifiedFileType::PS2_ISO: return "PS2_ISO";
612
case IdentifiedFileType::PS3_ISO: return "PS3_ISO";
613
case IdentifiedFileType::PSP_UMD_VIDEO_ISO: return "UMD_VIDEO";
614
case IdentifiedFileType::NORMAL_DIRECTORY: return "NORMAL_DIRECTORY";
615
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY: return "PSP_SAVEDATA_DIRECTORY";
616
case IdentifiedFileType::PPSSPP_SAVESTATE: return "PPSSPP_SAVESTATE";
617
case IdentifiedFileType::PPSSPP_GE_DUMP: return "PPSSPP_GE_DUMP";
618
case IdentifiedFileType::UNKNOWN: return "UNKNOWN";
619
default: return "INVALID_TYPE";
620
}
621
}
622
623