Skip to content

Commit

Permalink
Use OpenCFile, for future Android compatibility for chd
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Sep 29, 2023
1 parent ade6417 commit 64d92c9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Core/FileSystems/BlockDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ BlockDevice *constructBlockDevice(FileLoader *fileLoader) {
return new NPDRMDemoBlockDevice(fileLoader);
} else if (!memcmp(buffer, "MComprHD", 8)) {
return new CHDFileBlockDevice(fileLoader);
} else {
// Should be jsut a regular ISO.
return new FileBlockDevice(fileLoader);
}

// Should be just a regular ISO. Let's open it as a plain block device and let the other systems take over.
return new FileBlockDevice(fileLoader);
}

u32 BlockDevice::CalculateCRC(volatile bool *cancel) {
Expand Down Expand Up @@ -600,15 +600,25 @@ CHDFileBlockDevice::CHDFileBlockDevice(FileLoader *fileLoader)

chd_file *parent = NULL;
chd_file *child = NULL;
err = chd_open(paths[depth].c_str(), CHD_OPEN_READ, NULL, &child);

FILE *file = File::OpenCFile(paths[depth], "rb");
if (!file) {
ERROR_LOG(LOADER, "Error opening CHD file '%s'", paths[depth].c_str());
NotifyReadError();
return;
}
err = chd_open_file(file, CHD_OPEN_READ, NULL, &child);
if (err != CHDERR_NONE) {
ERROR_LOG(LOADER, "Error loading CHD '%s': %s", paths[depth].c_str(), chd_error_string(err));
NotifyReadError();
return;
}

// We won't enter this loop until we enable the parent/child stuff above.
for (int d = depth - 1; d >= 0; d--) {
parent = child;
child = NULL;
// TODO: Use chd_open_file
err = chd_open(paths[d].c_str(), CHD_OPEN_READ, parent, &child);
if (err != CHDERR_NONE) {
ERROR_LOG(LOADER, "Error loading CHD '%s': %s", paths[d].c_str(), chd_error_string(err));
Expand Down

0 comments on commit 64d92c9

Please sign in to comment.