Merge pull request #601 from TheLastRar/dev9logging

Dev9ghz: Respect user Log dir setting, use PluginLog. Fixes init crashes
This commit is contained in:
bositman 2015-06-12 12:08:08 +03:00
commit 93168069db
4 changed files with 41 additions and 10 deletions

View File

@ -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, ...)
{

View File

@ -17,6 +17,7 @@
#define __DEV9_H__
#include <stdio.h>
#include <string>
#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, ...);

View File

@ -26,4 +26,5 @@ EXPORTS
DEV9irqHandler @21
DEV9async @22
DEV9setSettingsDir
DEV9setSettingsDir
DEV9setLogDir

View File

@ -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");