From 2b558a960616acbdae2a3e762dae5eec14993a64 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sun, 14 Feb 2016 12:29:05 +0000 Subject: [PATCH] lilypad: Make command/response debug output portable It also makes the log viewable in Windows Notepad. Also fix an off-by-one and fix the missing C++ exception settings. --- plugins/LilyPad/LilyPad.cpp | 70 ++++++++++++++++----------------- plugins/LilyPad/LilyPad.vcxproj | 4 -- 2 files changed, 33 insertions(+), 41 deletions(-) diff --git a/plugins/LilyPad/LilyPad.cpp b/plugins/LilyPad/LilyPad.cpp index a0ff878f56..d39662183f 100644 --- a/plugins/LilyPad/LilyPad.cpp +++ b/plugins/LilyPad/LilyPad.cpp @@ -19,6 +19,9 @@ // For escape timer, so as not to break GSDX+DX9. #include +#include +#include +#include #include "resource.h" #include "InputManager.h" #include "Config.h" @@ -109,55 +112,48 @@ int IsWindowMaximized (HWND hWnd) { #endif void DEBUG_TEXT_OUT(const char *text) { -#ifdef _MSC_VER - if (config.debug) { - HANDLE hFile = CreateFileA("logs\\padLog.txt", FILE_APPEND_DATA, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); - if (hFile != INVALID_HANDLE_VALUE) { - DWORD junk; - WriteFile(hFile, text, strlen(text), &junk, 0); - CloseHandle(hFile);; - } - } -#endif + if (!config.debug) + return; + + std::ofstream file("logs/padLog.txt", std::ios::app); + if (!file.good()) + return; + file << text; } void DEBUG_NEW_SET() { -#ifdef _MSC_VER - if (config.debug && bufSize>1) { - HANDLE hFile = CreateFileA("logs\\padLog.txt", FILE_APPEND_DATA, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); - if (hFile != INVALID_HANDLE_VALUE) { - u32 i; - char temp[1500]; - char *end = temp; - sprintf(end, "%02X (%02X) ", inBuf[0], inBuf[1]); - end += 8; - for (i=2; i 1) { + std::ofstream file("logs/padLog.txt", std::ios::app); + if (file.good()) { + std::stringstream stream; + stream.setf(std::ios::hex, std::ios::basefield); + stream.setf(std::ios::uppercase); + stream.fill('0'); + + unsigned char *buffer[2] = {inBuf, outBuf}; + for (const auto &buf : buffer) { + // Port/FF + stream << std::setw(2) << int(buf[0]); + // Active slots/Enabled (only relevant for multitap) + stream << " (" << std::setw(2) << int(buf[1]) << ')'; + + // Command/Response + for (u32 n = 2; n < bufSize; ++n) + stream << ' ' << std::setw(2) << int(buf[n]); + stream << '\n'; } - end[-1] = '\n'; - sprintf(end, "%02X (%02X) ", outBuf[0], outBuf[1]); - end += 8; - for (i=2; i NDEBUG;_USRDLL;TEST_EXPORTS;%(PreprocessorDefinitions) - - Use Global.h FastCall @@ -227,8 +225,6 @@ true WIN32;NDEBUG;_WINDOWS;_USRDLL;TEST_EXPORTS;%(PreprocessorDefinitions) true - - MultiThreadedDLL false true