From 2081e2f2a19e8216c5292c30083a20b38236e8bc Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Mon, 11 Apr 2022 06:08:19 +0200 Subject: [PATCH] Config: Move ToGameCubeRegion(), GetDirectoryForRegion(), and GetBootROMPath() to new config system namespace. --- Source/Core/Core/Boot/Boot.cpp | 6 +- Source/Core/Core/Config/MainSettings.cpp | 48 +++++++++++++++ Source/Core/Core/Config/MainSettings.h | 7 +++ Source/Core/Core/ConfigManager.cpp | 58 +------------------ Source/Core/Core/ConfigManager.h | 6 -- Source/Core/Core/HW/EXI/EXI.cpp | 2 +- .../Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp | 6 +- Source/Core/Core/NetPlayServer.cpp | 6 +- Source/Core/DolphinQt/GameList/GameList.cpp | 2 +- Source/Core/DolphinQt/MenuBar.cpp | 9 +-- 10 files changed, 72 insertions(+), 78 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 0ad7f6ec12..4e2844c95b 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -311,8 +311,8 @@ std::unique_ptr BootParameters::GenerateFromFile(std::vector>& devices) { Config::SetBase(Config::MAIN_USB_PASSTHROUGH_DEVICES, SaveUSBWhitelistToString(devices)); } + +// The reason we need this function is because some memory card code +// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii. +DiscIO::Region ToGameCubeRegion(DiscIO::Region region) +{ + if (region != DiscIO::Region::NTSC_K) + return region; + + // GameCube has no NTSC-K region. No choice of replacement value is completely + // non-arbitrary, but let's go with NTSC-J since Korean GameCubes are NTSC-J. + return DiscIO::Region::NTSC_J; +} + +const char* GetDirectoryForRegion(DiscIO::Region region) +{ + if (region == DiscIO::Region::Unknown) + region = ToGameCubeRegion(Config::Get(Config::MAIN_FALLBACK_REGION)); + + switch (region) + { + case DiscIO::Region::NTSC_J: + return JAP_DIR; + + case DiscIO::Region::NTSC_U: + return USA_DIR; + + case DiscIO::Region::PAL: + return EUR_DIR; + + case DiscIO::Region::NTSC_K: + ASSERT_MSG(BOOT, false, "NTSC-K is not a valid GameCube region"); + return JAP_DIR; // See ToGameCubeRegion + + default: + ASSERT_MSG(BOOT, false, "Default case should not be reached"); + return EUR_DIR; + } +} + +std::string GetBootROMPath(const std::string& region_directory) +{ + const std::string path = + File::GetUserPath(D_GCUSER_IDX) + DIR_SEP + region_directory + DIR_SEP GC_IPL; + if (!File::Exists(path)) + return File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + region_directory + DIR_SEP GC_IPL; + return path; +} } // namespace Config diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 4ed43a79da..413f595dd4 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -331,4 +331,11 @@ extern const Info MAIN_USB_PASSTHROUGH_DEVICES; std::set> GetUSBDeviceWhitelist(); void SetUSBDeviceWhitelist(const std::set>& devices); +// GameCube path utility functions + +// Replaces NTSC-K with some other region, and doesn't replace non-NTSC-K regions +DiscIO::Region ToGameCubeRegion(DiscIO::Region region); +// The region argument must be valid for GameCube (i.e. must not be NTSC-K) +const char* GetDirectoryForRegion(DiscIO::Region region); +std::string GetBootROMPath(const std::string& region_directory); } // namespace Config diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index 2d90207601..497d938f76 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -220,53 +220,6 @@ std::string SConfig::MakeGameID(std::string_view file_name) return "ID-" + std::string(file_name.substr(0, lastdot)); } -// The reason we need this function is because some memory card code -// expects to get a non-NTSC-K region even if we're emulating an NTSC-K Wii. -DiscIO::Region SConfig::ToGameCubeRegion(DiscIO::Region region) -{ - if (region != DiscIO::Region::NTSC_K) - return region; - - // GameCube has no NTSC-K region. No choice of replacement value is completely - // non-arbitrary, but let's go with NTSC-J since Korean GameCubes are NTSC-J. - return DiscIO::Region::NTSC_J; -} - -const char* SConfig::GetDirectoryForRegion(DiscIO::Region region) -{ - if (region == DiscIO::Region::Unknown) - region = ToGameCubeRegion(GetFallbackRegion()); - - switch (region) - { - case DiscIO::Region::NTSC_J: - return JAP_DIR; - - case DiscIO::Region::NTSC_U: - return USA_DIR; - - case DiscIO::Region::PAL: - return EUR_DIR; - - case DiscIO::Region::NTSC_K: - ASSERT_MSG(BOOT, false, "NTSC-K is not a valid GameCube region"); - return JAP_DIR; // See ToGameCubeRegion - - default: - ASSERT_MSG(BOOT, false, "Default case should not be reached"); - return EUR_DIR; - } -} - -std::string SConfig::GetBootROMPath(const std::string& region_directory) const -{ - const std::string path = - File::GetUserPath(D_GCUSER_IDX) + DIR_SEP + region_directory + DIR_SEP GC_IPL; - if (!File::Exists(path)) - return File::GetSysDirectory() + GC_SYS_DIR + DIR_SEP + region_directory + DIR_SEP GC_IPL; - return path; -} - struct SetGameMetadata { SetGameMetadata(SConfig* config_, DiscIO::Region* region_) : config(config_), region(region_) {} @@ -375,21 +328,16 @@ bool SConfig::SetPathsAndGameMetadata(const BootParameters& boot) return false; if (m_region == DiscIO::Region::Unknown) - m_region = GetFallbackRegion(); + m_region = Config::Get(Config::MAIN_FALLBACK_REGION); // Set up paths - const std::string region_dir = GetDirectoryForRegion(ToGameCubeRegion(m_region)); + const std::string region_dir = Config::GetDirectoryForRegion(Config::ToGameCubeRegion(m_region)); m_strSRAM = File::GetUserPath(F_GCSRAM_IDX); - m_strBootROM = GetBootROMPath(region_dir); + m_strBootROM = Config::GetBootROMPath(region_dir); return true; } -DiscIO::Region SConfig::GetFallbackRegion() -{ - return Config::Get(Config::MAIN_FALLBACK_REGION); -} - DiscIO::Language SConfig::GetCurrentLanguage(bool wii) const { DiscIO::Language language; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index bb0b165249..6a6045c0f8 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -72,13 +72,7 @@ struct SConfig void LoadDefaults(); static std::string MakeGameID(std::string_view file_name); - // Replaces NTSC-K with some other region, and doesn't replace non-NTSC-K regions - static DiscIO::Region ToGameCubeRegion(DiscIO::Region region); - // The region argument must be valid for GameCube (i.e. must not be NTSC-K) - static const char* GetDirectoryForRegion(DiscIO::Region region); - std::string GetBootROMPath(const std::string& region_directory) const; bool SetPathsAndGameMetadata(const BootParameters& boot); - static DiscIO::Region GetFallbackRegion(); DiscIO::Language GetCurrentLanguage(bool wii) const; DiscIO::Language GetLanguageAdjustedForRegion(bool wii, DiscIO::Region region) const; diff --git a/Source/Core/Core/HW/EXI/EXI.cpp b/Source/Core/Core/HW/EXI/EXI.cpp index eb1d99e81e..c480e09235 100644 --- a/Source/Core/Core/HW/EXI/EXI.cpp +++ b/Source/Core/Core/HW/EXI/EXI.cpp @@ -117,7 +117,7 @@ void Init() if (size_override >= 0 && size_override <= 4) size_mbits = Memcard::MBIT_SIZE_MEMORY_CARD_59 << size_override; const bool shift_jis = - SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J; + Config::ToGameCubeRegion(SConfig::GetInstance().m_region) == DiscIO::Region::NTSC_J; const CardFlashId& flash_id = g_SRAM.settings_ex.flash_id[Memcard::SLOT_A]; const u32 rtc_bias = g_SRAM.settings.rtc_bias; const u32 sram_language = static_cast(g_SRAM.settings.language); diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp index c7538ceae2..2baf002ca1 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceMemoryCard.cpp @@ -162,8 +162,8 @@ CEXIMemoryCard::GetGCIFolderPath(Slot card_slot, AllowMovieFolder allow_movie_fo if (use_movie_folder) path += "Movie" DIR_SEP; - const DiscIO::Region region = SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region); - path = path + SConfig::GetDirectoryForRegion(region) + DIR_SEP + + const DiscIO::Region region = Config::ToGameCubeRegion(SConfig::GetInstance().m_region); + path = path + Config::GetDirectoryForRegion(region) + DIR_SEP + fmt::format("Card {}", s_card_short_names[card_slot]); return {std::move(path), !use_movie_folder}; } @@ -227,7 +227,7 @@ void CEXIMemoryCard::SetupRawMemcard(u16 size_mb) } const std::string region_dir = - SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(SConfig::GetInstance().m_region)); + Config::GetDirectoryForRegion(Config::ToGameCubeRegion(SConfig::GetInstance().m_region)); MemoryCard::CheckPath(filename, region_dir, m_card_slot); if (size_mb < Memcard::MBIT_SIZE_MEMORY_CARD_2043) diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 30a0311910..cc1d9e6280 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -1470,8 +1470,8 @@ bool NetPlayServer::StartGame() const sf::Uint64 initial_rtc = GetInitialNetPlayRTC(); - const std::string region = SConfig::GetDirectoryForRegion( - SConfig::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game_identifier)->GetRegion())); + const std::string region = Config::GetDirectoryForRegion( + Config::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game_identifier)->GetRegion())); // sync GC SRAM with clients if (!g_SRAM_netplay_initialized) @@ -1666,7 +1666,7 @@ bool NetPlayServer::SyncSaveData() return true; const std::string region = - SConfig::GetDirectoryForRegion(SConfig::ToGameCubeRegion(game->GetRegion())); + Config::GetDirectoryForRegion(Config::ToGameCubeRegion(game->GetRegion())); for (ExpansionInterface::Slot slot : ExpansionInterface::MEMCARD_SLOTS) { diff --git a/Source/Core/DolphinQt/GameList/GameList.cpp b/Source/Core/DolphinQt/GameList/GameList.cpp index 03bc60e7b2..bebb6d81bf 100644 --- a/Source/Core/DolphinQt/GameList/GameList.cpp +++ b/Source/Core/DolphinQt/GameList/GameList.cpp @@ -713,7 +713,7 @@ void GameList::OpenGCSaveFolder() case ExpansionInterface::EXIDeviceType::MemoryCardFolder: { std::string path = StringFromFormat("%s/%s/%s", File::GetUserPath(D_GCUSER_IDX).c_str(), - SConfig::GetDirectoryForRegion(game->GetRegion()), + Config::GetDirectoryForRegion(game->GetRegion()), slot == Slot::A ? "Card A" : "Card B"); std::string override_path = Config::Get(Config::GetInfoForGCIPathOverride(slot)); diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index 1ace1276b8..a5b0adca99 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -1001,12 +1001,9 @@ void MenuBar::UpdateToolsMenu(bool emulation_started) { m_boot_sysmenu->setEnabled(!emulation_started); m_perform_online_update_menu->setEnabled(!emulation_started); - m_ntscj_ipl->setEnabled(!emulation_started && - File::Exists(SConfig::GetInstance().GetBootROMPath(JAP_DIR))); - m_ntscu_ipl->setEnabled(!emulation_started && - File::Exists(SConfig::GetInstance().GetBootROMPath(USA_DIR))); - m_pal_ipl->setEnabled(!emulation_started && - File::Exists(SConfig::GetInstance().GetBootROMPath(EUR_DIR))); + m_ntscj_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(JAP_DIR))); + m_ntscu_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(USA_DIR))); + m_pal_ipl->setEnabled(!emulation_started && File::Exists(Config::GetBootROMPath(EUR_DIR))); m_import_backup->setEnabled(!emulation_started); m_check_nand->setEnabled(!emulation_started);