Skip to content

Commit

Permalink
[libromdata] Remove a few no-longer-needed IRpFilePtr to IDiscReaderP…
Browse files Browse the repository at this point in the history
…tr conversions.

XDVDFSPartition and IsoPartition now take IRpFilePtr instead of
IDiscReaderPtr.

IsoPartition's IDiscReaderPtr constructor was removed, and the IRpFilePtr
constructor is no longer deleted.

Tested with SA2 on Dreamcast. (Need to test Xbox discs...)

Code size difference: (64-bit Gentoo Linux, gcc-13.2.0, release build, no LTO)

   text    data     bss     dec     hex filename
2048911   70760     704 2120375  205ab7 libromdata.so.4 [before]
2048195   70760     704 2119659  2057eb libromdata.so.4
   -716       0       0    -716    -2cc Difference
  • Loading branch information
GerbilSoft committed Nov 12, 2023
1 parent 493e324 commit 860ec94
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 47 deletions.
12 changes: 2 additions & 10 deletions src/libromdata/Console/XboxDisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,7 @@ XboxDisc::XboxDisc(const IRpFilePtr &file)
}

// Open the XDVDFSPartition.
IDiscReaderPtr discReader = std::make_shared<DiscReader>(d->file);
if (!discReader->isOpen()) {
// Unable to open the discReader.
d->file.reset();
d->lockKreonDrive();
d->isKreon = false;
return;
}
d->xdvdfsPartition = std::make_shared<XDVDFSPartition>(discReader, d->xdvdfs_addr, d->file->size() - d->xdvdfs_addr);
d->xdvdfsPartition = std::make_shared<XDVDFSPartition>(d->file, d->xdvdfs_addr, d->file->size() - d->xdvdfs_addr);
if (!d->xdvdfsPartition->isOpen()) {
// Unable to open the XDVDFSPartition.
d->xdvdfsPartition.reset();
Expand All @@ -405,7 +397,7 @@ XboxDisc::XboxDisc(const IRpFilePtr &file)
if (d->discType == XboxDiscPrivate::DiscType::XGD2) {
static const off64_t xgd3_offset = XDVDFS_LBA_OFFSET_XGD3 * XDVDFS_BLOCK_SIZE;
d->xdvdfs_addr = XDVDFS_LBA_OFFSET_XGD3 * XDVDFS_BLOCK_SIZE;
d->xdvdfsPartition = std::make_shared<XDVDFSPartition>(discReader,
d->xdvdfsPartition = std::make_shared<XDVDFSPartition>(d->file,
xgd3_offset, d->file->size() - xgd3_offset);
if (d->xdvdfsPartition->isOpen()) {
// It's an XGD3.
Expand Down
14 changes: 3 additions & 11 deletions src/libromdata/disc/GdiReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ IsoPartitionPtr GdiReader::openIsoPartition(int trackNumber)
return nullptr;
}

// FIXME: IsoPartition's constructor requires an IDiscReaderPtr,
// but we don't have our own shared_ptr<> available.
// FIXME: IsoPartition's constructor requires an IDiscReaderPtr
// or IRpFilePtr, but we don't have our own shared_ptr<> available.
// Workaround: Create a PartitionFile and use that.
PartitionFilePtr isoFile = std::make_shared<PartitionFile>(this,
static_cast<off64_t>(lba_start) * 2048,
Expand All @@ -666,17 +666,9 @@ IsoPartitionPtr GdiReader::openIsoPartition(int trackNumber)
return nullptr;
}

// NOTE: IsoPartition *only* works properly with IDiscReader.
IDiscReaderPtr discReader = std::make_shared<DiscReader>(isoFile);
if (!discReader->isOpen()) {
// Unable to open the DiscReader.
return nullptr;
}

// Logical block size is 2048.
// ISO starting offset is the LBA.
// FIXME BEFORE COMMIT: Verify that this works correctly.
return std::make_shared<IsoPartition>(discReader, 0, lba_start);
return std::make_shared<IsoPartition>(isoFile, 0, lba_start);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/libromdata/disc/IsoPartition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace LibRomData {
class IsoPartitionPrivate
{
public:
IsoPartitionPrivate(IsoPartition *q,
off64_t partition_offset, int iso_start_offset);
IsoPartitionPrivate(IsoPartition *q, off64_t partition_offset, int iso_start_offset);

private:
RP_DISABLE_COPY(IsoPartitionPrivate)
Expand Down Expand Up @@ -479,13 +478,13 @@ time_t IsoPartitionPrivate::parseTimestamp(const ISO_Dir_DateTime_t *isofiletime
/** IsoPartition **/

/**
* Construct an IsoPartition with the specified IDiscReader.
* Construct an IsoPartition with the specified IDiscReader (or IRpFile).
*
* @param discReader IDiscReader
* @param discReader IDiscReader (or IRpFile)
* @param partition_offset Partition start offset.
* @param iso_start_offset ISO start offset, in blocks. (If -1, uses heuristics.)
*/
IsoPartition::IsoPartition(const IDiscReaderPtr &discReader, off64_t partition_offset, int iso_start_offset)
IsoPartition::IsoPartition(const IRpFilePtr &discReader, off64_t partition_offset, int iso_start_offset)
: super(discReader)
, d_ptr(new IsoPartitionPrivate(this, partition_offset, iso_start_offset))
{}
Expand Down
16 changes: 3 additions & 13 deletions src/libromdata/disc/IsoPartition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,13 @@ class IsoPartition final : public LibRpBase::IPartition
{
public:
/**
* Construct an IsoPartition with the specified IRpFile.
* *** EXPLICITLY DELETED ***
* Construct an IsoPartition with the specified IDiscReader (or IRpFile).
*
* @param file IRpFile
* @param discReader IDiscReader (or IRpFile)
* @param partition_offset Partition start offset.
* @param iso_start_offset ISO start offset, in blocks. (If -1, uses heuristics.)
*/
IsoPartition(const LibRpFile::IRpFilePtr &file, off64_t partition_offset, int iso_start_offset = -1) = delete;

/**
* Construct an IsoPartition with the specified IDiscReader.
*
* @param discReader IDiscReader
* @param partition_offset Partition start offset.
* @param iso_start_offset ISO start offset, in blocks. (If -1, uses heuristics.)
*/
IsoPartition(const LibRpBase::IDiscReaderPtr &discReader, off64_t partition_offset, int iso_start_offset = -1);
IsoPartition(const LibRpFile::IRpFilePtr &discReader, off64_t partition_offset, int iso_start_offset = -1);
public:
~IsoPartition() final;

Expand Down
8 changes: 4 additions & 4 deletions src/libromdata/disc/XDVDFSPartition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,11 @@ const rp::uvector<uint8_t> *XDVDFSPartitionPrivate::getDirectory(const char *pat
* NOTE: The IDiscReader *must* remain valid while this
* XDVDFSPartition is open.
*
* @param discReader IDiscReader.
* @param partition_offset Partition start offset.
* @param partition_size Partition size.
* @param discReader IDiscReader (or IRpFile)
* @param partition_offset Partition start offset
* @param partition_size Partition size
*/
XDVDFSPartition::XDVDFSPartition(const IDiscReaderPtr &discReader, off64_t partition_offset, off64_t partition_size)
XDVDFSPartition::XDVDFSPartition(const IRpFilePtr &discReader, off64_t partition_offset, off64_t partition_size)
: super(discReader)
, d_ptr(new XDVDFSPartitionPrivate(this, partition_offset, partition_size))
{ }
Expand Down
8 changes: 4 additions & 4 deletions src/libromdata/disc/XDVDFSPartition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class XDVDFSPartition final : public LibRpBase::IPartition
* NOTE: The IDiscReader *must* remain valid while this
* XDVDFSPartition is open.
*
* @param discReader IDiscReader.
* @param partition_offset Partition start offset.
* @param partition_size Partition size.
* @param discReader IDiscReader (or IRpFile)
* @param partition_offset Partition start offset
* @param partition_size Partition size
*/
XDVDFSPartition(const LibRpBase::IDiscReaderPtr &discReader, off64_t partition_offset, off64_t partition_size);
XDVDFSPartition(const LibRpFile::IRpFilePtr &discReader, off64_t partition_offset, off64_t partition_size);
public:
~XDVDFSPartition() final;

Expand Down

0 comments on commit 860ec94

Please sign in to comment.