123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "stdafx.h"
- #include "Global.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CLock g_loglock;
- TCHAR g_szDomain[64] = {0};
- TCHAR g_szModuleFilePath[MAX_PATH + 1] = {0};
- BOOL lyfzCopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists)
- {
- // 1.如果是覆盖选项;
- if (!bFailIfExists)
- return CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);
- // 2.如果不是覆盖选项;
- TCHAR szNewFileName[1024] = { 0 };
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_FNAME] = { 0 };
- TCHAR szExt[_MAX_EXT] = { 0 };
- #ifdef _UNICODE
- wsprintf(szNewFileName, _T("%s"), lpNewFileName);
- #else
- sprintf(szNewFileName, _T("%s"), lpNewFileName);
- #endif //#ifdef _UNICODE
- _tsplitpath(szNewFileName, szDrive, szDir, szFna, szExt);
- int nIndex = 1;
- while (PathFileExists(szNewFileName))
- {
- #ifdef _UNICODE
- wsprintf(szNewFileName, _T("%s%s%s (%d)%s"), szDrive, szDir, szFna, nIndex++, szExt);
- #else
- sprintf(szNewFileName, _T("%s%s%s (%d)%s"), szDrive, szDir, szFna, nIndex++, szExt);
- #endif //#ifdef _UNICODE
- }
- return CopyFile(lpExistingFileName, szNewFileName, bFailIfExists);
- }
- void WriteLogin(CString str) // 线程安全问题,如果同时有两个线程同时访问,可能存在线程安全问题;
- {
- CAutoLock autolock(&g_loglock);
- try
- {
- CStdioFile fp;
- 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 (...)
- {
- }
- }
|