From 90dee823779b7196a392b039f1ad8dc1e67c974e Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Sat, 29 Jun 2024 08:15:57 +0300 Subject: [PATCH] more utf-8 with std::filesystem --- crash_printer/linux.cpp | 2 +- crash_printer/tests/test_linux_sa_handler.cpp | 2 +- crash_printer/tests/test_linux_sa_sigaction.cpp | 2 +- crash_printer/tests/test_win.cpp | 2 +- resources/win/file_dos_stub/file_dos_stub.cpp | 3 ++- tools/generate_interfaces/generate_interfaces.cpp | 5 +++-- tools/lobby_connect/lobby_connect.cpp | 6 +++--- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/crash_printer/linux.cpp b/crash_printer/linux.cpp index dc38cd1e..e1e5864f 100644 --- a/crash_printer/linux.cpp +++ b/crash_printer/linux.cpp @@ -50,7 +50,7 @@ static void exception_handler(int signal, siginfo_t *info, void *context, struct return; } - std::ofstream file(logs_filepath, std::ios::app); + std::ofstream file(std::filesystem::u8path(logs_filepath), std::ios::app); std::string time(common_helpers::get_utc_time()); common_helpers::write(file, "[" + time + "]"); diff --git a/crash_printer/tests/test_linux_sa_handler.cpp b/crash_printer/tests/test_linux_sa_handler.cpp index 67e0054a..908d410d 100644 --- a/crash_printer/tests/test_linux_sa_handler.cpp +++ b/crash_printer/tests/test_linux_sa_handler.cpp @@ -15,7 +15,7 @@ std::string logs_filepath = "./crash_test/asd.txt"; // sa_sigaction handler for illegal instruction (SIGILL) void exception_handler_SIGILL(int signal) { - std::ifstream file(logs_filepath); + std::ifstream file(std::filesystem::u8path(logs_filepath)); if (file.is_open()) { std::string line{}; std::getline(file, line); diff --git a/crash_printer/tests/test_linux_sa_sigaction.cpp b/crash_printer/tests/test_linux_sa_sigaction.cpp index ac56f2ed..09113618 100644 --- a/crash_printer/tests/test_linux_sa_sigaction.cpp +++ b/crash_printer/tests/test_linux_sa_sigaction.cpp @@ -15,7 +15,7 @@ std::string logs_filepath = "./crash_test/asd.txt"; // sa_handler handler for illegal instruction (SIGILL) void exception_handler_SIGILL(int signal, siginfo_t *info, void *context) { - std::ifstream file(logs_filepath); + std::ifstream file(std::filesystem::u8path(logs_filepath)); if (file.is_open()) { std::string line{}; std::getline(file, line); diff --git a/crash_printer/tests/test_win.cpp b/crash_printer/tests/test_win.cpp index 0c027a15..055987ce 100644 --- a/crash_printer/tests/test_win.cpp +++ b/crash_printer/tests/test_win.cpp @@ -13,7 +13,7 @@ std::string logs_filepath = "./crash_test/zxc.txt"; static LONG WINAPI exception_handler(LPEXCEPTION_POINTERS ex_pointers) { - std::ifstream file(logs_filepath); + std::ifstream file(std::filesystem::u8path(logs_filepath)); if (file.is_open()) { std::string line{}; std::getline(file, line); diff --git a/resources/win/file_dos_stub/file_dos_stub.cpp b/resources/win/file_dos_stub/file_dos_stub.cpp index 3f3097d4..fe537a55 100644 --- a/resources/win/file_dos_stub/file_dos_stub.cpp +++ b/resources/win/file_dos_stub/file_dos_stub.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "pe_helpers/pe_helpers.hpp" @@ -57,7 +58,7 @@ int main(int argc, char* *argv) for (size_t i = 1; i < (size_t)argc; ++i) { auto arg = argv[i]; - std::fstream file(arg, std::ios::in | std::ios::out | std::ios::binary); + std::fstream file(std::filesystem::u8path(arg), std::ios::in | std::ios::out | std::ios::binary); if (!file.is_open()) { std::cerr << "Failed to open file: '" << arg << "'" << std::endl; return 1; diff --git a/tools/generate_interfaces/generate_interfaces.cpp b/tools/generate_interfaces/generate_interfaces.cpp index a9c164a5..b06e676b 100644 --- a/tools/generate_interfaces/generate_interfaces.cpp +++ b/tools/generate_interfaces/generate_interfaces.cpp @@ -3,6 +3,7 @@ #include #include #include +#include // these are defined in dll.cpp at the top like this: // static char old_xxx[128] = ... @@ -67,7 +68,7 @@ int main (int argc, char *argv[]) return 1; } - std::ifstream steam_api_file(argv[1], std::ios::binary); + std::ifstream steam_api_file(std::filesystem::u8path(argv[1]), std::ios::binary); if (!steam_api_file.is_open()) { std::cerr << "Error opening file" << std::endl; return 1; @@ -84,7 +85,7 @@ int main (int argc, char *argv[]) } unsigned int total_matches = 0; - std::ofstream out_file("steam_interfaces.txt"); + std::ofstream out_file(std::filesystem::u8path("steam_interfaces.txt")); if (!out_file.is_open()) { std::cerr << "Error opening output file" << std::endl; return 1; diff --git a/tools/lobby_connect/lobby_connect.cpp b/tools/lobby_connect/lobby_connect.cpp index 45257a46..3478f3b3 100644 --- a/tools/lobby_connect/lobby_connect.cpp +++ b/tools/lobby_connect/lobby_connect.cpp @@ -109,19 +109,19 @@ top: auto readLobbyFile = [&lobbyFile]() { std::string data; - std::ifstream ifs(lobbyFile); + std::ifstream ifs(std::filesystem::u8path(lobbyFile)); if (ifs.is_open()) std::getline(ifs, data); return data; }; auto writeLobbyFile = [&lobbyFile](const std::string& data) { - std::ofstream ofs(lobbyFile); + std::ofstream ofs(std::filesystem::u8path(lobbyFile)); ofs << data << std::endl; }; auto fileExists = [](const std::string& filename) { - std::ifstream ifs(filename); + std::ifstream ifs(std::filesystem::u8path(filename)); return ifs.is_open(); };