mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-06-12 10:37:59 -05:00
common: fs: Rework the Common Filesystem interface to make use of std::filesystem (#6270)
* common: fs: fs_types: Create filesystem types Contains various filesystem types used by the Common::FS library * common: fs: fs_util: Add std::string to std::u8string conversion utility * common: fs: path_util: Add utlity functions for paths Contains various utility functions for getting or manipulating filesystem paths used by the Common::FS library * common: fs: file: Rewrite the IOFile implementation * common: fs: Reimplement Common::FS library using std::filesystem * common: fs: fs_paths: Add fs_paths to replace common_paths * common: fs: path_util: Add the rest of the path functions * common: Remove the previous Common::FS implementation * general: Remove unused fs includes * string_util: Remove unused function and include * nvidia_flags: Migrate to the new Common::FS library * settings: Migrate to the new Common::FS library * logging: backend: Migrate to the new Common::FS library * core: Migrate to the new Common::FS library * perf_stats: Migrate to the new Common::FS library * reporter: Migrate to the new Common::FS library * telemetry_session: Migrate to the new Common::FS library * key_manager: Migrate to the new Common::FS library * bis_factory: Migrate to the new Common::FS library * registered_cache: Migrate to the new Common::FS library * xts_archive: Migrate to the new Common::FS library * service: acc: Migrate to the new Common::FS library * applets/profile: Migrate to the new Common::FS library * applets/web: Migrate to the new Common::FS library * service: filesystem: Migrate to the new Common::FS library * loader: Migrate to the new Common::FS library * gl_shader_disk_cache: Migrate to the new Common::FS library * nsight_aftermath_tracker: Migrate to the new Common::FS library * vulkan_library: Migrate to the new Common::FS library * configure_debug: Migrate to the new Common::FS library * game_list_worker: Migrate to the new Common::FS library * config: Migrate to the new Common::FS library * configure_filesystem: Migrate to the new Common::FS library * configure_per_game_addons: Migrate to the new Common::FS library * configure_profile_manager: Migrate to the new Common::FS library * configure_ui: Migrate to the new Common::FS library * input_profiles: Migrate to the new Common::FS library * yuzu_cmd: config: Migrate to the new Common::FS library * yuzu_cmd: Migrate to the new Common::FS library * vfs_real: Migrate to the new Common::FS library * vfs: Migrate to the new Common::FS library * vfs_libzip: Migrate to the new Common::FS library * service: bcat: Migrate to the new Common::FS library * yuzu: main: Migrate to the new Common::FS library * vfs_real: Delete the contents of an existing file in CreateFile Current usages of CreateFile expect to delete the contents of an existing file, retain this behavior for now. * input_profiles: Don't iterate the input profile dir if it does not exist Silences an error produced in the log if the directory does not exist. * game_list_worker: Skip parsing file if the returned VfsFile is nullptr Prevents crashes in GetLoader when the virtual file is nullptr * common: fs: Validate paths for path length * service: filesystem: Open the mod load directory as read only
This commit is contained in:
@ -12,8 +12,8 @@
|
||||
#include <QFileInfo>
|
||||
#include <QSettings>
|
||||
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/fs/fs.h"
|
||||
#include "common/fs/path_util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/card_image.h"
|
||||
#include "core/file_sys/content_archive.h"
|
||||
@ -39,10 +39,11 @@ QString GetGameListCachedObject(const std::string& filename, const std::string&
|
||||
return generator();
|
||||
}
|
||||
|
||||
const auto path = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||
"game_list" + DIR_SEP + filename + '.' + ext;
|
||||
const auto path =
|
||||
Common::FS::PathToUTF8String(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
|
||||
"game_list" / fmt::format("{}.{}", filename, ext));
|
||||
|
||||
Common::FS::CreateFullPath(path);
|
||||
void(Common::FS::CreateParentDirs(path));
|
||||
|
||||
if (!Common::FS::Exists(path)) {
|
||||
const auto str = generator();
|
||||
@ -70,12 +71,15 @@ std::pair<std::vector<u8>, std::string> GetGameListCachedObject(
|
||||
return generator();
|
||||
}
|
||||
|
||||
const auto path1 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||
"game_list" + DIR_SEP + filename + ".jpeg";
|
||||
const auto path2 = Common::FS::GetUserPath(Common::FS::UserPath::CacheDir) + DIR_SEP +
|
||||
"game_list" + DIR_SEP + filename + ".appname.txt";
|
||||
const auto game_list_dir =
|
||||
Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / "game_list";
|
||||
const auto jpeg_name = fmt::format("{}.jpeg", filename);
|
||||
const auto app_name = fmt::format("{}.appname.txt", filename);
|
||||
|
||||
Common::FS::CreateFullPath(path1);
|
||||
const auto path1 = Common::FS::PathToUTF8String(game_list_dir / jpeg_name);
|
||||
const auto path2 = Common::FS::PathToUTF8String(game_list_dir / app_name);
|
||||
|
||||
void(Common::FS::CreateParentDirs(path1));
|
||||
|
||||
if (!Common::FS::Exists(path1) || !Common::FS::Exists(path2)) {
|
||||
const auto [icon, nacp] = generator();
|
||||
@ -281,23 +285,27 @@ void GameListWorker::AddTitlesToGameList(GameListDir* parent_dir) {
|
||||
}
|
||||
}
|
||||
|
||||
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path,
|
||||
unsigned int recursion, GameListDir* parent_dir) {
|
||||
void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
|
||||
GameListDir* parent_dir) {
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
const auto callback = [this, target, recursion, parent_dir,
|
||||
&system](u64* num_entries_out, const std::string& directory,
|
||||
const std::string& virtual_name) -> bool {
|
||||
const auto callback = [this, target, parent_dir,
|
||||
&system](const std::filesystem::path& path) -> bool {
|
||||
if (stop_processing) {
|
||||
// Breaks the callback loop.
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string physical_name = directory + DIR_SEP + virtual_name;
|
||||
const bool is_dir = Common::FS::IsDirectory(physical_name);
|
||||
const auto physical_name = Common::FS::PathToUTF8String(path);
|
||||
const auto is_dir = Common::FS::IsDir(path);
|
||||
|
||||
if (!is_dir &&
|
||||
(HasSupportedFileExtension(physical_name) || IsExtractedNCAMain(physical_name))) {
|
||||
const auto file = vfs->OpenFile(physical_name, FileSys::Mode::Read);
|
||||
if (!file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto loader = Loader::GetLoader(system, file);
|
||||
if (!loader) {
|
||||
return true;
|
||||
@ -343,15 +351,19 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa
|
||||
compatibility_list, patch),
|
||||
parent_dir);
|
||||
}
|
||||
} else if (is_dir && recursion > 0) {
|
||||
} else if (is_dir) {
|
||||
watch_list.append(QString::fromStdString(physical_name));
|
||||
ScanFileSystem(target, physical_name, recursion - 1, parent_dir);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Common::FS::ForeachDirectoryEntry(nullptr, dir_path, callback);
|
||||
if (deep_scan) {
|
||||
Common::FS::IterateDirEntriesRecursively(dir_path, callback,
|
||||
Common::FS::DirEntryFilter::All);
|
||||
} else {
|
||||
Common::FS::IterateDirEntries(dir_path, callback, Common::FS::DirEntryFilter::File);
|
||||
}
|
||||
}
|
||||
|
||||
void GameListWorker::run() {
|
||||
@ -376,9 +388,9 @@ void GameListWorker::run() {
|
||||
auto* const game_list_dir = new GameListDir(game_dir);
|
||||
emit DirEntryReady(game_list_dir);
|
||||
ScanFileSystem(ScanTarget::FillManualContentProvider, game_dir.path.toStdString(),
|
||||
game_dir.deep_scan ? 256 : 0, game_list_dir);
|
||||
game_dir.deep_scan, game_list_dir);
|
||||
ScanFileSystem(ScanTarget::PopulateGameList, game_dir.path.toStdString(),
|
||||
game_dir.deep_scan ? 256 : 0, game_list_dir);
|
||||
game_dir.deep_scan, game_list_dir);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user