mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
DiscIO: Use std::string_view in FileSystem::FindFileInfo
...and in the functions that call it.
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user