mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 20:14:17 +01:00
Merge pull request #5306 from lioncash/view2
file-sys: Make use of std::string_view where applicable
This commit is contained in:
commit
70a43be714
@ -185,7 +185,7 @@ struct ExtSaveDataArchivePath {
|
|||||||
|
|
||||||
static_assert(sizeof(ExtSaveDataArchivePath) == 12, "Incorrect path size");
|
static_assert(sizeof(ExtSaveDataArchivePath) == 12, "Incorrect path size");
|
||||||
|
|
||||||
std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) {
|
std::string GetExtSaveDataPath(std::string_view mount_point, const Path& path) {
|
||||||
std::vector<u8> vec_data = path.AsBinary();
|
std::vector<u8> vec_data = path.AsBinary();
|
||||||
|
|
||||||
ExtSaveDataArchivePath path_data;
|
ExtSaveDataArchivePath path_data;
|
||||||
@ -194,16 +194,16 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path)
|
|||||||
return fmt::format("{}{:08X}/{:08X}/", mount_point, path_data.save_high, path_data.save_low);
|
return fmt::format("{}{:08X}/{:08X}/", mount_point, path_data.save_high, path_data.save_low);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) {
|
std::string GetExtDataContainerPath(std::string_view mount_point, bool shared) {
|
||||||
if (shared)
|
if (shared) {
|
||||||
return fmt::format("{}data/{}/extdata/", mount_point, SYSTEM_ID);
|
return fmt::format("{}data/{}/extdata/", mount_point, SYSTEM_ID);
|
||||||
|
}
|
||||||
return fmt::format("{}Nintendo 3DS/{}/{}/extdata/", mount_point, SYSTEM_ID, SDCARD_ID);
|
return fmt::format("{}Nintendo 3DS/{}/{}/extdata/", mount_point, SYSTEM_ID, SDCARD_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetExtDataPathFromId(const std::string& mount_point, u64 extdata_id) {
|
std::string GetExtDataPathFromId(std::string_view mount_point, u64 extdata_id) {
|
||||||
u32 high = static_cast<u32>(extdata_id >> 32);
|
const u32 high = static_cast<u32>(extdata_id >> 32);
|
||||||
u32 low = static_cast<u32>(extdata_id & 0xFFFFFFFF);
|
const u32 low = static_cast<u32>(extdata_id & 0xFFFFFFFF);
|
||||||
|
|
||||||
return fmt::format("{}{:08x}/{:08x}/", GetExtDataContainerPath(mount_point, false), high, low);
|
return fmt::format("{}{:08x}/{:08x}/", GetExtDataContainerPath(mount_point, false), high, low);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ private:
|
|||||||
* @param path The path that identifies the requested concrete ExtSaveData archive.
|
* @param path The path that identifies the requested concrete ExtSaveData archive.
|
||||||
* @returns The complete path to the specified extdata archive in the host filesystem
|
* @returns The complete path to the specified extdata archive in the host filesystem
|
||||||
*/
|
*/
|
||||||
std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path);
|
std::string GetExtSaveDataPath(std::string_view mount_point, const Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a path to the concrete ExtData archive in the host filesystem based on the
|
* Constructs a path to the concrete ExtData archive in the host filesystem based on the
|
||||||
@ -83,7 +83,7 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path)
|
|||||||
* @param extdata_id The id of the ExtSaveData
|
* @param extdata_id The id of the ExtSaveData
|
||||||
* @returns The complete path to the specified extdata archive in the host filesystem
|
* @returns The complete path to the specified extdata archive in the host filesystem
|
||||||
*/
|
*/
|
||||||
std::string GetExtDataPathFromId(const std::string& mount_point, u64 extdata_id);
|
std::string GetExtDataPathFromId(std::string_view mount_point, u64 extdata_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file
|
* Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file
|
||||||
@ -92,7 +92,7 @@ std::string GetExtDataPathFromId(const std::string& mount_point, u64 extdata_id)
|
|||||||
* @param shared Whether this ExtSaveData container is for SharedExtSaveDatas or not.
|
* @param shared Whether this ExtSaveData container is for SharedExtSaveDatas or not.
|
||||||
* @returns The path to the base ExtSaveData archives' folder in the host file system
|
* @returns The path to the base ExtSaveData archives' folder in the host file system
|
||||||
*/
|
*/
|
||||||
std::string GetExtDataContainerPath(const std::string& mount_point, bool shared);
|
std::string GetExtDataContainerPath(std::string_view mount_point, bool shared);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a FileSys::Path object that refers to the ExtData archive identified by
|
* Constructs a FileSys::Path object that refers to the ExtData archive identified by
|
||||||
|
@ -22,7 +22,7 @@ SERIALIZE_EXPORT_IMPL(FileSys::ArchiveFactory_SystemSaveData)
|
|||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) {
|
std::string GetSystemSaveDataPath(std::string_view mount_point, const Path& path) {
|
||||||
const std::vector<u8> vec_data = path.AsBinary();
|
const std::vector<u8> vec_data = path.AsBinary();
|
||||||
u32 save_low;
|
u32 save_low;
|
||||||
u32 save_high;
|
u32 save_high;
|
||||||
@ -31,7 +31,7 @@ std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& pa
|
|||||||
return fmt::format("{}{:08X}/{:08X}/", mount_point, save_low, save_high);
|
return fmt::format("{}{:08X}/{:08X}/", mount_point, save_low, save_high);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetSystemSaveDataContainerPath(const std::string& mount_point) {
|
std::string GetSystemSaveDataContainerPath(std::string_view mount_point) {
|
||||||
return fmt::format("{}data/{}/sysdata/", mount_point, SYSTEM_ID);
|
return fmt::format("{}data/{}/sysdata/", mount_point, SYSTEM_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ private:
|
|||||||
* @param path The path that identifies the requested concrete SystemSaveData archive.
|
* @param path The path that identifies the requested concrete SystemSaveData archive.
|
||||||
* @returns The complete path to the specified SystemSaveData archive in the host filesystem
|
* @returns The complete path to the specified SystemSaveData archive in the host filesystem
|
||||||
*/
|
*/
|
||||||
std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path);
|
std::string GetSystemSaveDataPath(std::string_view mount_point, const Path& path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file
|
* Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file
|
||||||
@ -58,7 +58,7 @@ std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& pa
|
|||||||
* @param mount_point The base folder where this folder resides, ie. SDMC or NAND.
|
* @param mount_point The base folder where this folder resides, ie. SDMC or NAND.
|
||||||
* @returns The path to the base SystemSaveData archives' folder in the host file system
|
* @returns The path to the base SystemSaveData archives' folder in the host file system
|
||||||
*/
|
*/
|
||||||
std::string GetSystemSaveDataContainerPath(const std::string& mount_point);
|
std::string GetSystemSaveDataContainerPath(std::string_view mount_point);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a FileSys::Path object that refers to the SystemSaveData archive identified by
|
* Constructs a FileSys::Path object that refers to the SystemSaveData archive identified by
|
||||||
|
@ -57,8 +57,8 @@ PathParser::PathParser(const Path& path) {
|
|||||||
is_root = level == 0;
|
is_root = level == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PathParser::HostStatus PathParser::GetHostStatus(const std::string& mount_point) const {
|
PathParser::HostStatus PathParser::GetHostStatus(std::string_view mount_point) const {
|
||||||
auto path = mount_point;
|
std::string path{mount_point};
|
||||||
if (!FileUtil::IsDirectory(path))
|
if (!FileUtil::IsDirectory(path))
|
||||||
return InvalidMountPoint;
|
return InvalidMountPoint;
|
||||||
if (path_sequence.empty()) {
|
if (path_sequence.empty()) {
|
||||||
@ -85,8 +85,8 @@ PathParser::HostStatus PathParser::GetHostStatus(const std::string& mount_point)
|
|||||||
return FileFound;
|
return FileFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PathParser::BuildHostPath(const std::string& mount_point) const {
|
std::string PathParser::BuildHostPath(std::string_view mount_point) const {
|
||||||
std::string path = mount_point;
|
std::string path{mount_point};
|
||||||
for (auto& node : path_sequence) {
|
for (auto& node : path_sequence) {
|
||||||
if (path.back() != '/')
|
if (path.back() != '/')
|
||||||
path += '/';
|
path += '/';
|
||||||
|
@ -47,10 +47,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Checks the status of the specified file / directory by the Path on the host file system.
|
/// Checks the status of the specified file / directory by the Path on the host file system.
|
||||||
HostStatus GetHostStatus(const std::string& mount_point) const;
|
HostStatus GetHostStatus(std::string_view mount_point) const;
|
||||||
|
|
||||||
/// Builds a full path on the host file system.
|
/// Builds a full path on the host file system.
|
||||||
std::string BuildHostPath(const std::string& mount_point) const;
|
std::string BuildHostPath(std::string_view mount_point) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> path_sequence;
|
std::vector<std::string> path_sequence;
|
||||||
|
@ -33,7 +33,7 @@ Loader::ResultStatus TitleMetadata::Load(const std::string& file_path) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader::ResultStatus TitleMetadata::Load(const std::vector<u8> file_data, std::size_t offset) {
|
Loader::ResultStatus TitleMetadata::Load(const std::vector<u8>& file_data, std::size_t offset) {
|
||||||
std::size_t total_size = static_cast<std::size_t>(file_data.size() - offset);
|
std::size_t total_size = static_cast<std::size_t>(file_data.size() - offset);
|
||||||
if (total_size < sizeof(u32_be))
|
if (total_size < sizeof(u32_be))
|
||||||
return Loader::ResultStatus::Error;
|
return Loader::ResultStatus::Error;
|
||||||
|
@ -85,7 +85,7 @@ public:
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
Loader::ResultStatus Load(const std::string& file_path);
|
Loader::ResultStatus Load(const std::string& file_path);
|
||||||
Loader::ResultStatus Load(const std::vector<u8> file_data, std::size_t offset = 0);
|
Loader::ResultStatus Load(const std::vector<u8>& file_data, std::size_t offset = 0);
|
||||||
Loader::ResultStatus Save(const std::string& file_path);
|
Loader::ResultStatus Save(const std::string& file_path);
|
||||||
|
|
||||||
u64 GetTitleID() const;
|
u64 GetTitleID() const;
|
||||||
|
Loading…
Reference in New Issue
Block a user