Files
parallel-gx1/Source/Core/DiscIO/ScrubbedBlob.cpp
T
LibretroAdmin c033a61899 DiscIO: pointer and size instead of spans, loops instead of STL algorithms
Names, game IDs, patch lists, LBA ranges and hash exceptions are passed
as pointer plus count. min/max/fill/copy become ternaries, memset and
memcpy; FST entries sort with an in-place heap sort, partitions with an
insertion sort. WAD content checks decrypt and hash in 2 KiB chunks
straight from the borrowed input; banner names read onto the stack.
2026-11-07 12:55:07 +01:00

72 lines
1.7 KiB
C++

// Copyright 2020 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DiscIO/ScrubbedBlob.h"
#include <cstring>
#include <memory>
#include <string>
#include <utility>
#include "Common/Align.h"
#include "DiscIO/Blob.h"
#include "DiscIO/DiscScrubber.h"
#include "DiscIO/VolumeDisc.h"
namespace DiscIO
{
ScrubbedBlob::ScrubbedBlob(std::unique_ptr<BlobReader> blob_reader, DiscScrubber scrubber)
: m_blob_reader(std::move(blob_reader)), m_scrubber(std::move(scrubber))
{
}
std::unique_ptr<ScrubbedBlob> ScrubbedBlob::Create(const std::string& path)
{
std::unique_ptr<VolumeDisc> disc = CreateDisc(path);
if (!disc)
return nullptr;
DiscScrubber scrubber;
if (!scrubber.SetupScrub(*disc))
return nullptr;
std::unique_ptr<BlobReader> blob = CreateBlobReader(path);
if (!blob)
return nullptr;
return std::unique_ptr<ScrubbedBlob>(new ScrubbedBlob(std::move(blob), std::move(scrubber)));
}
std::unique_ptr<BlobReader> ScrubbedBlob::CopyReader() const
{
return std::unique_ptr<ScrubbedBlob>(new ScrubbedBlob(m_blob_reader->CopyReader(), m_scrubber));
}
bool ScrubbedBlob::Read(u64 offset, u64 size, u8* out_ptr)
{
while (size > 0)
{
constexpr size_t CLUSTER_SIZE = DiscScrubber::CLUSTER_SIZE;
const u64 cluster_left = Common::AlignDown(offset + CLUSTER_SIZE, CLUSTER_SIZE) - offset;
const u64 bytes_to_read = cluster_left < size ? cluster_left : size;
if (m_scrubber.CanBlockBeScrubbed(offset))
{
std::memset(out_ptr, 0, bytes_to_read);
}
else
{
if (!m_blob_reader->Read(offset, bytes_to_read, out_ptr))
return false;
}
offset += bytes_to_read;
size -= bytes_to_read;
out_ptr += bytes_to_read;
}
return true;
}
} // namespace DiscIO