stratosphere-except-ldr: use fs bindings (this temporarily breaks loader)

This commit is contained in:
Michael Scire 2020-03-08 16:33:49 -07:00
parent 4eb3109c93
commit 6eee3f5fe7
17 changed files with 283 additions and 187 deletions

View file

@ -20,7 +20,13 @@ namespace ams::cfg {
namespace {
std::atomic<u32> g_flag_mount_count;
/* Helper. */
void GetFlagMountName(char *dst) {
std::snprintf(dst, fs::MountNameLengthMax + 1, "#flag%08x", g_flag_mount_count.fetch_add(1));
}
bool HasFlagFile(const char *flag_path) {
/* All flags are not present until the SD card is. */
if (!IsSdCardInitialized()) {
@ -28,20 +34,23 @@ namespace ams::cfg {
}
/* Mount the SD card. */
FsFileSystem sd_fs = {};
if (R_FAILED(fsOpenSdCardFileSystem(&sd_fs))) {
char mount_name[fs::MountNameLengthMax + 1];
GetFlagMountName(mount_name);
if (R_FAILED(fs::MountSdCard(mount_name))) {
return false;
}
ON_SCOPE_EXIT { serviceClose(&sd_fs.s); };
ON_SCOPE_EXIT { fs::Unmount(mount_name); };
/* Open the file. */
FsFile flag_file;
if (R_FAILED(fsFsOpenFile(&sd_fs, flag_path, FsOpenMode_Read, &flag_file))) {
/* Check if the entry exists. */
char full_path[fs::EntryNameLengthMax + 1];
std::snprintf(full_path, sizeof(full_path), "%s:/%s", mount_name, flag_path[0] == '/' ? flag_path + 1 : flag_path);
bool has_file;
if (R_FAILED(fs::HasFile(std::addressof(has_file), full_path))) {
return false;
}
fsFileClose(&flag_file);
return true;
return has_file;
}
}
@ -52,13 +61,13 @@ namespace ams::cfg {
}
bool HasContentSpecificFlag(ncm::ProgramId program_id, const char *flag) {
char content_flag[FS_MAX_PATH];
char content_flag[fs::EntryNameLengthMax + 1];
std::snprintf(content_flag, sizeof(content_flag) - 1, "/atmosphere/contents/%016lx/flags/%s.flag", static_cast<u64>(program_id), flag);
return HasFlagFile(content_flag);
}
bool HasGlobalFlag(const char *flag) {
char global_flag[FS_MAX_PATH];
char global_flag[fs::EntryNameLengthMax + 1];
std::snprintf(global_flag, sizeof(global_flag) - 1, "/atmosphere/flags/%s.flag", flag);
return HasFlagFile(global_flag);
}