Guess 'main' to be Directory by filename
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
#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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -45,16 +45,19 @@ FileType IdentifyFile(const std::string& file_name) {
|
||||
return IdentifyFile(FileSys::VirtualFile(std::make_shared<FileSys::RealVfsFile>(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<AppLoader> GetFileLoader(FileSys::VirtualFile file, FileT
|
||||
|
||||
std::unique_ptr<AppLoader> 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());
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user