mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-30 13:24:16 +01:00
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
@ -115,6 +115,18 @@ static void OnMessageReceived(const Network::ChatEntry& msg) {
|
|||||||
std::cout << std::endl << msg.nickname << ": " << msg.message << std::endl << std::endl;
|
std::cout << std::endl << msg.nickname << ": " << msg.message << std::endl << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void InitializeLogging() {
|
||||||
|
Log::Filter log_filter(Log::Level::Debug);
|
||||||
|
log_filter.ParseFilterString(Settings::values.log_filter);
|
||||||
|
Log::SetGlobalFilter(log_filter);
|
||||||
|
|
||||||
|
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
||||||
|
|
||||||
|
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||||
|
FileUtil::CreateFullPath(log_dir);
|
||||||
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
|
}
|
||||||
|
|
||||||
/// Application entry point
|
/// Application entry point
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
Config config;
|
Config config;
|
||||||
@ -124,14 +136,7 @@ int main(int argc, char** argv) {
|
|||||||
std::string movie_record;
|
std::string movie_record;
|
||||||
std::string movie_play;
|
std::string movie_play;
|
||||||
|
|
||||||
Log::Filter log_filter;
|
InitializeLogging();
|
||||||
log_filter.ParseFilterString(Settings::values.log_filter);
|
|
||||||
Log::SetGlobalFilter(log_filter);
|
|
||||||
|
|
||||||
Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
|
|
||||||
FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX));
|
|
||||||
Log::AddBackend(
|
|
||||||
std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE));
|
|
||||||
|
|
||||||
char* endarg;
|
char* endarg;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
Config::Config() {
|
Config::Config() {
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||||
sdl2_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "sdl2-config.ini";
|
sdl2_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-config.ini";
|
||||||
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
|
||||||
|
|
||||||
Reload();
|
Reload();
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
Config::Config() {
|
Config::Config() {
|
||||||
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
// TODO: Don't hardcode the path; let the frontend decide where to put the config files.
|
||||||
qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini";
|
qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini";
|
||||||
FileUtil::CreateFullPath(qt_config_loc);
|
FileUtil::CreateFullPath(qt_config_loc);
|
||||||
qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
|
qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ ConfigureDebug::ConfigureDebug(QWidget* parent) : QWidget(parent), ui(new Ui::Co
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->setConfiguration();
|
this->setConfiguration();
|
||||||
connect(ui->open_log_button, &QPushButton::pressed, []() {
|
connect(ui->open_log_button, &QPushButton::pressed, []() {
|
||||||
QString path = QString::fromStdString(FileUtil::GetUserPath(D_LOGS_IDX));
|
QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LogDir));
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
|
||||||
});
|
});
|
||||||
ui->toggle_cpu_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn());
|
ui->toggle_cpu_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn());
|
||||||
|
@ -715,17 +715,19 @@ void GameListWorker::run() {
|
|||||||
stop_processing = false;
|
stop_processing = false;
|
||||||
for (UISettings::GameDir& game_dir : game_dirs) {
|
for (UISettings::GameDir& game_dir : game_dirs) {
|
||||||
if (game_dir.path == "INSTALLED") {
|
if (game_dir.path == "INSTALLED") {
|
||||||
QString path = QString::fromStdString(FileUtil::GetUserPath(D_SDMC_IDX)) +
|
QString path =
|
||||||
"Nintendo "
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) +
|
||||||
"3DS/00000000000000000000000000000000/"
|
"Nintendo "
|
||||||
"00000000000000000000000000000000/title/00040000";
|
"3DS/00000000000000000000000000000000/"
|
||||||
|
"00000000000000000000000000000000/title/00040000";
|
||||||
watch_list.append(path);
|
watch_list.append(path);
|
||||||
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir);
|
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir);
|
||||||
emit DirEntryReady({game_list_dir});
|
emit DirEntryReady({game_list_dir});
|
||||||
AddFstEntriesToGameList(path.toStdString(), 2, game_list_dir);
|
AddFstEntriesToGameList(path.toStdString(), 2, game_list_dir);
|
||||||
} else if (game_dir.path == "SYSTEM") {
|
} else if (game_dir.path == "SYSTEM") {
|
||||||
QString path = QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX)) +
|
QString path =
|
||||||
"00000000000000000000000000000000/title/00040010";
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)) +
|
||||||
|
"00000000000000000000000000000000/title/00040010";
|
||||||
watch_list.append(path);
|
watch_list.append(path);
|
||||||
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir);
|
GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir);
|
||||||
emit DirEntryReady({game_list_dir});
|
emit DirEntryReady({game_list_dir});
|
||||||
|
@ -172,13 +172,13 @@ public:
|
|||||||
QString second_name = QString::fromStdString(filename + extension);
|
QString second_name = QString::fromStdString(filename + extension);
|
||||||
static QRegExp installed_pattern(
|
static QRegExp installed_pattern(
|
||||||
QString::fromStdString(
|
QString::fromStdString(
|
||||||
FileUtil::GetUserPath(D_SDMC_IDX) +
|
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) +
|
||||||
"Nintendo "
|
"Nintendo "
|
||||||
"3DS/00000000000000000000000000000000/00000000000000000000000000000000/"
|
"3DS/00000000000000000000000000000000/00000000000000000000000000000000/"
|
||||||
"title/0004000(0|e)/[0-9a-f]{8}/content/")
|
"title/0004000(0|e)/[0-9a-f]{8}/content/")
|
||||||
.replace("\\", "\\\\"));
|
.replace("\\", "\\\\"));
|
||||||
static QRegExp system_pattern(
|
static QRegExp system_pattern(
|
||||||
QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX) +
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
|
||||||
"00000000000000000000000000000000/"
|
"00000000000000000000000000000000/"
|
||||||
"title/00040010/[0-9a-f]{8}/content/")
|
"title/00040010/[0-9a-f]{8}/content/")
|
||||||
.replace("\\", "\\\\"));
|
.replace("\\", "\\\\"));
|
||||||
|
@ -102,13 +102,18 @@ void GMainWindow::ShowTelemetryCallout() {
|
|||||||
|
|
||||||
const int GMainWindow::max_recent_files_item;
|
const int GMainWindow::max_recent_files_item;
|
||||||
|
|
||||||
GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
|
static void InitializeLogging() {
|
||||||
Log::Filter log_filter;
|
Log::Filter log_filter;
|
||||||
log_filter.ParseFilterString(Settings::values.log_filter);
|
log_filter.ParseFilterString(Settings::values.log_filter);
|
||||||
Log::SetGlobalFilter(log_filter);
|
Log::SetGlobalFilter(log_filter);
|
||||||
FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX));
|
|
||||||
Log::AddBackend(
|
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||||
std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE));
|
FileUtil::CreateFullPath(log_dir);
|
||||||
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
|
}
|
||||||
|
|
||||||
|
GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) {
|
||||||
|
InitializeLogging();
|
||||||
Debugger::ToggleConsole();
|
Debugger::ToggleConsole();
|
||||||
Settings::LogSettings();
|
Settings::LogSettings();
|
||||||
|
|
||||||
@ -880,7 +885,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target
|
|||||||
switch (target) {
|
switch (target) {
|
||||||
case GameListOpenTarget::SAVE_DATA: {
|
case GameListOpenTarget::SAVE_DATA: {
|
||||||
open_target = "Save Data";
|
open_target = "Save Data";
|
||||||
std::string sdmc_dir = FileUtil::GetUserPath(D_SDMC_IDX);
|
std::string sdmc_dir = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
|
||||||
path = FileSys::ArchiveSource_SDSaveData::GetSaveDataPathFor(sdmc_dir, program_id);
|
path = FileSys::ArchiveSource_SDSaveData::GetSaveDataPathFor(sdmc_dir, program_id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -931,13 +936,13 @@ void GMainWindow::OnGameListOpenDirectory(QString directory) {
|
|||||||
QString path;
|
QString path;
|
||||||
if (directory == "INSTALLED") {
|
if (directory == "INSTALLED") {
|
||||||
path =
|
path =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(D_SDMC_IDX).c_str() +
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir).c_str() +
|
||||||
std::string("Nintendo "
|
std::string("Nintendo "
|
||||||
"3DS/00000000000000000000000000000000/"
|
"3DS/00000000000000000000000000000000/"
|
||||||
"00000000000000000000000000000000/title/00040000"));
|
"00000000000000000000000000000000/title/00040000"));
|
||||||
} else if (directory == "SYSTEM") {
|
} else if (directory == "SYSTEM") {
|
||||||
path =
|
path =
|
||||||
QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX).c_str() +
|
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() +
|
||||||
std::string("00000000000000000000000000000000/title/00040010"));
|
std::string("00000000000000000000000000000000/title/00040010"));
|
||||||
} else {
|
} else {
|
||||||
path = directory;
|
path = directory;
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#define USA_DIR "USA"
|
#define USA_DIR "USA"
|
||||||
#define JAP_DIR "JAP"
|
#define JAP_DIR "JAP"
|
||||||
|
|
||||||
// Subdirs in the User dir returned by GetUserPath(D_USER_IDX)
|
// Subdirs in the User dir returned by GetUserPath(UserPath::UserDir)
|
||||||
#define CONFIG_DIR "config"
|
#define CONFIG_DIR "config"
|
||||||
#define CACHE_DIR "cache"
|
#define CACHE_DIR "cache"
|
||||||
#define SDMC_DIR "sdmc"
|
#define SDMC_DIR "sdmc"
|
||||||
@ -39,10 +39,10 @@
|
|||||||
#define LOG_DIR "log"
|
#define LOG_DIR "log"
|
||||||
|
|
||||||
// Filenames
|
// Filenames
|
||||||
// Files in the directory returned by GetUserPath(D_LOGS_IDX)
|
// Files in the directory returned by GetUserPath(UserPath::LogDir)
|
||||||
#define LOG_FILE "citra_log.txt"
|
#define LOG_FILE "citra_log.txt"
|
||||||
|
|
||||||
// Files in the directory returned by GetUserPath(D_CONFIG_IDX)
|
// Files in the directory returned by GetUserPath(UserPath::ConfigDir)
|
||||||
#define EMU_CONFIG "emu.ini"
|
#define EMU_CONFIG "emu.ini"
|
||||||
#define DEBUGGER_CONFIG "debugger.ini"
|
#define DEBUGGER_CONFIG "debugger.ini"
|
||||||
#define LOGGER_CONFIG "logger.ini"
|
#define LOGGER_CONFIG "logger.ini"
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_paths.h"
|
#include "common/common_paths.h"
|
||||||
@ -670,67 +671,68 @@ std::string GetSysDirectory() {
|
|||||||
|
|
||||||
// Returns a string with a Citra data dir or file in the user's home
|
// Returns a string with a Citra data dir or file in the user's home
|
||||||
// directory. To be used in "multi-user" mode (that is, installed).
|
// directory. To be used in "multi-user" mode (that is, installed).
|
||||||
const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath) {
|
const std::string& GetUserPath(UserPath path, const std::string& new_path) {
|
||||||
static std::string paths[NUM_PATH_INDICES];
|
static std::unordered_map<UserPath, std::string> paths;
|
||||||
|
auto& user_path = paths[UserPath::UserDir];
|
||||||
|
|
||||||
// Set up all paths and files on the first run
|
// Set up all paths and files on the first run
|
||||||
if (paths[D_USER_IDX].empty()) {
|
if (user_path.empty()) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
user_path = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
if (!FileUtil::IsDirectory(paths[D_USER_IDX])) {
|
if (!FileUtil::IsDirectory(user_path)) {
|
||||||
paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Common_Filesystem, "Using the local user directory");
|
LOG_INFO(Common_Filesystem, "Using the local user directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
|
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
||||||
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
|
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
||||||
#else
|
#else
|
||||||
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
|
if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
|
||||||
paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
|
||||||
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
|
paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
|
||||||
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
|
paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
|
||||||
} else {
|
} else {
|
||||||
std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
|
std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
|
||||||
std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
|
std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
|
||||||
std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME");
|
std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME");
|
||||||
|
|
||||||
paths[D_USER_IDX] = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
user_path = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
||||||
paths[D_CONFIG_IDX] = config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
paths.emplace(UserPath::ConfigDir, config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
||||||
paths[D_CACHE_IDX] = cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
|
paths.emplace(UserPath::CacheDir, cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
|
paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
|
||||||
paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
|
paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
|
||||||
paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP;
|
paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
|
||||||
// TODO: Put the logs in a better location for each OS
|
// TODO: Put the logs in a better location for each OS
|
||||||
paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOG_DIR DIR_SEP;
|
paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newPath.empty()) {
|
if (!new_path.empty()) {
|
||||||
if (!FileUtil::IsDirectory(newPath)) {
|
if (!FileUtil::IsDirectory(new_path)) {
|
||||||
LOG_ERROR(Common_Filesystem, "Invalid path specified {}", newPath);
|
LOG_ERROR(Common_Filesystem, "Invalid path specified {}", new_path);
|
||||||
return paths[DirIDX];
|
return paths[path];
|
||||||
} else {
|
} else {
|
||||||
paths[DirIDX] = newPath;
|
paths[path] = new_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (DirIDX) {
|
switch (path) {
|
||||||
case D_ROOT_IDX:
|
case UserPath::RootDir:
|
||||||
paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
|
user_path = paths[UserPath::RootDir] + DIR_SEP;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_USER_IDX:
|
case UserPath::UserDir:
|
||||||
paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP;
|
user_path = paths[UserPath::RootDir] + DIR_SEP;
|
||||||
paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP;
|
paths[UserPath::ConfigDir] = user_path + CONFIG_DIR DIR_SEP;
|
||||||
paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP;
|
paths[UserPath::CacheDir] = user_path + CACHE_DIR DIR_SEP;
|
||||||
paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP;
|
paths[UserPath::SDMCDir] = user_path + SDMC_DIR DIR_SEP;
|
||||||
paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP;
|
paths[UserPath::NANDDir] = user_path + NAND_DIR DIR_SEP;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return paths[DirIDX];
|
return paths[path];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
|
size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
|
||||||
|
@ -17,21 +17,20 @@
|
|||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// User directory indices for GetUserPath
|
|
||||||
enum {
|
|
||||||
D_USER_IDX,
|
|
||||||
D_ROOT_IDX,
|
|
||||||
D_CONFIG_IDX,
|
|
||||||
D_CACHE_IDX,
|
|
||||||
D_SDMC_IDX,
|
|
||||||
D_NAND_IDX,
|
|
||||||
D_SYSDATA_IDX,
|
|
||||||
D_LOGS_IDX,
|
|
||||||
NUM_PATH_INDICES
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace FileUtil {
|
namespace FileUtil {
|
||||||
|
|
||||||
|
// User paths for GetUserPath
|
||||||
|
enum class UserPath {
|
||||||
|
CacheDir,
|
||||||
|
ConfigDir,
|
||||||
|
LogDir,
|
||||||
|
NANDDir,
|
||||||
|
RootDir,
|
||||||
|
SDMCDir,
|
||||||
|
SysDataDir,
|
||||||
|
UserDir,
|
||||||
|
};
|
||||||
|
|
||||||
// FileSystem tree node/
|
// FileSystem tree node/
|
||||||
struct FSTEntry {
|
struct FSTEntry {
|
||||||
bool isDirectory;
|
bool isDirectory;
|
||||||
@ -124,7 +123,7 @@ bool SetCurrentDir(const std::string& directory);
|
|||||||
|
|
||||||
// Returns a pointer to a string with a Citra data dir in the user's home
|
// Returns a pointer to a string with a Citra data dir in the user's home
|
||||||
// directory. To be used in "multi-user" mode (that is, installed).
|
// directory. To be used in "multi-user" mode (that is, installed).
|
||||||
const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath = "");
|
const std::string& GetUserPath(UserPath path, const std::string& new_path = "");
|
||||||
|
|
||||||
// Returns the path to where the sys file are
|
// Returns the path to where the sys file are
|
||||||
std::string GetSysDirectory();
|
std::string GetSysDirectory();
|
||||||
|
@ -441,11 +441,13 @@ std::string GetTitlePath(Service::FS::MediaType media_type, u64 tid) {
|
|||||||
|
|
||||||
std::string GetMediaTitlePath(Service::FS::MediaType media_type) {
|
std::string GetMediaTitlePath(Service::FS::MediaType media_type) {
|
||||||
if (media_type == Service::FS::MediaType::NAND)
|
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)
|
if (media_type == Service::FS::MediaType::SDMC)
|
||||||
return fmt::format("{}Nintendo 3DS/{}/{}/title/", FileUtil::GetUserPath(D_SDMC_IDX),
|
return fmt::format("{}Nintendo 3DS/{}/{}/title/",
|
||||||
SYSTEM_ID, SDCARD_ID);
|
FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), SYSTEM_ID,
|
||||||
|
SDCARD_ID);
|
||||||
|
|
||||||
if (media_type == Service::FS::MediaType::GameCard) {
|
if (media_type == Service::FS::MediaType::GameCard) {
|
||||||
// TODO(shinyquagsire23): get current app parent folder if TID matches?
|
// 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
|
// 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
|
// a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file
|
||||||
// "shared_font.bin" in the Citra "sysdata" directory.
|
// "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::CreateFullPath(filepath); // Create path if not already created
|
||||||
FileUtil::IOFile file(filepath, "rb");
|
FileUtil::IOFile file(filepath, "rb");
|
||||||
|
@ -572,9 +572,9 @@ ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
|
|||||||
|
|
||||||
std::string media_type_directory;
|
std::string media_type_directory;
|
||||||
if (media_type == MediaType::NAND) {
|
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) {
|
} else if (media_type == MediaType::SDMC) {
|
||||||
media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
|
media_type_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_FS, "Unsupported media type {}", static_cast<u32>(media_type));
|
LOG_ERROR(Service_FS, "Unsupported media type {}", static_cast<u32>(media_type));
|
||||||
return ResultCode(-1); // TODO(Subv): Find the right error code
|
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
|
// Construct the binary path to the archive first
|
||||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
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 base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||||
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
|
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
|
||||||
@ -605,7 +605,7 @@ ResultCode CreateSystemSaveData(u32 high, u32 low) {
|
|||||||
// Construct the binary path to the archive first
|
// Construct the binary path to the archive first
|
||||||
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
|
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 base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
|
||||||
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
|
||||||
if (!FileUtil::CreateFullPath(systemsavedata_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:
|
// TODO(Subv): Add the other archive types (see here for the known types:
|
||||||
// http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
|
// http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
|
||||||
|
|
||||||
std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
|
std::string sdmc_directory = FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir);
|
||||||
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
|
std::string nand_directory = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir);
|
||||||
auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
|
auto sdmc_factory = std::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
|
||||||
if (sdmc_factory->Initialize())
|
if (sdmc_factory->Initialize())
|
||||||
RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
|
RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
|
||||||
|
@ -70,7 +70,7 @@ AESKey HexToKey(const std::string& hex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LoadPresetKeys() {
|
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
|
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
OpenFStream(file, filepath, std::ios_base::in);
|
OpenFStream(file, filepath, std::ios_base::in);
|
||||||
|
@ -45,7 +45,8 @@ static u64 GenerateTelemetryId() {
|
|||||||
|
|
||||||
u64 GetTelemetryId() {
|
u64 GetTelemetryId() {
|
||||||
u64 telemetry_id{};
|
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)) {
|
if (FileUtil::Exists(filename)) {
|
||||||
FileUtil::IOFile file(filename, "rb");
|
FileUtil::IOFile file(filename, "rb");
|
||||||
@ -69,7 +70,8 @@ u64 GetTelemetryId() {
|
|||||||
|
|
||||||
u64 RegenerateTelemetryId() {
|
u64 RegenerateTelemetryId() {
|
||||||
const u64 new_telemetry_id{GenerateTelemetryId()};
|
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");
|
FileUtil::IOFile file(filename, "wb");
|
||||||
if (!file.IsOpen()) {
|
if (!file.IsOpen()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user