stdafx.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // stdafx.cpp : 只包括标准包含文件的源文件
  2. // lyfzBackupModle.pch 将作为预编译头
  3. // stdafx.obj 将包含预编译类型信息
  4. #include "stdafx.h"
  5. #include "Lock.h"
  6. TCHAR g_szModuleFilePath[MAX_PATH + 1] = {0};
  7. CLock g_loglock;
  8. void WriteLogin(CString str) // 线程安全问题,如果同时有两个线程同时访问,可能存在线程安全问题;
  9. {
  10. CAutoLock autolock(&g_loglock);
  11. try
  12. {
  13. CStdioFile fp;
  14. //CString path = _T("D:\\备份模块.txt");
  15. CString path = g_szModuleFilePath;
  16. path += _T("备份模块.txt");
  17. if (::PathFileExists(path))
  18. {
  19. #ifndef _UNICODE
  20. fp.Open(path, CFile::modeWrite);
  21. #else
  22. fp.Open(path, CFile::modeWrite | CFile::typeBinary | CFile::typeText);
  23. #endif
  24. int length = fp.GetLength();
  25. if (length > 1024 * 1024)
  26. {
  27. fp.Close();
  28. ::DeleteFile(path); // 删除检测备份日志.txt
  29. return;
  30. }
  31. fp.SeekToEnd();
  32. }
  33. else
  34. {
  35. #ifndef _UNICODE
  36. fp.Open(path, CFile::modeCreate | CFile::modeWrite);
  37. #else
  38. fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary);
  39. #endif //#ifndef _UNICODE
  40. }
  41. CString strMsg = _T("");
  42. strMsg.Format(_T("%s%s\n"), CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S ")), str);
  43. fp.WriteString(strMsg);
  44. fp.Close();
  45. }
  46. catch (...)
  47. {
  48. }
  49. }