mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Prepare for dumping NPDRM isos, use shared_ptr to manage lifetime of BlockDevice
This commit is contained in:
@@ -224,6 +224,7 @@ enum class DumpFileType {
|
||||
EBOOT = (1 << 0),
|
||||
PRX = (1 << 1),
|
||||
Atrac3 = (1 << 2),
|
||||
PBP_ISO = (1 << 3),
|
||||
};
|
||||
ENUM_CLASS_BITOPS(DumpFileType);
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ LocalFileLoader::LocalFileLoader(const Path &filename)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_LIBRETRO_VFS)
|
||||
file_ = File::OpenCFile(filename, "rb");
|
||||
if (!file_) {
|
||||
|
||||
@@ -66,8 +66,9 @@ BlockDevice *ConstructBlockDevice(FileLoader *fileLoader, std::string *errorStri
|
||||
} else if (!memcmp(buffer, "\x00PBP", 4)) {
|
||||
uint32_t psarOffset = 0;
|
||||
size = fileLoader->ReadAt(0x24, 1, 4, &psarOffset);
|
||||
if (size == 4 && psarOffset < fileLoader->FileSize())
|
||||
if (size == 4 && psarOffset < fileLoader->FileSize()) {
|
||||
device = new NPDRMDemoBlockDevice(fileLoader);
|
||||
}
|
||||
} else if (!memcmp(buffer, "MComprHD", 8)) {
|
||||
device = new CHDFileBlockDevice(fileLoader);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ struct VolDescriptor {
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
ISOFileSystem::ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice) {
|
||||
ISOFileSystem::ISOFileSystem(IHandleAllocator *_hAlloc, std::shared_ptr<BlockDevice> _blockDevice) {
|
||||
blockDevice = _blockDevice;
|
||||
hAlloc = _hAlloc;
|
||||
|
||||
@@ -173,7 +173,6 @@ ISOFileSystem::ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevic
|
||||
}
|
||||
|
||||
ISOFileSystem::~ISOFileSystem() {
|
||||
delete blockDevice;
|
||||
delete treeroot;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ bool parseLBN(const std::string &filename, u32 *sectorStart, u32 *readSize);
|
||||
|
||||
class ISOFileSystem : public IFileSystem {
|
||||
public:
|
||||
ISOFileSystem(IHandleAllocator *_hAlloc, BlockDevice *_blockDevice);
|
||||
ISOFileSystem(IHandleAllocator *_hAlloc, std::shared_ptr<BlockDevice> _blockDevice);
|
||||
~ISOFileSystem();
|
||||
|
||||
void DoState(PointerWrap &p) override;
|
||||
@@ -92,7 +92,7 @@ private:
|
||||
EntryMap entries;
|
||||
IHandleAllocator *hAlloc;
|
||||
TreeEntry *treeroot;
|
||||
BlockDevice *blockDevice;
|
||||
std::shared_ptr<BlockDevice> blockDevice;
|
||||
mutable u32 lastReadBlock_;
|
||||
|
||||
TreeEntry entireISO;
|
||||
|
||||
+3
-3
@@ -124,7 +124,7 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorStrin
|
||||
if (isDiscImage || fileLoader->FileSize() >= 0x8800) {
|
||||
// Do the quick check for PSP ISOs here.
|
||||
std::string bdError;
|
||||
std::unique_ptr<BlockDevice> bd(ConstructBlockDevice(fileLoader, &bdError));
|
||||
std::shared_ptr<BlockDevice> bd(ConstructBlockDevice(fileLoader, &bdError));
|
||||
if (bd) {
|
||||
u8 block16[2048]{};
|
||||
bd->ReadBlock(16, (u8 *)block16);
|
||||
@@ -139,7 +139,7 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorStrin
|
||||
// This is rare so being slightly slow here shouldn't be a problem. Let's go check for the presence of
|
||||
// actual game data.
|
||||
SequentialHandleAllocator hAlloc;
|
||||
ISOFileSystem umd(&hAlloc, bd.release());
|
||||
ISOFileSystem umd(&hAlloc, bd);
|
||||
if (umd.GetFileInfo("/PSP_GAME").exists) {
|
||||
INFO_LOG(Log::Loader, "Found an UMD VIDEO disc with game data. Treating as game.");
|
||||
*errorString = "UMD Video with PSP GAME data";
|
||||
@@ -162,7 +162,7 @@ IdentifiedFileType Identify_File(FileLoader *fileLoader, std::string *errorStrin
|
||||
} else {
|
||||
// Let's go check for PSP game data.
|
||||
SequentialHandleAllocator hAlloc;
|
||||
ISOFileSystem umd(&hAlloc, bd.release());
|
||||
ISOFileSystem umd(&hAlloc, bd);
|
||||
if (umd.GetFileInfo("/PSP_GAME").exists) {
|
||||
INFO_LOG(Log::Loader, "PSP ISO with unknown system ID: %.32s: %s", pvd.systemId, fileLoader->GetPath().c_str());
|
||||
return IdentifiedFileType::PSP_ISO;
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ bool MountGameISO(FileLoader *fileLoader, std::string *errorString) {
|
||||
fileSystem = std::make_shared<VirtualDiscFileSystem>(&pspFileSystem, fileLoader->GetPath());
|
||||
blockSystem = fileSystem;
|
||||
} else {
|
||||
auto bd = ConstructBlockDevice(fileLoader, errorString);
|
||||
std::shared_ptr<BlockDevice> bd(ConstructBlockDevice(fileLoader, errorString));
|
||||
if (!bd) {
|
||||
// Can only fail if the ISO is bad.
|
||||
return false;
|
||||
@@ -302,7 +302,7 @@ static Path NormalizePath(const Path &path) {
|
||||
bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string_view discId, std::string *error_string) {
|
||||
// This is really just for headless, might need tweaking later.
|
||||
if (PSP_CoreParameter().mountIsoLoader != nullptr) {
|
||||
auto bd = ConstructBlockDevice(PSP_CoreParameter().mountIsoLoader, error_string);
|
||||
std::shared_ptr<BlockDevice> bd(ConstructBlockDevice(PSP_CoreParameter().mountIsoLoader, error_string));
|
||||
if (bd) {
|
||||
auto umd2 = std::make_shared<ISOFileSystem>(&pspFileSystem, bd);
|
||||
auto blockSystem = std::make_shared<ISOBlockSystem>(umd2);
|
||||
|
||||
@@ -92,7 +92,7 @@ static std::string FormatRCheevosMD5(uint8_t digest[16]) {
|
||||
|
||||
// Consumes the blockDevice.
|
||||
// If failed, returns an empty string, otherwise a 32-character string with the hash in hex format.
|
||||
static std::string ComputePSPISOHash(BlockDevice *blockDevice) {
|
||||
static std::string ComputePSPISOHash(std::shared_ptr<BlockDevice> blockDevice) {
|
||||
md5_context md5;
|
||||
ppsspp_md5_starts(&md5);
|
||||
|
||||
@@ -1064,7 +1064,7 @@ void SetGame(const Path &path, IdentifiedFileType fileType, FileLoader *fileLoad
|
||||
// TODO: Fish the block device out of the loading process somewhere else. Though, probably easier to just do it here,
|
||||
// we need a temporary blockdevice anyway since it gets consumed by ComputePSPISOHash.
|
||||
std::string errorString;
|
||||
BlockDevice *blockDevice(ConstructBlockDevice(fileLoader, &errorString));
|
||||
std::shared_ptr<BlockDevice> blockDevice(ConstructBlockDevice(fileLoader, &errorString));
|
||||
if (!blockDevice) {
|
||||
ERROR_LOG(Log::Achievements, "Failed to construct block device for '%s' - can't identify: %s", path.c_str(), errorString.c_str());
|
||||
g_isIdentifying = false;
|
||||
@@ -1128,7 +1128,7 @@ void ChangeUMD(const Path &path, FileLoader *fileLoader) {
|
||||
}
|
||||
|
||||
std::string errorString;
|
||||
BlockDevice *blockDevice = ConstructBlockDevice(fileLoader, &errorString);
|
||||
std::shared_ptr<BlockDevice> blockDevice(ConstructBlockDevice(fileLoader, &errorString));
|
||||
if (!blockDevice) {
|
||||
ERROR_LOG(Log::Achievements, "Failed to construct block device for '%s' - can't identify: %s", path.c_str(), errorString.c_str());
|
||||
return;
|
||||
|
||||
@@ -448,7 +448,7 @@ std::string GameManager::GetPBPGameID(FileLoader *loader) const {
|
||||
std::string GameManager::GetISOGameID(FileLoader *loader) const {
|
||||
SequentialHandleAllocator handles;
|
||||
std::string errorString;
|
||||
BlockDevice *bd = ConstructBlockDevice(loader, &errorString);
|
||||
std::shared_ptr<BlockDevice> bd(ConstructBlockDevice(loader, &errorString));
|
||||
if (!bd) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -268,6 +268,7 @@ void DeveloperToolsScreen::CreateDumpFileTab(UI::LinearLayout *list) {
|
||||
list->Add(new BitCheckBox(&g_Config.iDumpFileTypes, (int)DumpFileType::EBOOT, dev->T("Dump Decrypted Eboot", "Dump Decrypted EBOOT.BIN (If Encrypted) When Booting Game")));
|
||||
list->Add(new BitCheckBox(&g_Config.iDumpFileTypes, (int)DumpFileType::PRX, dev->T("PRX")));
|
||||
list->Add(new BitCheckBox(&g_Config.iDumpFileTypes, (int)DumpFileType::Atrac3, dev->T("Atrac3/3+")));
|
||||
list->Add(new BitCheckBox(&g_Config.iDumpFileTypes, (int)DumpFileType::PBP_ISO, dev->T("ISO from PBP")));
|
||||
}
|
||||
|
||||
void DeveloperToolsScreen::CreateHLETab(UI::LinearLayout *list) {
|
||||
|
||||
@@ -813,7 +813,7 @@ handleELF:
|
||||
info_->MarkReadyNoLock(flags_);
|
||||
return;
|
||||
}
|
||||
BlockDevice *bd = ConstructBlockDevice(info_->GetFileLoader().get(), &errorString);
|
||||
std::shared_ptr<BlockDevice> bd(ConstructBlockDevice(info_->GetFileLoader().get(), &errorString));
|
||||
if (!bd) {
|
||||
ERROR_LOG(Log::Loader, "Failed constructing block device for ISO %s: %s", info_->GetFilePath().ToVisualString().c_str(), errorString.c_str());
|
||||
std::unique_lock<std::mutex> lock(info_->lock);
|
||||
|
||||
Reference in New Issue
Block a user