file_util: Use an enum class for GetUserPath()
Instead of using an unsigned int as a parameter and expecting a user to always pass in the correct values, we can just convert the enum into an enum class and use that type as the parameter type instead, which makes the interface more type safe. We also get rid of the bookkeeping "NUM_" element in the enum by just using an unordered map. This function is generally low-frequency in terms of calls (and I'd hope so, considering otherwise would mean we're slamming the disk with IO all the time) so I'd consider this acceptable in this case.
This commit is contained in:
parent
80cdfe1c45
commit
b3221c3180
15 changed files with 106 additions and 89 deletions
|
@ -441,11 +441,13 @@ std::string GetTitlePath(Service::FS::MediaType media_type, u64 tid) {
|
|||
|
||||
std::string GetMediaTitlePath(Service::FS::MediaType media_type) {
|
||||
if (media_type == Service::FS::MediaType::NAND)
|
||||
return fmt::format("{}{}/title/", FileUtil::GetUserPath(D_NAND_IDX), SYSTEM_ID);
|
||||
return fmt::format("{}{}/title/", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir),
|
||||
SYSTEM_ID);
|
||||
|
||||
if (media_type == Service::FS::MediaType::SDMC)
|
||||
return fmt::format("{}Nintendo 3DS/{}/{}/title/", FileUtil::GetUserPath(D_SDMC_IDX),
|
||||
SYSTEM_ID, SDCARD_ID);
|
||||
return fmt::format("{}Nintendo 3DS/{}/{}/title/",
|
||||
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), SYSTEM_ID,
|
||||
SDCARD_ID);
|
||||
|
||||
if (media_type == Service::FS::MediaType::GameCard) {
|
||||
// TODO(shinyquagsire23): get current app parent folder if TID matches?
|
||||
|
|
|
@ -172,7 +172,7 @@ bool Module::LoadLegacySharedFont() {
|
|||
// generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided
|
||||
// a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file
|
||||
// "shared_font.bin" in the Citra "sysdata" directory.
|
||||
std::string filepath = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT;
|
||||
std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SHARED_FONT;
|
||||
|
||||
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
||||
FileUtil::IOFile file(filepath, "rb");
|
||||
|
|
|
@ -572,9 +572,9 @@ ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
|
|||
|
||||
std::string media_type_directory;
|
||||
if (media_type == MediaType::NAND) {
|
||||
media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
|
||||
media_type_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
} else if (media_type == MediaType::SDMC) {
|
||||
media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
|
||||
media_type_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
|
||||
} else {
|
||||
LOG_ERROR(Service_FS, "Unsupported media type {}", static_cast<u32>(media_type));
|
||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
||||
|
@ -593,7 +593,7 @@ ResultCode DeleteSystemSaveData(u32 high, u32 low) {
|
|||
// Construct the binary path to the archive first
|
||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
|
||||
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
|
||||
|
@ -605,7 +605,7 @@ ResultCode CreateSystemSaveData(u32 high, u32 low) {
|
|||
// Construct the binary path to the archive first
|
||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
||||
|
||||
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||
if (!FileUtil::CreateFullPath(systemsavedata_path))
|
||||
|
@ -617,8 +617,8 @@ void RegisterArchiveTypes() {
|
|||
// TODO(Subv): Add the other archive types (see here for the known types:
|
||||
// http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
|
||||
|
||||
std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
|
||||
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
|
||||
std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
|
||||
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||
auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
|
||||
if (sdmc_factory->Initialize())
|
||||
RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
|
||||
|
|
|
@ -70,7 +70,7 @@ AESKey HexToKey(const std::string& hex) {
|
|||
}
|
||||
|
||||
void LoadPresetKeys() {
|
||||
const std::string filepath = FileUtil::GetUserPath(D_SYSDATA_IDX) + AES_KEYS;
|
||||
const std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + AES_KEYS;
|
||||
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
||||
std::ifstream file;
|
||||
OpenFStream(file, filepath, std::ios_base::in);
|
||||
|
|
|
@ -45,7 +45,8 @@ static u64 GenerateTelemetryId() {
|
|||
|
||||
u64 GetTelemetryId() {
|
||||
u64 telemetry_id{};
|
||||
const std::string filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
|
||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
|
||||
if (FileUtil::Exists(filename)) {
|
||||
FileUtil::IOFile file(filename, "rb");
|
||||
|
@ -69,7 +70,8 @@ u64 GetTelemetryId() {
|
|||
|
||||
u64 RegenerateTelemetryId() {
|
||||
const u64 new_telemetry_id{GenerateTelemetryId()};
|
||||
const std::string filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"};
|
||||
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
|
||||
"telemetry_id"};
|
||||
|
||||
FileUtil::IOFile file(filename, "wb");
|
||||
if (!file.IsOpen()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue