From f1ad43afafe72fcad67d5ff39469442a2740213f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 18 Apr 2023 12:50:31 -0400 Subject: [PATCH] Common/CommonFuncs: Move interface into Common namespace Gets these functions out of the global namespace. --- Source/Core/Common/CommonFuncs.cpp | 3 +++ Source/Core/Common/CommonFuncs.h | 3 +++ Source/Core/Common/CompatPatches.cpp | 2 +- Source/Core/Common/FileUtil.cpp | 8 ++++---- Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp | 7 ++++--- Source/Core/UICommon/AutoUpdate.cpp | 4 ++-- Source/Core/UpdaterCommon/UpdaterCommon.cpp | 2 +- Source/Core/WinUpdater/Main.cpp | 2 +- 8 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Source/Core/Common/CommonFuncs.cpp b/Source/Core/Common/CommonFuncs.cpp index 68834209b3..4fdefa3a67 100644 --- a/Source/Core/Common/CommonFuncs.cpp +++ b/Source/Core/Common/CommonFuncs.cpp @@ -13,6 +13,8 @@ #define strerror_r(err, buf, len) strerror_s(buf, len, err) #endif +namespace Common +{ constexpr size_t BUFFER_SIZE = 256; // Wrapper function to get last strerror(errno) string. @@ -73,3 +75,4 @@ std::optional GetModuleName(void* hInstance) return name; } #endif +} // namespace Common diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h index db6b8643a1..cd8dbe94ac 100644 --- a/Source/Core/Common/CommonFuncs.h +++ b/Source/Core/Common/CommonFuncs.h @@ -39,6 +39,8 @@ __declspec(dllimport) void __stdcall DebugBreak(void); } #endif // WIN32 ndef +namespace Common +{ // Wrapper function to get last strerror(errno) string. // This function might change the error code. std::string LastStrerrorString(); @@ -51,3 +53,4 @@ std::string GetLastErrorString(); // Obtains a full path to the specified module. std::optional GetModuleName(void* hInstance); #endif +} // namespace Common diff --git a/Source/Core/Common/CompatPatches.cpp b/Source/Core/Common/CompatPatches.cpp index da211248b5..5b99658665 100644 --- a/Source/Core/Common/CompatPatches.cpp +++ b/Source/Core/Common/CompatPatches.cpp @@ -170,7 +170,7 @@ static std::optional GetModulePath(const wchar_t* name) if (module == nullptr) return std::nullopt; - return GetModuleName(module); + return Common::GetModuleName(module); } static bool GetModuleVersion(const wchar_t* name, Version* version) diff --git a/Source/Core/Common/FileUtil.cpp b/Source/Core/Common/FileUtil.cpp index a9e7c35946..9a494ab2e0 100644 --- a/Source/Core/Common/FileUtil.cpp +++ b/Source/Core/Common/FileUtil.cpp @@ -358,14 +358,14 @@ u64 GetSize(FILE* f) const u64 pos = ftello(f); if (fseeko(f, 0, SEEK_END) != 0) { - ERROR_LOG_FMT(COMMON, "GetSize: seek failed {}: {}", fmt::ptr(f), LastStrerrorString()); + ERROR_LOG_FMT(COMMON, "GetSize: seek failed {}: {}", fmt::ptr(f), Common::LastStrerrorString()); return 0; } const u64 size = ftello(f); if ((size != pos) && (fseeko(f, pos, SEEK_SET) != 0)) { - ERROR_LOG_FMT(COMMON, "GetSize: seek failed {}: {}", fmt::ptr(f), LastStrerrorString()); + ERROR_LOG_FMT(COMMON, "GetSize: seek failed {}: {}", fmt::ptr(f), Common::LastStrerrorString()); return 0; } @@ -379,7 +379,7 @@ bool CreateEmptyFile(const std::string& filename) if (!File::IOFile(filename, "wb")) { - ERROR_LOG_FMT(COMMON, "CreateEmptyFile: failed {}: {}", filename, LastStrerrorString()); + ERROR_LOG_FMT(COMMON, "CreateEmptyFile: failed {}: {}", filename, Common::LastStrerrorString()); return false; } @@ -726,7 +726,7 @@ std::string GetBundleDirectory() std::string GetExePath() { #ifdef _WIN32 - auto exe_path = GetModuleName(nullptr); + auto exe_path = Common::GetModuleName(nullptr); if (!exe_path) return {}; std::error_code error; diff --git a/Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp b/Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp index 77a8f74a9c..de71067c1b 100644 --- a/Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp +++ b/Source/Core/Core/HW/EXI/BBA/TAPServer_Apple.cpp @@ -45,7 +45,8 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate() if (connect(fd, reinterpret_cast(&sun), sizeof(sun)) == -1) { - ERROR_LOG_FMT(SP1, "Couldn't connect socket ({}), unable to init BBA", LastStrerrorString()); + ERROR_LOG_FMT(SP1, "Couldn't connect socket ({}), unable to init BBA", + Common::LastStrerrorString()); close(fd); fd = -1; return false; @@ -99,14 +100,14 @@ void CEXIETHERNET::TAPServerNetworkInterface::ReadThreadHandler() u16 size; if (read(fd, &size, 2) != 2) { - ERROR_LOG_FMT(SP1, "Failed to read size field from BBA: {}", LastStrerrorString()); + ERROR_LOG_FMT(SP1, "Failed to read size field from BBA: {}", Common::LastStrerrorString()); } else { int read_bytes = read(fd, m_eth_ref->mRecvBuffer.get(), size); if (read_bytes < 0) { - ERROR_LOG_FMT(SP1, "Failed to read packet data from BBA: {}", LastStrerrorString()); + ERROR_LOG_FMT(SP1, "Failed to read packet data from BBA: {}", Common::LastStrerrorString()); } else if (readEnabled.IsSet()) { diff --git a/Source/Core/UICommon/AutoUpdate.cpp b/Source/Core/UICommon/AutoUpdate.cpp index a638ae33a6..e8de74c794 100644 --- a/Source/Core/UICommon/AutoUpdate.cpp +++ b/Source/Core/UICommon/AutoUpdate.cpp @@ -299,13 +299,13 @@ void AutoUpdateChecker::TriggerUpdate(const AutoUpdateChecker::NewVersionInforma } else { - const std::string error = GetLastErrorString(); + const std::string error = Common::GetLastErrorString(); CriticalAlertFmtT("Could not start updater process: {0}", error); } #else if (popen(command_line.c_str(), "r") == nullptr) { - const std::string error = LastStrerrorString(); + const std::string error = Common::LastStrerrorString(); CriticalAlertFmtT("Could not start updater process: {0}", error); } #endif diff --git a/Source/Core/UpdaterCommon/UpdaterCommon.cpp b/Source/Core/UpdaterCommon/UpdaterCommon.cpp index 9dd40c679f..bba12b8f48 100644 --- a/Source/Core/UpdaterCommon/UpdaterCommon.cpp +++ b/Source/Core/UpdaterCommon/UpdaterCommon.cpp @@ -373,7 +373,7 @@ bool UpdateFiles(const std::vector& to_update, const std::string& install_base_path, const std::string& temp_path) { #ifdef _WIN32 - const auto self_path = std::filesystem::path(GetModuleName(nullptr).value()); + const auto self_path = std::filesystem::path(Common::GetModuleName(nullptr).value()); const auto self_filename = self_path.filename(); #endif diff --git a/Source/Core/WinUpdater/Main.cpp b/Source/Core/WinUpdater/Main.cpp index 6b7fd801ef..11997822e8 100644 --- a/Source/Core/WinUpdater/Main.cpp +++ b/Source/Core/WinUpdater/Main.cpp @@ -31,7 +31,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine // Test for write permissions bool need_admin = false; - auto path = GetModuleName(hInstance); + auto path = Common::GetModuleName(hInstance); if (!path) { UI::Error("Failed to get updater filename.");