Fixing various utf-8 issues + path to binary lookup.

Should fix #1600.
This commit is contained in:
Nicolas Pixel Noble 2024-03-26 21:42:56 -07:00
parent d8a4a56cf0
commit e2769a43b8
10 changed files with 184 additions and 4 deletions

View file

@ -545,7 +545,7 @@ void PCSX::GUI::init(std::function<void()> applyArguments) {
if (vg) {
g_system->findResource(
[vg](auto path) -> bool {
int res = nvgCreateFont(vg, "noto-sans-regular", path.string().c_str());
int res = nvgCreateFont(vg, "noto-sans-regular", (const char *)(path.u8string().c_str()));
return res >= 0;
},
MAKEU8("NotoSans-Regular.ttf"), "fonts", std::filesystem::path("third_party") / "noto");

View file

@ -37,6 +37,7 @@
#include "lua/luawrapper.h"
#include "main/textui.h"
#include "spu/interface.h"
#include "support/binpath.h"
#include "support/uvfile.h"
#include "support/version.h"
#include "tracy/Tracy.hpp"
@ -194,7 +195,7 @@ int pcsxMain(int argc, char **argv) {
const PCSX::u8string logfileArg = MAKEU8(logfileArgOpt.has_value() ? logfileArgOpt->c_str() : "");
if (!logfileArg.empty()) system->useLogfile(logfileArg);
PCSX::g_system = system;
std::filesystem::path self = argv[0];
std::filesystem::path self = PCSX::BinPath::getExecutablePath();
std::filesystem::path binDir = std::filesystem::absolute(self).parent_path();
system->setBinDir(binDir);
system->loadAllLocales();

View file

@ -0,0 +1,39 @@
/*
MIT License
Copyright (c) 2024 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "binpath.h"
#ifdef __linux__
#include <unistd.h>
std::u8string PCSX::BinPath::getExecutablePath() {
char8_t buffer[BUFSIZ];
readlink("/proc/self/exe", (char*)buffer, BUFSIZ);
return std::u8string(buffer);
}
#endif

View file

@ -0,0 +1,46 @@
/*
MIT License
Copyright (c) 2024 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "binpath.h"
#if defined(__APPLE__) && defined(__MACH__)
#include <CoreFoundation/CoreFoundation.h>
#include <stdexcept>
std::u8string PCSX::BinPath::getExecutablePath() {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef execURL = CFBundleCopyExecutableURL(mainBundle);
char8_t path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(execURL, TRUE, (UInt8 *)path, PATH_MAX)) {
throw std::runtime_error("Could not get executable path");
}
CFRelease(execURL);
return std::u8string(path);
}
#endif

View file

@ -0,0 +1,43 @@
/*
MIT License
Copyright (c) 2024 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Needs to stay on top
#include "windowswrapper.h"
// Because MSVC is a special snowflake
#include "binpath.h"
#ifdef _WIN32
std::u8string PCSX::BinPath::getExecutablePath() {
wchar_t path[MAX_PATH];
GetModuleFileNameW(nullptr, path, MAX_PATH);
auto needed = WideCharToMultiByte(CP_UTF8, 0, path, -1, NULL, 0, NULL, NULL);
std::u8string result(needed, 0);
WideCharToMultiByte(CP_UTF8, 0, path, -1, (LPSTR)result.data(), needed, NULL, NULL);
return result;
}
#endif

35
src/support/binpath.h Normal file
View file

@ -0,0 +1,35 @@
/*
MIT License
Copyright (c) 2024 PCSX-Redux authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <string>
namespace PCSX::BinPath {
std::u8string getExecutablePath();
} // namespace PCSX::BinPath

View file

@ -171,7 +171,7 @@ static FILE *openwrapper(const char *filename, const wchar_t *mode) {
int needed = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
if (needed <= 0) return nullptr;
LPWSTR str = (LPWSTR)_malloca(needed * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, filename, -1, str, needed * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, filename, -1, str, needed);
FILE *ret = _wfopen(str, mode);
_freea(str);
return ret;

2
third_party/zep vendored

@ -1 +1 @@
Subproject commit 325d622d191ab1a79c23737452e5be0b8644bf50
Subproject commit 5a7efc2611b4046aa8dfdc34640c12bd994e1c09

View file

@ -151,6 +151,7 @@
<ItemGroup>
<ClInclude Include="..\..\src\mips\common\util\sjis-table.h" />
<ClInclude Include="..\..\src\support\bezier.h" />
<ClInclude Include="..\..\src\support\binpath.h" />
<ClInclude Include="..\..\src\support\binstruct.h" />
<ClInclude Include="..\..\src\support\circular.h" />
<ClInclude Include="..\..\src\support\container-file.h" />
@ -202,6 +203,9 @@
<ClInclude Include="..\..\third_party\typestring.hh" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\support\binpath-linux.cc" />
<ClCompile Include="..\..\src\support\binpath-macos.cc" />
<ClCompile Include="..\..\src\support\binpath-windows.cc" />
<ClCompile Include="..\..\src\support\container-file.cc" />
<ClCompile Include="..\..\src\support\ffmpeg-audio-file.cc" />
<ClCompile Include="..\..\src\support\file.cc" />

View file

@ -171,6 +171,9 @@
<ClInclude Include="..\..\src\support\table-generator.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\support\binpath.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\support\file.cc">
@ -224,6 +227,15 @@
<ClCompile Include="..\..\src\support\sharedmem.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\support\binpath-linux.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\support\binpath-macos.cc">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\support\binpath-windows.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />