mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00: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
					
				
					 15 changed files with 106 additions and 89 deletions
				
			
		|  | @ -14,7 +14,7 @@ | |||
| 
 | ||||
| Config::Config() { | ||||
|     // 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); | ||||
|     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); | ||||
|     this->setConfiguration(); | ||||
|     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)); | ||||
|     }); | ||||
|     ui->toggle_cpu_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn()); | ||||
|  |  | |||
|  | @ -715,17 +715,19 @@ void GameListWorker::run() { | |||
|     stop_processing = false; | ||||
|     for (UISettings::GameDir& game_dir : game_dirs) { | ||||
|         if (game_dir.path == "INSTALLED") { | ||||
|             QString path = QString::fromStdString(FileUtil::GetUserPath(D_SDMC_IDX)) + | ||||
|                            "Nintendo " | ||||
|                            "3DS/00000000000000000000000000000000/" | ||||
|                            "00000000000000000000000000000000/title/00040000"; | ||||
|             QString path = | ||||
|                 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir)) + | ||||
|                 "Nintendo " | ||||
|                 "3DS/00000000000000000000000000000000/" | ||||
|                 "00000000000000000000000000000000/title/00040000"; | ||||
|             watch_list.append(path); | ||||
|             GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::InstalledDir); | ||||
|             emit DirEntryReady({game_list_dir}); | ||||
|             AddFstEntriesToGameList(path.toStdString(), 2, game_list_dir); | ||||
|         } else if (game_dir.path == "SYSTEM") { | ||||
|             QString path = QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX)) + | ||||
|                            "00000000000000000000000000000000/title/00040010"; | ||||
|             QString path = | ||||
|                 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)) + | ||||
|                 "00000000000000000000000000000000/title/00040010"; | ||||
|             watch_list.append(path); | ||||
|             GameListDir* game_list_dir = new GameListDir(game_dir, GameListItemType::SystemDir); | ||||
|             emit DirEntryReady({game_list_dir}); | ||||
|  |  | |||
|  | @ -172,13 +172,13 @@ public: | |||
|             QString second_name = QString::fromStdString(filename + extension); | ||||
|             static QRegExp installed_pattern( | ||||
|                 QString::fromStdString( | ||||
|                     FileUtil::GetUserPath(D_SDMC_IDX) + | ||||
|                     FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir) + | ||||
|                     "Nintendo " | ||||
|                     "3DS/00000000000000000000000000000000/00000000000000000000000000000000/" | ||||
|                     "title/0004000(0|e)/[0-9a-f]{8}/content/") | ||||
|                     .replace("\\", "\\\\")); | ||||
|             static QRegExp system_pattern( | ||||
|                 QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX) + | ||||
|                 QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | ||||
|                                        "00000000000000000000000000000000/" | ||||
|                                        "title/00040010/[0-9a-f]{8}/content/") | ||||
|                     .replace("\\", "\\\\")); | ||||
|  |  | |||
|  | @ -102,13 +102,18 @@ void GMainWindow::ShowTelemetryCallout() { | |||
| 
 | ||||
| const int GMainWindow::max_recent_files_item; | ||||
| 
 | ||||
| GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { | ||||
| static void InitializeLogging() { | ||||
|     Log::Filter log_filter; | ||||
|     log_filter.ParseFilterString(Settings::values.log_filter); | ||||
|     Log::SetGlobalFilter(log_filter); | ||||
|     FileUtil::CreateFullPath(FileUtil::GetUserPath(D_LOGS_IDX)); | ||||
|     Log::AddBackend( | ||||
|         std::make_unique<Log::FileBackend>(FileUtil::GetUserPath(D_LOGS_IDX) + LOG_FILE)); | ||||
| 
 | ||||
|     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)); | ||||
| } | ||||
| 
 | ||||
| GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr) { | ||||
|     InitializeLogging(); | ||||
|     Debugger::ToggleConsole(); | ||||
|     Settings::LogSettings(); | ||||
| 
 | ||||
|  | @ -880,7 +885,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target | |||
|     switch (target) { | ||||
|     case GameListOpenTarget::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); | ||||
|         break; | ||||
|     } | ||||
|  | @ -931,13 +936,13 @@ void GMainWindow::OnGameListOpenDirectory(QString directory) { | |||
|     QString path; | ||||
|     if (directory == "INSTALLED") { | ||||
|         path = | ||||
|             QString::fromStdString(FileUtil::GetUserPath(D_SDMC_IDX).c_str() + | ||||
|             QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir).c_str() + | ||||
|                                    std::string("Nintendo " | ||||
|                                                "3DS/00000000000000000000000000000000/" | ||||
|                                                "00000000000000000000000000000000/title/00040000")); | ||||
|     } else if (directory == "SYSTEM") { | ||||
|         path = | ||||
|             QString::fromStdString(FileUtil::GetUserPath(D_NAND_IDX).c_str() + | ||||
|             QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir).c_str() + | ||||
|                                    std::string("00000000000000000000000000000000/title/00040010")); | ||||
|     } else { | ||||
|         path = directory; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue