diff options
Diffstat (limited to 'protocols/YAMN/src/debug.cpp')
-rw-r--r-- | protocols/YAMN/src/debug.cpp | 75 |
1 files changed, 6 insertions, 69 deletions
diff --git a/protocols/YAMN/src/debug.cpp b/protocols/YAMN/src/debug.cpp index 65322366ab..92d5a0b3c4 100644 --- a/protocols/YAMN/src/debug.cpp +++ b/protocols/YAMN/src/debug.cpp @@ -11,19 +11,11 @@ #ifdef _DEBUG
-//--------------------------------------------------------------------------------------------------
-//--------------------------------------------------------------------------------------------------
-
-wchar_t DebugUserDirectory[MAX_PATH] = L".";
-CRITICAL_SECTION FileAccessCS;
-
#ifdef DEBUG_COMM
-wchar_t DebugCommFileName2[]=L"%s\\yamn-debug.comm.log";
HANDLE CommFile;
#endif
#ifdef DEBUG_DECODE
-wchar_t DebugDecodeFileName2[]=L"%s\\yamn-debug.decode.log";
HANDLE DecodeFile;
#endif
@@ -32,80 +24,25 @@ HANDLE DecodeFile; void InitDebug()
{
-#if defined (DEBUG_COMM) || defined (DEBUG_DECODE)
- wchar_t DebugFileName[MAX_PATH];
-#endif
- InitializeCriticalSection(&FileAccessCS);
-
#ifdef DEBUG_COMM
- mir_snwprintf(DebugFileName, DebugCommFileName2, DebugUserDirectory);
-
- CommFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
- DebugLog(CommFile,"Communication debug file created by %s\n",YAMN_VER);
+ CommFile = mir_createLog("YAMN_comm", L"", VARSW(L"%miranda_userdata%\\yamn-debug.comm.log"), 0);
+ mir_writeLogA(CommFile,"Communication debug file created by %s\n",YAMN_VER);
#endif
#ifdef DEBUG_DECODE
- mir_snwprintf(DebugFileName, DebugDecodeFileName2, DebugUserDirectory);
-
- DecodeFile=CreateFile(DebugFileName,GENERIC_WRITE,FILE_SHARE_WRITE|FILE_SHARE_READ,NULL,CREATE_ALWAYS,0,NULL);
- DebugLog(DecodeFile,"Decoding kernel debug file created by %s\n",YAMN_VER);
+ DecodeFile = mir_createLog("YAMN_comm", L"", VARSW(L"%miranda_userdata%\\yamn-debug.decode.log"), 0);
+ mir_writeLogA(DecodeFile, "Decoding kernel debug file created by %s\n", YAMN_VER);
#endif
}
void UnInitDebug()
{
- DeleteCriticalSection(&FileAccessCS);
#ifdef DEBUG_COMM
- DebugLog(CommFile,"File is being closed normally.");
- CloseHandle(CommFile);
+ mir_writeLogA(CommFile,"File is being closed normally.");
#endif
#ifdef DEBUG_DECODE
- DebugLog(DecodeFile,"File is being closed normally.");
- CloseHandle(DecodeFile);
+ mir_writeLogA(DecodeFile,"File is being closed normally.");
#endif
}
-
-void DebugLog(HANDLE File,const char *fmt,...)
-{
- char *str;
- char tids[32];
- va_list vararg;
- int strsize;
- DWORD Written;
-
- va_start(vararg,fmt);
- str=(char *)malloc(strsize=65536);
- mir_snprintf(tids, "[%x]",GetCurrentThreadId());
- while(mir_vsnprintf(str, strsize, fmt, vararg)==-1)
- str=(char *)realloc(str,strsize+=65536);
- va_end(vararg);
- EnterCriticalSection(&FileAccessCS);
- WriteFile(File,tids,(uint32_t)mir_strlen(tids),&Written,nullptr);
- WriteFile(File,str,(uint32_t)mir_strlen(str),&Written,nullptr);
- LeaveCriticalSection(&FileAccessCS);
- free(str);
-}
-
-void DebugLogW(HANDLE File,const wchar_t *fmt,...)
-{
- wchar_t *str;
- char tids[32];
- va_list vararg;
- int strsize;
- DWORD Written;
-
- va_start(vararg,fmt);
- str=(wchar_t *)malloc((strsize=65536)*sizeof(wchar_t));
- mir_snprintf(tids, "[%x]",GetCurrentThreadId());
- while(mir_vsnwprintf(str, strsize, fmt, vararg)==-1)
- str=(wchar_t *)realloc(str,(strsize+=65536)*sizeof(wchar_t));
- va_end(vararg);
- EnterCriticalSection(&FileAccessCS);
- WriteFile(File,tids,(uint32_t)mir_strlen(tids),&Written,nullptr);
- WriteFile(File,str,(uint32_t)mir_wstrlen(str)*sizeof(wchar_t),&Written,nullptr);
- LeaveCriticalSection(&FileAccessCS);
- free(str);
-}
-
#endif //ifdef DEBUG
\ No newline at end of file |