DiscIO: Use std::string_view in FileSystem::FindFileInfo
...and in the functions that call it.
This commit is contained in:
parent
5fb56505b2
commit
d4b069f458
|
@ -13,6 +13,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -618,9 +619,9 @@ private:
|
|||
static_assert(sizeof(Entry) == 512, "Wrong size");
|
||||
#pragma pack(pop)
|
||||
|
||||
UpdateResult UpdateFromManifest(const std::string& manifest_name);
|
||||
UpdateResult UpdateFromManifest(std::string_view manifest_name);
|
||||
UpdateResult ProcessEntry(u32 type, std::bitset<32> attrs, const TitleInfo& title,
|
||||
const std::string& path);
|
||||
std::string_view path);
|
||||
|
||||
UpdateCallback m_update_callback;
|
||||
std::unique_ptr<DiscIO::Volume> m_volume;
|
||||
|
@ -655,7 +656,7 @@ UpdateResult DiscSystemUpdater::DoDiscUpdate()
|
|||
return UpdateFromManifest("__update.inf");
|
||||
}
|
||||
|
||||
UpdateResult DiscSystemUpdater::UpdateFromManifest(const std::string& manifest_name)
|
||||
UpdateResult DiscSystemUpdater::UpdateFromManifest(std::string_view manifest_name)
|
||||
{
|
||||
const DiscIO::FileSystem* disc_fs = m_volume->GetFileSystem(m_partition);
|
||||
if (!disc_fs)
|
||||
|
@ -693,7 +694,7 @@ UpdateResult DiscSystemUpdater::UpdateFromManifest(const std::string& manifest_n
|
|||
const u64 title_id = Common::swap64(entry.data() + offsetof(Entry, title_id));
|
||||
const u16 title_version = Common::swap16(entry.data() + offsetof(Entry, title_version));
|
||||
const char* path_pointer = reinterpret_cast<const char*>(entry.data() + offsetof(Entry, path));
|
||||
const std::string path{path_pointer, strnlen(path_pointer, sizeof(Entry::path))};
|
||||
const std::string_view path{path_pointer, strnlen(path_pointer, sizeof(Entry::path))};
|
||||
|
||||
if (!m_update_callback(i, num_entries, title_id))
|
||||
return UpdateResult::Cancelled;
|
||||
|
@ -712,7 +713,7 @@ UpdateResult DiscSystemUpdater::UpdateFromManifest(const std::string& manifest_n
|
|||
}
|
||||
|
||||
UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs,
|
||||
const TitleInfo& title, const std::string& path)
|
||||
const TitleInfo& title, std::string_view path)
|
||||
{
|
||||
// Skip any unknown type and boot2 updates (for now).
|
||||
if (type != 2 && type != 3 && type != 6 && type != 7)
|
||||
|
@ -734,7 +735,7 @@ UpdateResult DiscSystemUpdater::ProcessEntry(u32 type, std::bitset<32> attrs,
|
|||
auto blob = DiscIO::VolumeFileBlobReader::Create(*m_volume, m_partition, path);
|
||||
if (!blob)
|
||||
{
|
||||
ERROR_LOG(CORE, "Could not find %s", path.c_str());
|
||||
ERROR_LOG(CORE, "Could not find %s", std::string(path).c_str());
|
||||
return UpdateResult::DiscReadFailed;
|
||||
}
|
||||
const DiscIO::WiiWAD wad{std::move(blob)};
|
||||
|
|
|
@ -69,7 +69,7 @@ u64 ReadFile(const Volume& volume, const Partition& partition, const FileInfo* f
|
|||
return read_length;
|
||||
}
|
||||
|
||||
u64 ReadFile(const Volume& volume, const Partition& partition, const std::string& path, u8* buffer,
|
||||
u64 ReadFile(const Volume& volume, const Partition& partition, std::string_view path, u8* buffer,
|
||||
u64 max_buffer_size, u64 offset_in_file)
|
||||
{
|
||||
const FileSystem* file_system = volume.GetFileSystem(partition);
|
||||
|
@ -117,7 +117,7 @@ bool ExportFile(const Volume& volume, const Partition& partition, const FileInfo
|
|||
export_filename);
|
||||
}
|
||||
|
||||
bool ExportFile(const Volume& volume, const Partition& partition, const std::string& path,
|
||||
bool ExportFile(const Volume& volume, const Partition& partition, std::string_view path,
|
||||
const std::string& export_filename)
|
||||
{
|
||||
const FileSystem* file_system = volume.GetFileSystem(partition);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
||||
|
@ -24,13 +26,13 @@ std::string NameForPartitionType(u32 partition_type, bool include_prefix);
|
|||
|
||||
u64 ReadFile(const Volume& volume, const Partition& partition, const FileInfo* file_info,
|
||||
u8* buffer, u64 max_buffer_size, u64 offset_in_file = 0);
|
||||
u64 ReadFile(const Volume& volume, const Partition& partition, const std::string& path, u8* buffer,
|
||||
u64 ReadFile(const Volume& volume, const Partition& partition, std::string_view path, u8* buffer,
|
||||
u64 max_buffer_size, u64 offset_in_file = 0);
|
||||
bool ExportData(const Volume& volume, const Partition& partition, u64 offset, u64 size,
|
||||
const std::string& export_filename);
|
||||
bool ExportFile(const Volume& volume, const Partition& partition, const FileInfo* file_info,
|
||||
const std::string& export_filename);
|
||||
bool ExportFile(const Volume& volume, const Partition& partition, const std::string& path,
|
||||
bool ExportFile(const Volume& volume, const Partition& partition, std::string_view path,
|
||||
const std::string& export_filename);
|
||||
|
||||
// update_progress is called once for each child (file or directory).
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonFuncs.h"
|
||||
|
@ -257,7 +258,7 @@ const FileInfo& FileSystemGCWii::GetRoot() const
|
|||
return m_root;
|
||||
}
|
||||
|
||||
std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(const std::string& path) const
|
||||
std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(std::string_view path) const
|
||||
{
|
||||
if (!IsValid())
|
||||
return nullptr;
|
||||
|
@ -265,7 +266,7 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(const std::string& path)
|
|||
return FindFileInfo(path, m_root);
|
||||
}
|
||||
|
||||
std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(const std::string& path,
|
||||
std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(std::string_view path,
|
||||
const FileInfo& file_info) const
|
||||
{
|
||||
// Given a path like "directory1/directory2/fileA.bin", this function will
|
||||
|
@ -276,12 +277,17 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(const std::string& path,
|
|||
return file_info.clone(); // We're done
|
||||
|
||||
const size_t name_end = path.find('/', name_start);
|
||||
const std::string name = path.substr(name_start, name_end - name_start);
|
||||
const std::string rest_of_path = (name_end != std::string::npos) ? path.substr(name_end + 1) : "";
|
||||
const std::string_view name = path.substr(name_start, name_end - name_start);
|
||||
const std::string_view rest_of_path =
|
||||
(name_end != std::string::npos) ? path.substr(name_end + 1) : "";
|
||||
|
||||
for (const FileInfo& child : file_info)
|
||||
{
|
||||
if (!strcasecmp(child.GetName().c_str(), name.c_str()))
|
||||
const std::string child_name = child.GetName();
|
||||
|
||||
// We need case insensitive comparison since some games have OPENING.BNR instead of opening.bnr
|
||||
if (child_name.size() == name.size() &&
|
||||
!strncasecmp(child_name.data(), name.data(), name.size()))
|
||||
{
|
||||
// A match is found. The rest of the path is passed on to finish the search.
|
||||
std::unique_ptr<FileInfo> result = FindFileInfo(rest_of_path, child);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
@ -90,7 +91,7 @@ public:
|
|||
|
||||
bool IsValid() const override { return m_valid; }
|
||||
const FileInfo& GetRoot() const override;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const override;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(std::string_view path) const override;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const override;
|
||||
|
||||
private:
|
||||
|
@ -100,7 +101,7 @@ private:
|
|||
// Maps the end offset of files to FST indexes
|
||||
mutable std::map<u64, u32> m_offset_file_info_cache;
|
||||
|
||||
std::unique_ptr<FileInfo> FindFileInfo(const std::string& path, const FileInfo& file_info) const;
|
||||
std::unique_ptr<FileInfo> FindFileInfo(std::string_view path, const FileInfo& file_info) const;
|
||||
};
|
||||
|
||||
} // namespace DiscIO
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
|
@ -117,7 +118,7 @@ public:
|
|||
// are only valid for as long as the file system object is valid.
|
||||
virtual const FileInfo& GetRoot() const = 0;
|
||||
// Returns nullptr if not found
|
||||
virtual std::unique_ptr<FileInfo> FindFileInfo(const std::string& path) const = 0;
|
||||
virtual std::unique_ptr<FileInfo> FindFileInfo(std::string_view path) const = 0;
|
||||
// Returns nullptr if not found
|
||||
virtual std::unique_ptr<FileInfo> FindFileInfo(u64 disc_offset) const = 0;
|
||||
};
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
#include "DiscIO/VolumeFileBlobReader.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
#include "DiscIO/Filesystem.h"
|
||||
#include "DiscIO/Volume.h"
|
||||
|
||||
|
@ -11,7 +14,7 @@ namespace DiscIO
|
|||
{
|
||||
std::unique_ptr<VolumeFileBlobReader> VolumeFileBlobReader::Create(const Volume& volume,
|
||||
const Partition& partition,
|
||||
const std::string& file_path)
|
||||
std::string_view file_path)
|
||||
{
|
||||
const FileSystem* file_system = volume.GetFileSystem(partition);
|
||||
if (!file_system)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "DiscIO/Blob.h"
|
||||
|
@ -20,7 +20,7 @@ class VolumeFileBlobReader final : public BlobReader
|
|||
{
|
||||
public:
|
||||
static std::unique_ptr<VolumeFileBlobReader>
|
||||
Create(const Volume& volume, const Partition& partition, const std::string& file_path);
|
||||
Create(const Volume& volume, const Partition& partition, std::string_view file_path);
|
||||
|
||||
BlobType GetBlobType() const override { return BlobType::PLAIN; }
|
||||
u64 GetRawSize() const override;
|
||||
|
|
Loading…
Reference in New Issue