From a87426787c95f953dfb600e5c444461890bb76f3 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 3 Jul 2018 19:25:08 -0400 Subject: [PATCH] Guess 'main' to be Directory by filename --- src/common/file_util.cpp | 8 ++++++++ src/common/file_util.h | 3 +++ src/core/file_sys/vfs.cpp | 7 ++----- src/core/hle/service/filesystem/filesystem.cpp | 4 ++-- src/core/loader/loader.cpp | 15 +++++++++------ src/core/loader/loader.h | 6 +++--- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 983fb002db..13516a4a19 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -834,6 +834,14 @@ std::string GetFilename(std::string path) { return path.substr(name_index + 1); } +std::string GetExtensionFromFilename(const std::string& name) { + size_t index = name.find_last_of('.'); + if (index == std::string::npos) + return ""; + + return name.substr(index + 1); +} + std::string RemoveTrailingSlash(const std::string& path) { if (path.empty()) return path; diff --git a/src/common/file_util.h b/src/common/file_util.h index 99b61950c3..9bb3c41091 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -160,6 +160,9 @@ std::string GetParentPath(const std::string& path); // Gets the filename of the path std::string GetFilename(std::string path); +// Gets the extension of the filename +std::string GetExtensionFromFilename(const std::string& name); + // Removes the final '/' or '\' if one exists std::string RemoveTrailingSlash(const std::string& path); diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index 4773b06c9f..c99071d6aa 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp @@ -4,6 +4,7 @@ #include #include +#include "common/file_util.h" #include "core/file_sys/vfs.h" namespace FileSys { @@ -11,11 +12,7 @@ namespace FileSys { VfsFile::~VfsFile() = default; std::string VfsFile::GetExtension() const { - size_t index = GetName().find_last_of('.'); - if (index == std::string::npos) - return ""; - - return GetName().substr(index + 1); + return FileUtil::GetExtensionFromFilename(GetName()); } VfsDirectory::~VfsDirectory() = default; diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 2d497667c9..25810c165c 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -19,9 +19,9 @@ namespace Service::FileSystem { // Size of emulated sd card free space, reported in bytes. -// Just using 128GiB because thats +// Just using 32GB because thats reasonable // TODO(DarkLordZach): Eventually make this configurable in settings. -constexpr u64 EMULATED_SD_REPORTED_SIZE = 1 << 37; +constexpr u64 EMULATED_SD_REPORTED_SIZE = 32000000000; static FileSys::VirtualDir GetDirectoryRelativeWrapped(FileSys::VirtualDir base, const std::string& dir_name) { diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index c1692d9355..1574345a17 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp @@ -45,16 +45,19 @@ FileType IdentifyFile(const std::string& file_name) { return IdentifyFile(FileSys::VirtualFile(std::make_shared(file_name))); } -FileType GuessFromExtension(const std::string& extension_) { - std::string extension = Common::ToLower(extension_); +FileType GuessFromFilename(const std::string& name) { + if (name == "main") + return FileType::DeconstructedRomDirectory; + + const std::string extension = Common::ToLower(FileUtil::GetExtensionFromFilename(name)); if (extension == "elf") return FileType::ELF; - else if (extension == "nro") + if (extension == "nro") return FileType::NRO; - else if (extension == "nso") + if (extension == "nso") return FileType::NSO; - else if (extension == "nca") + if (extension == "nca") return FileType::NCA; return FileType::Unknown; @@ -118,7 +121,7 @@ static std::unique_ptr GetFileLoader(FileSys::VirtualFile file, FileT std::unique_ptr GetLoader(FileSys::VirtualFile file) { FileType type = IdentifyFile(file); - FileType filename_type = GuessFromExtension(file->GetExtension()); + FileType filename_type = GuessFromFilename(file->GetName()); if (type != filename_type) { LOG_WARNING(Loader, "File {} has a different type than its extension.", file->GetName()); diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 059e38a506..1da9e8099f 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -50,12 +50,12 @@ FileType IdentifyFile(FileSys::VirtualFile file); FileType IdentifyFile(const std::string& file_name); /** - * Guess the type of a bootable file from its extension - * @param extension String extension of bootable file + * Guess the type of a bootable file from its name + * @param name String name of bootable file * @return FileType of file. Note: this will return FileType::Unknown if it is unable to determine * a filetype, and will never return FileType::Error. */ -FileType GuessFromExtension(const std::string& extension); +FileType GuessFromFilename(const std::string& name); /** * Convert a FileType into a string which can be displayed to the user.