From edc5826fe032c3063b53343e26152fe18a47f333 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Thu, 15 Feb 2024 03:55:00 +0900 Subject: [PATCH 1/2] Dalamud.Boot: use unicode::convert --- Dalamud.Boot/utils.cpp | 10 ---------- Dalamud.Boot/utils.h | 2 -- Dalamud.Boot/veh.cpp | 14 +++++++------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/Dalamud.Boot/utils.cpp b/Dalamud.Boot/utils.cpp index 62a9d7055..9dc296c5f 100644 --- a/Dalamud.Boot/utils.cpp +++ b/Dalamud.Boot/utils.cpp @@ -578,16 +578,6 @@ std::vector utils::get_env_list(const wchar_t* pcszName) { return res; } -std::wstring utils::to_wstring(const std::string& str) { - if (str.empty()) return std::wstring(); - size_t convertedChars = 0; - size_t newStrSize = str.size() + 1; - std::wstring wstr(newStrSize, L'\0'); - mbstowcs_s(&convertedChars, &wstr[0], newStrSize, str.c_str(), _TRUNCATE); - wstr.resize(convertedChars - 1); - return wstr; -} - std::filesystem::path utils::get_module_path(HMODULE hModule) { std::wstring buf(MAX_PATH, L'\0'); while (true) { diff --git a/Dalamud.Boot/utils.h b/Dalamud.Boot/utils.h index ebf48a294..85509cf38 100644 --- a/Dalamud.Boot/utils.h +++ b/Dalamud.Boot/utils.h @@ -264,8 +264,6 @@ namespace utils { return get_env_list(unicode::convert(pcszName).c_str()); } - std::wstring to_wstring(const std::string& str); - std::filesystem::path get_module_path(HMODULE hModule); /// @brief Find the game main window. diff --git a/Dalamud.Boot/veh.cpp b/Dalamud.Boot/veh.cpp index eb27acce7..fc8689af7 100644 --- a/Dalamud.Boot/veh.cpp +++ b/Dalamud.Boot/veh.cpp @@ -110,13 +110,13 @@ static void append_injector_launch_args(std::vector& args) case DalamudStartInfo::LoadMethod::DllInject: args.emplace_back(L"--mode=inject"); } - args.emplace_back(L"--logpath=\"" + utils::to_wstring(g_startInfo.BootLogPath) + L"\""); - args.emplace_back(L"--dalamud-working-directory=\"" + utils::to_wstring(g_startInfo.WorkingDirectory) + L"\""); - args.emplace_back(L"--dalamud-configuration-path=\"" + utils::to_wstring(g_startInfo.ConfigurationPath) + L"\""); - args.emplace_back(L"--dalamud-plugin-directory=\"" + utils::to_wstring(g_startInfo.PluginDirectory) + L"\""); - args.emplace_back(L"--dalamud-asset-directory=\"" + utils::to_wstring(g_startInfo.AssetDirectory) + L"\""); - args.emplace_back(L"--dalamud-client-language=" + std::to_wstring(static_cast(g_startInfo.Language))); - args.emplace_back(L"--dalamud-delay-initialize=" + std::to_wstring(g_startInfo.DelayInitializeMs)); + args.emplace_back(L"--logpath=\"" + unicode::convert(g_startInfo.BootLogPath) + L"\""); + args.emplace_back(L"--dalamud-working-directory=\"" + unicode::convert(g_startInfo.WorkingDirectory) + L"\""); + args.emplace_back(L"--dalamud-configuration-path=\"" + unicode::convert(g_startInfo.ConfigurationPath) + L"\""); + args.emplace_back(L"--dalamud-plugin-directory=\"" + unicode::convert(g_startInfo.PluginDirectory) + L"\""); + args.emplace_back(L"--dalamud-asset-directory=\"" + unicode::convert(g_startInfo.AssetDirectory) + L"\""); + args.emplace_back(std::format(L"--dalamud-client-language={}", static_cast(g_startInfo.Language))); + args.emplace_back(std::format(L"--dalamud-delay-initialize={}", g_startInfo.DelayInitializeMs)); if (g_startInfo.BootShowConsole) args.emplace_back(L"--console"); if (g_startInfo.BootEnableEtw) From cce4f03403aecf5d72bac29f6b71673e390dea86 Mon Sep 17 00:00:00 2001 From: Soreepeong Date: Thu, 15 Feb 2024 04:14:23 +0900 Subject: [PATCH 2/2] Adjust logDir if logDir points to a .log file --- DalamudCrashHandler/DalamudCrashHandler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/DalamudCrashHandler/DalamudCrashHandler.cpp b/DalamudCrashHandler/DalamudCrashHandler.cpp index 1930b6fb4..4e2f01708 100644 --- a/DalamudCrashHandler/DalamudCrashHandler.cpp +++ b/DalamudCrashHandler/DalamudCrashHandler.cpp @@ -518,6 +518,7 @@ void export_tspack(HWND hWndParent, const std::filesystem::path& logDir, const s mz_throw_if_failed(mz_zip_writer_init_v2(&zipa, 0, 0), "mz_zip_writer_init_v2"); mz_throw_if_failed(mz_zip_writer_add_mem(&zipa, "trouble.json", troubleshootingPackData.data(), troubleshootingPackData.size(), MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE | MZ_BEST_COMPRESSION), "mz_zip_writer_add_mem: trouble.json"); mz_throw_if_failed(mz_zip_writer_add_mem(&zipa, "crash.log", crashLog.data(), crashLog.size(), MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE | MZ_BEST_COMPRESSION), "mz_zip_writer_add_mem: crash.log"); + std::string logExportLog; struct HandleAndBaseOffset { HANDLE h; @@ -534,8 +535,12 @@ void export_tspack(HWND hWndParent, const std::filesystem::path& logDir, const s }; for (const auto& pcszLogFileName : SourceLogFiles) { const auto logFilePath = logDir / pcszLogFileName; - if (!exists(logFilePath)) + if (!exists(logFilePath)) { + logExportLog += std::format("File does not exist: {}\n", ws_to_u8(logFilePath.wstring())); continue; + } else { + logExportLog += std::format("Including: {}\n", ws_to_u8(logFilePath.wstring())); + } const auto hLogFile = CreateFileW(logFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); if (hLogFile == INVALID_HANDLE_VALUE) @@ -574,6 +579,7 @@ void export_tspack(HWND hWndParent, const std::filesystem::path& logDir, const s ), std::format("mz_zip_writer_add_read_buf_callback({})", ws_to_u8(logFilePath.wstring()))); } + mz_throw_if_failed(mz_zip_writer_add_mem(&zipa, "logexport.log", logExportLog.data(), logExportLog.size(), MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE | MZ_BEST_COMPRESSION), "mz_zip_writer_add_mem: logexport.log"); mz_throw_if_failed(mz_zip_writer_finalize_archive(&zipa), "mz_zip_writer_finalize_archive"); mz_throw_if_failed(mz_zip_writer_end(&zipa), "mz_zip_writer_end"); @@ -710,6 +716,13 @@ int main() { return InvalidParameter; } + if (logDir.filename().wstring().ends_with(L".log")) { + std::wcout << L"logDir seems to be pointing to a file; stripping the last path component.\n" << std::endl; + std::wcout << L"Previous: " << logDir.wstring() << std::endl; + logDir = logDir.parent_path(); + std::wcout << L"Stripped: " << logDir.wstring() << std::endl; + } + while (true) { std::cout << "Waiting for crash...\n";