From d0af2033e9e4827d5b77e97d4ce3a7bf45d2eed9 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Thu, 11 Jun 2015 23:18:25 +0100 Subject: [PATCH] Dev9ghz: Respect user Log dir setting, use PluginLog for logging as it checks if log file was created/opened successfully Enable full logging in debug builds. --- plugins/dev9ghzdrk/DEV9.cpp | 34 ++++++++++++++++++++----- plugins/dev9ghzdrk/DEV9.h | 6 ++++- plugins/dev9ghzdrk/Win32/DEV9ghzdrk.def | 3 ++- plugins/dev9ghzdrk/pcap_io.cpp | 8 ++++-- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/plugins/dev9ghzdrk/DEV9.cpp b/plugins/dev9ghzdrk/DEV9.cpp index 13526bef72..b05fb3574b 100644 --- a/plugins/dev9ghzdrk/DEV9.cpp +++ b/plugins/dev9ghzdrk/DEV9.cpp @@ -80,8 +80,15 @@ u32 CALLBACK PS2EgetLibVersion2(u32 type) { return (version<<16) | (revision<<8) | build; } + +//string s_strIniPath = "inis"; +std::string s_strLogPath = "logs"; // Warning: The below log function is SLOW. Better fix it before attempting to use it. +#ifdef _DEBUG +int Log = 1; +#else int Log = 0; +#endif void __Log(char *fmt, ...) { if (!Log) return; @@ -94,26 +101,31 @@ void __Log(char *fmt, ...) { if(iopPC!=NULL) { - fprintf(dev9Log,"[%10d + %4d, IOP PC = %08x] ",nticks,nticks-ticks,*iopPC); + DEV9Log.Write("[%10d + %4d, IOP PC = %08x] ", nticks, nticks - ticks, *iopPC); } else { - fprintf(dev9Log,"[%10d + %4d] ",nticks,nticks-ticks); + DEV9Log.Write( "[%10d + %4d] ", nticks, nticks - ticks); } ticks=nticks; va_start(list, fmt); - vfprintf(dev9Log, fmt, list); + DEV9Log.Write(fmt, list); va_end(list); } +void LogInit() +{ + const std::string LogFile(s_strLogPath + "/dev9Log.txt"); + DEV9Log.WriteToFile = true; + DEV9Log.Open(LogFile); +} s32 CALLBACK DEV9init() { #ifdef DEV9_LOG_ENABLE - dev9Log = fopen("logs/dev9Log.txt", "w"); - setvbuf(dev9Log, NULL, _IONBF, 0); + LogInit(); DEV9_LOG("DEV9init\n"); #endif memset(&dev9, 0, sizeof(dev9)); @@ -179,7 +191,7 @@ s32 CALLBACK DEV9init() void CALLBACK DEV9shutdown() { DEV9_LOG("DEV9shutdown\n"); #ifdef DEV9_LOG_ENABLE - fclose(dev9Log); + DEV9Log.Close(); #endif } @@ -618,6 +630,16 @@ void CALLBACK DEV9setSettingsDir(const char* dir) // s_strIniPath = (dir == NULL) ? "inis" : dir; } +void CALLBACK DEV9setLogDir(const char* dir) +{ + // Get the path to the log directory. + s_strLogPath = (dir == NULL) ? "logs" : dir; + + // Reload the log file after updated the path + // Currently dosn't change winPcap log directories post DEV9open() + DEV9Log.Close(); + LogInit(); +} int emu_printf(const char *fmt, ...) { diff --git a/plugins/dev9ghzdrk/DEV9.h b/plugins/dev9ghzdrk/DEV9.h index 7443520a17..67d0958695 100644 --- a/plugins/dev9ghzdrk/DEV9.h +++ b/plugins/dev9ghzdrk/DEV9.h @@ -17,6 +17,7 @@ #define __DEV9_H__ #include +#include #ifndef EXTERN #define EXTERN extern #endif @@ -25,6 +26,7 @@ //#define _WIN32_WINNT 0x0500 #include "PS2Edefs.h" +#include "PS2Eext.h" #include "net.h" #ifdef __WIN32__ @@ -125,7 +127,9 @@ void _DEV9close(); EXTERN DEV9callback DEV9irq; //void DEV9thread(); -EXTERN FILE *dev9Log; +EXTERN PluginLog DEV9Log; +//Yes this is meant to be a lowercase extern +extern std::string s_strLogPath; void __Log(char *fmt, ...); void SysMessage(char *fmt, ...); diff --git a/plugins/dev9ghzdrk/Win32/DEV9ghzdrk.def b/plugins/dev9ghzdrk/Win32/DEV9ghzdrk.def index c5a4d6081a..226db9f0b0 100644 --- a/plugins/dev9ghzdrk/Win32/DEV9ghzdrk.def +++ b/plugins/dev9ghzdrk/Win32/DEV9ghzdrk.def @@ -26,4 +26,5 @@ EXPORTS DEV9irqHandler @21 DEV9async @22 - DEV9setSettingsDir \ No newline at end of file + DEV9setSettingsDir + DEV9setLogDir \ No newline at end of file diff --git a/plugins/dev9ghzdrk/pcap_io.cpp b/plugins/dev9ghzdrk/pcap_io.cpp index 467f90dc3e..3854952087 100644 --- a/plugins/dev9ghzdrk/pcap_io.cpp +++ b/plugins/dev9ghzdrk/pcap_io.cpp @@ -123,9 +123,13 @@ int pcap_io_init(char *adapter) fprintf(stderr,"WARNING: Error setting non-blocking mode. Default mode will be used.\n"); } - packet_log=fopen("logs/packet.log","w"); + //Changing the LogSetting might not affect logging + //directory of winPcap logs if done after Open() + const std::string pfile(s_strLogPath + "/packet.log"); + packet_log = fopen(pfile.c_str(), "w"); - dump_pcap = pcap_dump_open(adhandle,"logs/pkt_log.pcap"); + const std::string plfile(s_strLogPath + "/pkt_log.pcap"); + dump_pcap = pcap_dump_open(adhandle, plfile.c_str()); pcap_io_running=1; emu_printf("Ok.\n");