Skip to content

Commit

Permalink
Strings are assumed UTF-8 with fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Dec 2, 2024
1 parent ce27b87 commit 061f27d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 50 deletions.
30 changes: 0 additions & 30 deletions common/strutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,6 @@ std::wstring utf8_to_wstr(std::string_view str)

return ret;
}

std::string wstr_to_acp(std::wstring_view wstr)
{
std::string ret;

const auto len = WideCharToMultiByte(CP_ACP, 0, wstr.data(), al::sizei(wstr), nullptr, 0,
nullptr, nullptr);
if(len > 0)
{
ret.resize(static_cast<size_t>(len));
WideCharToMultiByte(CP_ACP, 0, wstr.data(), al::sizei(wstr), ret.data(), len, nullptr,
nullptr);
}

return ret;
}

std::wstring acp_to_wstr(std::string_view str)
{
std::wstring ret;

const auto len = MultiByteToWideChar(CP_ACP, 0, str.data(), al::sizei(str), nullptr, 0);
if(len > 0)
{
ret.resize(static_cast<size_t>(len));
MultiByteToWideChar(CP_ACP, 0, str.data(), al::sizei(str), ret.data(), len);
}

return ret;
}
/* NOLINTEND(bugprone-suspicious-stringview-data-usage) */
#endif

Expand Down
3 changes: 0 additions & 3 deletions common/strutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

std::string wstr_to_utf8(std::wstring_view wstr);
std::wstring utf8_to_wstr(std::string_view str);

std::string wstr_to_acp(std::wstring_view wstr);
std::wstring acp_to_wstr(std::string_view str);
#endif

namespace al {
Expand Down
2 changes: 1 addition & 1 deletion router/alc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void InitCtxFuncs(DriverIface &iface)
iface.x = reinterpret_cast<decltype(iface.x)>(iface.alGetProcAddress(#x));\
if(!iface.x) \
ERR("Failed to find entry point for {} in {}", #x, \
wstr_to_acp(iface.Name)); \
wstr_to_utf8(iface.Name)); \
} while(0)
if(iface.alcIsExtensionPresent(device, "ALC_EXT_EFX"))
{
Expand Down
32 changes: 16 additions & 16 deletions router/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
}
if(drv->Name == name)
{
TRACE("Skipping similarly-named module {}", wstr_to_acp(name));
TRACE("Skipping similarly-named module {}", wstr_to_utf8(name));
FreeLibrary(module);
return;
}
Expand All @@ -56,7 +56,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
{ return al::case_compare(name, accept) == 0; });
if(iter == gAcceptList.cend())
{
TRACE("{} not found in ALROUTER_ACCEPT, skipping", wstr_to_acp(name));
TRACE("{} not found in ALROUTER_ACCEPT, skipping", wstr_to_utf8(name));
FreeLibrary(module);
return;
}
Expand All @@ -68,7 +68,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
{ return al::case_compare(name, accept) == 0; });
if(iter != gRejectList.cend())
{
TRACE("{} found in ALROUTER_REJECT, skipping", wstr_to_acp(name));
TRACE("{} found in ALROUTER_REJECT, skipping", wstr_to_utf8(name));
FreeLibrary(module);
return;
}
Expand All @@ -84,7 +84,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
auto ptr = GetProcAddress(module, fname);
if(!ptr)
{
ERR("Failed to find entry point for {} in {}", fname, wstr_to_acp(name));
ERR("Failed to find entry point for {} in {}", fname, wstr_to_utf8(name));
return false;
}

Expand Down Expand Up @@ -184,7 +184,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
newdrv.ALCVer = MAKE_ALC_VER(alc_ver[0], alc_ver[1]);
else
{
WARN("Failed to query ALC version for {}, assuming 1.0", wstr_to_acp(name));
WARN("Failed to query ALC version for {}, assuming 1.0", wstr_to_utf8(name));
newdrv.ALCVer = MAKE_ALC_VER(1, 0);
}

Expand All @@ -194,7 +194,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
auto ptr = GetProcAddress(module, fname);
if(!ptr)
WARN("Failed to find optional entry point for {} in {}", fname,
wstr_to_acp(name));
wstr_to_utf8(name));
else
func = al::bit_cast<func_t>(ptr);
};
Expand All @@ -219,7 +219,7 @@ void AddModule(HMODULE module, const std::wstring_view name)
auto ptr = newdrv.alcGetProcAddress(nullptr, fname);
if(!ptr)
{
ERR("Failed to find entry point for {} in {}", fname, wstr_to_acp(name));
ERR("Failed to find entry point for {} in {}", fname, wstr_to_utf8(name));
return false;
}

Expand All @@ -241,12 +241,12 @@ void AddModule(HMODULE module, const std::wstring_view name)
return;
}
TRACE("Loaded module {}, {}, ALC {}.{}", decltype(std::declval<void*>()){module},
wstr_to_acp(name), newdrv.ALCVer>>8, newdrv.ALCVer&255);
wstr_to_utf8(name), newdrv.ALCVer>>8, newdrv.ALCVer&255);
}

void SearchDrivers(const std::wstring_view path)
{
TRACE("Searching for drivers in {}...", wstr_to_acp(path));
TRACE("Searching for drivers in {}...", wstr_to_utf8(path));
std::wstring srchPath{path};
srchPath += L"\\*oal.dll";

Expand All @@ -258,11 +258,11 @@ void SearchDrivers(const std::wstring_view path)
srchPath = path;
srchPath += L"\\";
srchPath += std::data(fdata.cFileName);
TRACE("Found {}", wstr_to_acp(srchPath));
TRACE("Found {}", wstr_to_utf8(srchPath));

HMODULE mod{LoadLibraryW(srchPath.c_str())};
if(!mod)
WARN("Could not load {}", wstr_to_acp(srchPath));
WARN("Could not load {}", wstr_to_utf8(srchPath));
else
AddModule(mod, std::data(fdata.cFileName));
} while(FindNextFileW(srchHdl, &fdata));
Expand Down Expand Up @@ -337,7 +337,7 @@ void LoadDriverList()

std::wstring dll_path;
if(GetLoadedModuleDirectory(L"OpenAL32.dll", &dll_path))
TRACE("Got DLL path {}", wstr_to_acp(dll_path));
TRACE("Got DLL path {}", wstr_to_utf8(dll_path));

std::wstring cwd_path;
if(DWORD pathlen{GetCurrentDirectoryW(0, nullptr)})
Expand All @@ -351,11 +351,11 @@ void LoadDriverList()
if(!cwd_path.empty() && (cwd_path.back() == '\\' || cwd_path.back() == '/'))
cwd_path.pop_back();
if(!cwd_path.empty())
TRACE("Got current working directory {}", wstr_to_acp(cwd_path));
TRACE("Got current working directory {}", wstr_to_utf8(cwd_path));

std::wstring proc_path;
if(GetLoadedModuleDirectory(nullptr, &proc_path))
TRACE("Got proc path {}", wstr_to_acp(proc_path));
TRACE("Got proc path {}", wstr_to_utf8(proc_path));

std::wstring sys_path;
if(UINT pathlen{GetSystemDirectoryW(nullptr, 0)})
Expand All @@ -369,7 +369,7 @@ void LoadDriverList()
if(!sys_path.empty() && (sys_path.back() == '\\' || sys_path.back() == '/'))
sys_path.pop_back();
if(!sys_path.empty())
TRACE("Got system path {}", wstr_to_acp(sys_path));
TRACE("Got system path {}", wstr_to_utf8(sys_path));

/* Don't search the DLL's path if it is the same as the current working
* directory, app's path, or system path (don't want to do duplicate
Expand Down Expand Up @@ -401,7 +401,7 @@ BOOL APIENTRY DllMain(HINSTANCE, DWORD reason, void*)
{
gsl::owner<std::FILE*> f{_wfopen(logfname->c_str(), L"w")};
if(f == nullptr)
ERR("Could not open log file: {}", wstr_to_acp(*logfname));
ERR("Could not open log file: {}", wstr_to_utf8(*logfname));
else
LogFile = f;
}
Expand Down

0 comments on commit 061f27d

Please sign in to comment.