From 26bcfac7d162d0ca71baaa347a263444f233207c Mon Sep 17 00:00:00 2001 From: Nick Koirala Date: Mon, 17 Nov 2025 19:14:27 +1300 Subject: [PATCH] feat: attempts to fix logging issue --- .vscode/settings.json | 20 +++++++++++- imgui.ini | 26 ++++++++-------- scripts/update.as | 2 +- src/GuiManager.cpp | 72 +++++++++++++++++++++++++++++++++++++------ 4 files changed, 95 insertions(+), 25 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 6715a50..64d298f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -72,6 +72,24 @@ "typeinfo": "cpp", "variant": "cpp", "format": "cpp", - "*.m": "cpp" + "*.m": "cpp", + "filesystem": "cpp", + "forward_list": "cpp", + "ios": "cpp", + "locale": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp" } } \ No newline at end of file diff --git a/imgui.ini b/imgui.ini index 4dcc263..fecbc7a 100644 --- a/imgui.ini +++ b/imgui.ini @@ -9,34 +9,34 @@ Size=400,400 Collapsed=0 [Window][Game Window] -Pos=8,25 -Size=1264,581 +Pos=8,29 +Size=1264,360 Collapsed=0 DockId=0x00000001,0 [Window][Log Viewer] -Pos=8,608 -Size=1264,104 +Pos=8,391 +Size=1264,321 Collapsed=0 DockId=0x00000002,0 [Window][##TOAST0] -Pos=1062,643 -Size=198,57 +Pos=1010,635 +Size=250,65 Collapsed=0 [Window][##TOAST1] -Pos=1062,576 -Size=198,57 +Pos=1010,560 +Size=250,65 Collapsed=0 [Window][##TOAST2] -Pos=1062,509 -Size=198,57 +Pos=1010,485 +Size=250,65 Collapsed=0 [Docking][Data] -DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,25 Size=1264,687 Split=Y Selected=0x27A02DAA - DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=1264,579 CentralNode=1 Selected=0x27A02DAA - DockNode ID=0x00000002 Parent=0x9076BACA SizeRef=1264,104 Selected=0xBEDDA0C1 +DockSpace ID=0x9076BACA Window=0x34F970D7 Pos=8,29 Size=1264,683 Split=Y Selected=0x27A02DAA + DockNode ID=0x00000001 Parent=0x9076BACA SizeRef=1264,360 CentralNode=1 Selected=0x27A02DAA + DockNode ID=0x00000002 Parent=0x9076BACA SizeRef=1264,321 Selected=0xBEDDA0C1 diff --git a/scripts/update.as b/scripts/update.as index 81b075a..9ab5d7d 100644 --- a/scripts/update.as +++ b/scripts/update.as @@ -2,7 +2,7 @@ float x = 50; float y = 100; void Update(float dt) { - x += 500 * dt; + x += 640 * dt; if (x > 800) { x = 0; Print("X position reset!"); diff --git a/src/GuiManager.cpp b/src/GuiManager.cpp index 2bf66bf..92018d8 100644 --- a/src/GuiManager.cpp +++ b/src/GuiManager.cpp @@ -5,6 +5,14 @@ #include #include "log.h" #include "Application.h" +#include // Add this for cross-platform file handling + +#ifdef _WIN32 +#include +#include +#include +#undef ShowCursor // Prevent conflict with Windows API +#endif GuiManager::GuiManager() {} @@ -103,19 +111,63 @@ void GuiManager::SetupDockspace(RenderTexture2D &renderTexture) static std::string logContent; static size_t lastFileSize = 0; - // Read the log file if it has changed - std::ifstream logFile("log.txt", std::ios::ate); // Open at the end to get the file size - if (logFile.is_open()) + // Use std::filesystem to construct the log file path + std::filesystem::path logFilePath = std::filesystem::current_path() / "log.txt"; + + // Debugging: Print the log file path to the console + std::cout << "Log file path: " << logFilePath << std::endl; + + // Check if the log file exists + if (std::filesystem::exists(logFilePath)) { - size_t fileSize = logFile.tellg(); - if (fileSize != lastFileSize) +#ifdef _WIN32 + // Convert the path to a narrow-character string + std::string logFilePathStr = logFilePath.string(); + + // Open the file with shared access on Windows + HANDLE hFile = CreateFileA(logFilePathStr.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile != INVALID_HANDLE_VALUE) { - lastFileSize = fileSize; - logFile.seekg(0, std::ios::beg); // Go back to the beginning - logContent.assign((std::istreambuf_iterator(logFile)), - std::istreambuf_iterator()); + LARGE_INTEGER fileSize; + if (GetFileSizeEx(hFile, &fileSize) && fileSize.QuadPart != lastFileSize) + { + lastFileSize = static_cast(fileSize.QuadPart); + logContent.resize(lastFileSize); + + DWORD bytesRead; + SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + ReadFile(hFile, logContent.data(), static_cast(lastFileSize), &bytesRead, NULL); + } + CloseHandle(hFile); } - logFile.close(); + else + { + std::cerr << "Failed to open log file with shared access: " << logFilePath << std::endl; + } +#else + // Standard file reading for non-Windows platforms + std::ifstream logFile(logFilePath, std::ios::ate); + if (logFile.is_open()) + { + size_t fileSize = logFile.tellg(); + if (fileSize != lastFileSize) + { + lastFileSize = fileSize; + logFile.seekg(0, std::ios::beg); + logContent.assign((std::istreambuf_iterator(logFile)), + std::istreambuf_iterator()); + } + logFile.close(); + } + else + { + std::cerr << "Failed to open log file: " << logFilePath << std::endl; + } +#endif + } + else + { + std::cerr << "Log file does not exist: " << logFilePath << std::endl; } // Display the log content in a scrollable text area