mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Write Dalamud.Boot log to TEMP, then CWD (#886)
This commit is contained in:
parent
cd41fda202
commit
ce49874935
13 changed files with 22375 additions and 98 deletions
|
|
@ -1,7 +1,8 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "bootconfig.h"
|
||||
#include "DalamudStartInfo.h"
|
||||
#include "logging.h"
|
||||
#include "utils.h"
|
||||
#include "veh.h"
|
||||
#include "xivfixes.h"
|
||||
|
||||
|
|
@ -9,30 +10,69 @@ HMODULE g_hModule;
|
|||
HINSTANCE g_hGameInstance = GetModuleHandleW(nullptr);
|
||||
|
||||
DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
||||
if (bootconfig::is_show_console())
|
||||
MessageBoxW(nullptr, L"", L"", MB_OK);
|
||||
|
||||
g_startInfo.from_envvars();
|
||||
|
||||
std::string jsonParseError;
|
||||
try {
|
||||
from_json(nlohmann::json::parse(std::string_view(static_cast<char*>(lpParam))), g_startInfo);
|
||||
} catch (const std::exception& e) {
|
||||
jsonParseError = e.what();
|
||||
}
|
||||
|
||||
if (g_startInfo.BootShowConsole)
|
||||
ConsoleSetup(L"Dalamud Boot");
|
||||
|
||||
logging::update_dll_load_status(true);
|
||||
|
||||
auto attemptFallbackLog = false;
|
||||
if (const auto logFilePath = utils::get_env<std::wstring>("DALAMUD_BOOT_LOGFILE"); logFilePath.empty()) {
|
||||
if (!bootconfig::is_show_console() && !bootconfig::is_disable_fallback_console())
|
||||
ConsoleSetup(L"Dalamud Boot - Fallback Console");
|
||||
attemptFallbackLog = true;
|
||||
|
||||
logging::I("No log file path given; not logging to file.");
|
||||
} else {
|
||||
try {
|
||||
logging::start_file_logging(logFilePath, !bootconfig::is_show_console());
|
||||
logging::start_file_logging(logFilePath, !g_startInfo.BootShowConsole);
|
||||
logging::I("Logging to file: {}", logFilePath);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
if (!bootconfig::is_show_console() && !bootconfig::is_disable_fallback_console())
|
||||
ConsoleSetup(L"Dalamud Boot - Fallback Console");
|
||||
attemptFallbackLog = true;
|
||||
|
||||
logging::E("Couldn't open log file: {}", logFilePath);
|
||||
logging::E("Error: {} / {}", errno, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
if (!jsonParseError.empty())
|
||||
logging::E("Couldn't parse input JSON: {}", jsonParseError);
|
||||
|
||||
if (attemptFallbackLog) {
|
||||
std::wstring logFilePath(PATHCCH_MAX_CCH + 1, L'\0');
|
||||
logFilePath.resize(GetTempPathW(static_cast<DWORD>(logFilePath.size()), &logFilePath[0]));
|
||||
if (logFilePath.empty()) {
|
||||
logFilePath.resize(PATHCCH_MAX_CCH + 1);
|
||||
logFilePath.resize(GetCurrentDirectoryW(static_cast<DWORD>(logFilePath.size()), &logFilePath[0]));
|
||||
}
|
||||
if (!logFilePath.empty() && logFilePath.back() != '/' && logFilePath.back() != '\\')
|
||||
logFilePath += L"\\";
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
logFilePath += std::format(L"Dalamud.Boot.{:04}{:02}{:02}.{:02}{:02}{:02}.{:03}.{}.log", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds, GetCurrentProcessId());
|
||||
|
||||
try {
|
||||
logging::start_file_logging(logFilePath, !g_startInfo.BootShowConsole);
|
||||
logging::I("Logging to fallback log file: {}", logFilePath);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
if (!g_startInfo.BootShowConsole && !g_startInfo.BootDisableFallbackConsole)
|
||||
ConsoleSetup(L"Dalamud Boot - Fallback Console");
|
||||
|
||||
logging::E("Couldn't open fallback log file: {}", logFilePath);
|
||||
logging::E("Error: {} / {}", errno, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
auto minHookLoaded = false;
|
||||
if (const auto mhStatus = MH_Initialize(); mhStatus == MH_OK) {
|
||||
logging::I("MinHook initialized.");
|
||||
|
|
@ -47,7 +87,7 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
|||
logging::I("Dalamud.Boot Injectable, (c) 2021 XIVLauncher Contributors");
|
||||
logging::I("Built at: " __DATE__ "@" __TIME__);
|
||||
|
||||
if (bootconfig::wait_messagebox() & bootconfig::WaitMessageboxFlags::BeforeInitialize)
|
||||
if (static_cast<int>(g_startInfo.BootWaitMessageBox) & static_cast<int>(DalamudStartInfo::WaitMessageboxFlags::BeforeInitialize))
|
||||
MessageBoxW(nullptr, L"Press OK to continue", L"Dalamud Boot", MB_OK);
|
||||
|
||||
if (minHookLoaded) {
|
||||
|
|
@ -58,7 +98,7 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
|||
logging::W("Skipping fixes, as MinHook has failed to load.");
|
||||
}
|
||||
|
||||
if (bootconfig::is_wait_debugger()) {
|
||||
if (g_startInfo.BootWaitDebugger) {
|
||||
logging::I("Waiting for debugger to attach...");
|
||||
while (!IsDebuggerPresent())
|
||||
Sleep(100);
|
||||
|
|
@ -94,8 +134,8 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
|||
logging::I("Initializing VEH...");
|
||||
if (utils::is_running_on_linux()) {
|
||||
logging::I("=> VEH was disabled, running on linux");
|
||||
} else if (bootconfig::is_veh_enabled()) {
|
||||
if (veh::add_handler(bootconfig::is_veh_full()))
|
||||
} else if (g_startInfo.BootVehEnabled) {
|
||||
if (veh::add_handler(g_startInfo.BootVehFull))
|
||||
logging::I("=> Done!");
|
||||
else
|
||||
logging::I("=> Failed!");
|
||||
|
|
@ -105,7 +145,7 @@ DllExport DWORD WINAPI Initialize(LPVOID lpParam, HANDLE hMainThreadContinue) {
|
|||
|
||||
// ============================== Dalamud ==================================== //
|
||||
|
||||
if (bootconfig::wait_messagebox() & bootconfig::WaitMessageboxFlags::BeforeDalamudEntrypoint)
|
||||
if (static_cast<int>(g_startInfo.BootWaitMessageBox) & static_cast<int>(DalamudStartInfo::WaitMessageboxFlags::BeforeDalamudEntrypoint))
|
||||
MessageBoxW(nullptr, L"Press OK to continue", L"Dalamud Boot", MB_OK);
|
||||
|
||||
if (hMainThreadContinue) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue