123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // stdafx.cpp : 只包括标准包含文件的源文件
- // lyfzBackupModle.pch 将作为预编译头
- // stdafx.obj 将包含预编译类型信息
- #include "stdafx.h"
- #include "Lock.h"
- TCHAR g_szModuleFilePath[MAX_PATH + 1] = {0};
- CLock g_loglock;
- void WriteLogin(CString str) // 线程安全问题,如果同时有两个线程同时访问,可能存在线程安全问题;
- {
- CAutoLock autolock(&g_loglock);
- try
- {
- CStdioFile fp;
- //CString path = _T("D:\\备份模块.txt");
- CString path = g_szModuleFilePath;
- path += _T("备份模块.txt");
- if (::PathFileExists(path))
- {
- #ifndef _UNICODE
- fp.Open(path, CFile::modeWrite);
- #else
- fp.Open(path, CFile::modeWrite | CFile::typeBinary | CFile::typeText);
- #endif
- int length = fp.GetLength();
- if (length > 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path); // 删除检测备份日志.txt
- return;
- }
- fp.SeekToEnd();
- }
- else
- {
- #ifndef _UNICODE
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- #else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
- #endif //#ifndef _UNICODE
- }
- CString strMsg = _T("");
- strMsg.Format(_T("%s%s\n"), CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S ")), str);
- fp.WriteString(strMsg);
- fp.Close();
- }
- catch (...)
- {
- }
- }
|