summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/common_paths.h6
-rw-r--r--src/common/file_util.cpp68
-rw-r--r--src/common/file_util.h27
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp4
-rw-r--r--src/core/hle/service/ns/pl_u.cpp2
-rw-r--r--src/core/telemetry_session.cpp6
-rw-r--r--src/yuzu/configuration/config.cpp2
-rw-r--r--src/yuzu/configuration/configure_debug.cpp2
-rw-r--r--src/yuzu/main.cpp18
-rw-r--r--src/yuzu_cmd/config.cpp2
-rw-r--r--src/yuzu_cmd/yuzu.cpp21
11 files changed, 85 insertions, 73 deletions
diff --git a/src/common/common_paths.h b/src/common/common_paths.h
index 9bf3efaf2..6799a357a 100644
--- a/src/common/common_paths.h
+++ b/src/common/common_paths.h
@@ -26,7 +26,7 @@
26#define USA_DIR "USA" 26#define USA_DIR "USA"
27#define JAP_DIR "JAP" 27#define JAP_DIR "JAP"
28 28
29// Subdirs in the User dir returned by GetUserPath(D_USER_IDX) 29// Subdirs in the User dir returned by GetUserPath(UserPath::UserDir)
30#define CONFIG_DIR "config" 30#define CONFIG_DIR "config"
31#define CACHE_DIR "cache" 31#define CACHE_DIR "cache"
32#define SDMC_DIR "sdmc" 32#define SDMC_DIR "sdmc"
@@ -35,11 +35,11 @@
35#define LOG_DIR "log" 35#define LOG_DIR "log"
36 36
37// Filenames 37// Filenames
38// Files in the directory returned by GetUserPath(D_CONFIG_IDX) 38// Files in the directory returned by GetUserPath(UserPath::ConfigDir)
39#define EMU_CONFIG "emu.ini" 39#define EMU_CONFIG "emu.ini"
40#define DEBUGGER_CONFIG "debugger.ini" 40#define DEBUGGER_CONFIG "debugger.ini"
41#define LOGGER_CONFIG "logger.ini" 41#define LOGGER_CONFIG "logger.ini"
42// Files in the directory returned by GetUserPath(D_LOGS_IDX) 42// Files in the directory returned by GetUserPath(UserPath::LogDir)
43#define LOG_FILE "yuzu_log.txt" 43#define LOG_FILE "yuzu_log.txt"
44 44
45// Sys files 45// Sys files
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index c882ab39f..1e28f7cbb 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <sstream> 5#include <sstream>
6#include <unordered_map>
6#include "common/assert.h" 7#include "common/assert.h"
7#include "common/common_funcs.h" 8#include "common/common_funcs.h"
8#include "common/common_paths.h" 9#include "common/common_paths.h"
@@ -681,67 +682,68 @@ std::string GetSysDirectory() {
681 682
682// Returns a string with a yuzu data dir or file in the user's home 683// Returns a string with a yuzu data dir or file in the user's home
683// directory. To be used in "multi-user" mode (that is, installed). 684// directory. To be used in "multi-user" mode (that is, installed).
684const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath) { 685const std::string& GetUserPath(UserPath path, const std::string& new_path) {
685 static std::string paths[NUM_PATH_INDICES]; 686 static std::unordered_map<UserPath, std::string> paths;
687 auto& user_path = paths[UserPath::UserDir];
686 688
687 // Set up all paths and files on the first run 689 // Set up all paths and files on the first run
688 if (paths[D_USER_IDX].empty()) { 690 if (user_path.empty()) {
689#ifdef _WIN32 691#ifdef _WIN32
690 paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; 692 user_path = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP;
691 if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { 693 if (!FileUtil::IsDirectory(user_path)) {
692 paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; 694 user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
693 } else { 695 } else {
694 LOG_INFO(Common_Filesystem, "Using the local user directory"); 696 LOG_INFO(Common_Filesystem, "Using the local user directory");
695 } 697 }
696 698
697 paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; 699 paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
698 paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; 700 paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
699#else 701#else
700 if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) { 702 if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) {
701 paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; 703 user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
702 paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; 704 paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
703 paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; 705 paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
704 } else { 706 } else {
705 std::string data_dir = GetUserDirectory("XDG_DATA_HOME"); 707 std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
706 std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME"); 708 std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
707 std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME"); 709 std::string cache_dir = GetUserDirectory("XDG_CACHE_HOME");
708 710
709 paths[D_USER_IDX] = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP; 711 user_path = data_dir + DIR_SEP EMU_DATA_DIR DIR_SEP;
710 paths[D_CONFIG_IDX] = config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP; 712 paths.emplace(UserPath::ConfigDir, config_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
711 paths[D_CACHE_IDX] = cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP; 713 paths.emplace(UserPath::CacheDir, cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP);
712 } 714 }
713#endif 715#endif
714 paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; 716 paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
715 paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; 717 paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
716 paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; 718 paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
717 // TODO: Put the logs in a better location for each OS 719 // TODO: Put the logs in a better location for each OS
718 paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOG_DIR DIR_SEP; 720 paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
719 } 721 }
720 722
721 if (!newPath.empty()) { 723 if (!new_path.empty()) {
722 if (!FileUtil::IsDirectory(newPath)) { 724 if (!FileUtil::IsDirectory(new_path)) {
723 LOG_ERROR(Common_Filesystem, "Invalid path specified {}", newPath); 725 LOG_ERROR(Common_Filesystem, "Invalid path specified {}", new_path);
724 return paths[DirIDX]; 726 return paths[path];
725 } else { 727 } else {
726 paths[DirIDX] = newPath; 728 paths[path] = new_path;
727 } 729 }
728 730
729 switch (DirIDX) { 731 switch (path) {
730 case D_ROOT_IDX: 732 case UserPath::RootDir:
731 paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP; 733 user_path = paths[UserPath::RootDir] + DIR_SEP;
732 break; 734 break;
733 735
734 case D_USER_IDX: 736 case UserPath::UserDir:
735 paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP; 737 user_path = paths[UserPath::RootDir] + DIR_SEP;
736 paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; 738 paths[UserPath::ConfigDir] = user_path + CONFIG_DIR DIR_SEP;
737 paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; 739 paths[UserPath::CacheDir] = user_path + CACHE_DIR DIR_SEP;
738 paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; 740 paths[UserPath::SDMCDir] = user_path + SDMC_DIR DIR_SEP;
739 paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; 741 paths[UserPath::NANDDir] = user_path + NAND_DIR DIR_SEP;
740 break; 742 break;
741 } 743 }
742 } 744 }
743 745
744 return paths[DirIDX]; 746 return paths[path];
745} 747}
746 748
747size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) { 749size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename) {
diff --git a/src/common/file_util.h b/src/common/file_util.h
index 1f38b1560..ff01bf0ff 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -16,21 +16,20 @@
16#include "common/string_util.h" 16#include "common/string_util.h"
17#endif 17#endif
18 18
19// User directory indices for GetUserPath
20enum {
21 D_USER_IDX,
22 D_ROOT_IDX,
23 D_CONFIG_IDX,
24 D_CACHE_IDX,
25 D_SDMC_IDX,
26 D_NAND_IDX,
27 D_SYSDATA_IDX,
28 D_LOGS_IDX,
29 NUM_PATH_INDICES
30};
31
32namespace FileUtil { 19namespace FileUtil {
33 20
21// User paths for GetUserPath
22enum class UserPath {
23 CacheDir,
24 ConfigDir,
25 LogDir,
26 NANDDir,
27 RootDir,
28 SDMCDir,
29 SysDataDir,
30 UserDir,
31};
32
34// FileSystem tree node/ 33// FileSystem tree node/
35struct FSTEntry { 34struct FSTEntry {
36 bool isDirectory; 35 bool isDirectory;
@@ -123,7 +122,7 @@ bool SetCurrentDir(const std::string& directory);
123 122
124// Returns a pointer to a string with a yuzu data dir in the user's home 123// Returns a pointer to a string with a yuzu data dir in the user's home
125// directory. To be used in "multi-user" mode (that is, installed). 124// directory. To be used in "multi-user" mode (that is, installed).
126const std::string& GetUserPath(const unsigned int DirIDX, const std::string& newPath = ""); 125const std::string& GetUserPath(UserPath path, const std::string& new_path = "");
127 126
128// Returns the path to where the sys file are 127// Returns the path to where the sys file are
129std::string GetSysDirectory(); 128std::string GetSysDirectory();
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index dffcdfbaf..671e0b8d0 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -272,9 +272,9 @@ void RegisterFileSystems() {
272 sdmc_factory = nullptr; 272 sdmc_factory = nullptr;
273 273
274 auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>( 274 auto nand_directory = std::make_shared<FileSys::RealVfsDirectory>(
275 FileUtil::GetUserPath(D_NAND_IDX), FileSys::Mode::Write); 275 FileUtil::GetUserPath(FileUtil::UserPath::NANDDir), FileSys::Mode::Write);
276 auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>( 276 auto sd_directory = std::make_shared<FileSys::RealVfsDirectory>(
277 FileUtil::GetUserPath(D_SDMC_IDX), FileSys::Mode::Write); 277 FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir), FileSys::Mode::Write);
278 278
279 auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory)); 279 auto savedata = std::make_unique<FileSys::SaveDataFactory>(std::move(nand_directory));
280 save_data_factory = std::move(savedata); 280 save_data_factory = std::move(savedata);
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 691b1d106..bad27894a 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -42,7 +42,7 @@ PL_U::PL_U() : ServiceFramework("pl:u") {
42 RegisterHandlers(functions); 42 RegisterHandlers(functions);
43 43
44 // Attempt to load shared font data from disk 44 // Attempt to load shared font data from disk
45 const std::string filepath{FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT}; 45 const std::string filepath{FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SHARED_FONT};
46 FileUtil::CreateFullPath(filepath); // Create path if not already created 46 FileUtil::CreateFullPath(filepath); // Create path if not already created
47 FileUtil::IOFile file(filepath, "rb"); 47 FileUtil::IOFile file(filepath, "rb");
48 48
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp
index b9a603df3..69aa7a7be 100644
--- a/src/core/telemetry_session.cpp
+++ b/src/core/telemetry_session.cpp
@@ -37,7 +37,8 @@ static u64 GenerateTelemetryId() {
37 37
38u64 GetTelemetryId() { 38u64 GetTelemetryId() {
39 u64 telemetry_id{}; 39 u64 telemetry_id{};
40 static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; 40 static const std::string& filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
41 "telemetry_id"};
41 42
42 if (FileUtil::Exists(filename)) { 43 if (FileUtil::Exists(filename)) {
43 FileUtil::IOFile file(filename, "rb"); 44 FileUtil::IOFile file(filename, "rb");
@@ -61,7 +62,8 @@ u64 GetTelemetryId() {
61 62
62u64 RegenerateTelemetryId() { 63u64 RegenerateTelemetryId() {
63 const u64 new_telemetry_id{GenerateTelemetryId()}; 64 const u64 new_telemetry_id{GenerateTelemetryId()};
64 static const std::string& filename{FileUtil::GetUserPath(D_CONFIG_IDX) + "telemetry_id"}; 65 static const std::string& filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
66 "telemetry_id"};
65 67
66 FileUtil::IOFile file(filename, "wb"); 68 FileUtil::IOFile file(filename, "wb");
67 if (!file.IsOpen()) { 69 if (!file.IsOpen()) {
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp
index 62754a1a9..98969fe10 100644
--- a/src/yuzu/configuration/config.cpp
+++ b/src/yuzu/configuration/config.cpp
@@ -10,7 +10,7 @@
10 10
11Config::Config() { 11Config::Config() {
12 // TODO: Don't hardcode the path; let the frontend decide where to put the config files. 12 // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
13 qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; 13 qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini";
14 FileUtil::CreateFullPath(qt_config_loc); 14 FileUtil::CreateFullPath(qt_config_loc);
15 qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); 15 qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat);
16 16
diff --git a/src/yuzu/configuration/configure_debug.cpp b/src/yuzu/configuration/configure_debug.cpp
index 241db4ae3..5e66239ff 100644
--- a/src/yuzu/configuration/configure_debug.cpp
+++ b/src/yuzu/configuration/configure_debug.cpp
@@ -19,7 +19,7 @@ ConfigureDebug::ConfigureDebug(QWidget* parent) : QWidget(parent), ui(new Ui::Co
19 ui->setupUi(this); 19 ui->setupUi(this);
20 this->setConfiguration(); 20 this->setConfiguration();
21 connect(ui->open_log_button, &QPushButton::pressed, []() { 21 connect(ui->open_log_button, &QPushButton::pressed, []() {
22 QString path = QString::fromStdString(FileUtil::GetUserPath(D_LOGS_IDX)); 22 QString path = QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::LogDir));
23 QDesktopServices::openUrl(QUrl::fromLocalFile(path)); 23 QDesktopServices::openUrl(QUrl::fromLocalFile(path));
24 }); 24 });
25} 25}
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 16812e077..16a95bb19 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -909,6 +909,16 @@ void GMainWindow::UpdateUITheme() {
909#undef main 909#undef main
910#endif 910#endif
911 911
912static void InitializeLogging() {
913 Log::Filter log_filter;
914 log_filter.ParseFilterString(Settings::values.log_filter);
915 Log::SetGlobalFilter(log_filter);
916
917 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
918 FileUtil::CreateFullPath(log_dir);
919 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
920}
921
912int main(int argc, char* argv[]) { 922int main(int argc, char* argv[]) {
913 MicroProfileOnThreadCreate("Frontend"); 923 MicroProfileOnThreadCreate("Frontend");
914 SCOPE_EXIT({ MicroProfileShutdown(); }); 924 SCOPE_EXIT({ MicroProfileShutdown(); });
@@ -927,13 +937,7 @@ int main(int argc, char* argv[]) {
927 937
928 GMainWindow main_window; 938 GMainWindow main_window;
929 // After settings have been loaded by GMainWindow, apply the filter 939 // After settings have been loaded by GMainWindow, apply the filter
930 Log::Filter log_filter; 940 InitializeLogging();
931 log_filter.ParseFilterString(Settings::values.log_filter);
932 Log::SetGlobalFilter(log_filter);
933 FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX));
934 Log::AddBackend(
935 std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE));
936
937 main_window.show(); 941 main_window.show();
938 return app.exec(); 942 return app.exec();
939} 943}
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp
index 723e8b4cc..cea1a5e62 100644
--- a/src/yuzu_cmd/config.cpp
+++ b/src/yuzu_cmd/config.cpp
@@ -15,7 +15,7 @@
15 15
16Config::Config() { 16Config::Config() {
17 // TODO: Don't hardcode the path; let the frontend decide where to put the config files. 17 // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
18 sdl2_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "sdl2-config.ini"; 18 sdl2_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "sdl2-config.ini";
19 sdl2_config = std::make_unique<INIReader>(sdl2_config_loc); 19 sdl2_config = std::make_unique<INIReader>(sdl2_config_loc);
20 20
21 Reload(); 21 Reload();
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 24db1065a..b5392c499 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -56,6 +56,18 @@ static void PrintVersion() {
56 std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl; 56 std::cout << "yuzu " << Common::g_scm_branch << " " << Common::g_scm_desc << std::endl;
57} 57}
58 58
59static void InitializeLogging() {
60 Log::Filter log_filter(Log::Level::Debug);
61 log_filter.ParseFilterString(Settings::values.log_filter);
62 Log::SetGlobalFilter(log_filter);
63
64 Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
65
66 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
67 FileUtil::CreateFullPath(log_dir);
68 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
69}
70
59/// Application entry point 71/// Application entry point
60int main(int argc, char** argv) { 72int main(int argc, char** argv) {
61 Config config; 73 Config config;
@@ -124,14 +136,7 @@ int main(int argc, char** argv) {
124 LocalFree(argv_w); 136 LocalFree(argv_w);
125#endif 137#endif
126 138
127 Log::Filter log_filter(Log::Level::Debug); 139 InitializeLogging();
128 log_filter.ParseFilterString(Settings::values.log_filter);
129 Log::SetGlobalFilter(log_filter);
130
131 Log::AddBackend(std::make_unique<Log::ColorConsoleBackend>());
132 FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX));
133 Log::AddBackend(
134 std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE));
135 140
136 MicroProfileOnThreadCreate("EmuThread"); 141 MicroProfileOnThreadCreate("EmuThread");
137 SCOPE_EXIT({ MicroProfileShutdown(); }); 142 SCOPE_EXIT({ MicroProfileShutdown(); });