mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Common/CommonFuncs: Move interface into Common namespace
Gets these functions out of the global namespace.
This commit is contained in:
parent
361ffd5917
commit
f1ad43afaf
@ -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<std::wstring> GetModuleName(void* hInstance)
|
||||
return name;
|
||||
}
|
||||
#endif
|
||||
} // namespace Common
|
||||
|
@ -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<std::wstring> GetModuleName(void* hInstance);
|
||||
#endif
|
||||
} // namespace Common
|
||||
|
@ -170,7 +170,7 @@ static std::optional<std::wstring> 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)
|
||||
|
@ -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;
|
||||
|
@ -45,7 +45,8 @@ bool CEXIETHERNET::TAPServerNetworkInterface::Activate()
|
||||
|
||||
if (connect(fd, reinterpret_cast<sockaddr*>(&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())
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -373,7 +373,7 @@ bool UpdateFiles(const std::vector<TodoList::UpdateOp>& 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
|
||||
|
||||
|
@ -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.");
|
||||
|
Loading…
Reference in New Issue
Block a user