bool CLogFile::Close() { try { // limit log file growth size_t maxLines = (DWORD)m_maxlines; size_t newLines = m_newLines.size(); TrimFile (DWORD(max (maxLines, newLines) - newLines)); // append new info CStdioFile file; int retrycounter = 10; // try to open the file for about two seconds - some other TSVN process might be // writing to the file and we just wait a little for this to finish while (!file.Open(m_logfile.GetWinPath(), CFile::typeText | CFile::modeReadWrite | CFile::modeCreate | CFile::modeNoTruncate) && retrycounter) { retrycounter--; Sleep(200); } if (retrycounter == 0) return false; file.SeekToEnd(); for (std::deque<CString>::const_iterator it = m_newLines.begin(); it != m_newLines.end(); ++it) { file.WriteString(*it); file.WriteString(L"\n"); } file.Close(); } catch (CFileException* pE) { CTraceToOutputDebugString::Instance()(__FUNCTION__ ": CFileException saving log file\n"); pE->Delete(); return false; } return true; }
int GoProcessing(const tagCMDL & cmdl) { int mode = cmdl.mode; CreateDirectory(cmdl.temppath, NULL); wchar_t tempfile[MAX_PATH]; if( lstrlen(cmdl.temppath) == 0 ) { // кодируем в файл по умолчанию StringCchCopy(tempfile, MAX_PATH, cmdl.outputfilename); }else { StringCchCopy(tempfile, MAX_PATH, cmdl.temppath); if( tempfile[ lstrlen(tempfile) -1 ] != L'\\') StringCchCat(tempfile, MAX_PATH, L"\\"); StringCchCat(tempfile, MAX_PATH, PathFindFileName(cmdl.outputfilename)); } HWND fwwnd = FindWindow(wndclassnameW, NULL); if(fwwnd == NULL) return 4; int pos = -1; while( pos < 0 ) { if( !isProcessExist() ) // проверяем мьютекс return 0; // преждевременный выход pos = (int)SendMessage(fwwnd, MES_ONNEWTHREAD, 0, 0); if( pos >= 0 ) break; Sleep(200); } ////////////////////////////////////////////////////////////////////////// // название файла if( !SendFileName(fwwnd, cmdl.outputfilename, pos) ) return 0; // выход, лажа. ////////////////////////////////////////////////////////////////////////// // читаем файл из stdin и создаём временный wav-файл if( !ReadAndCreateFile(tempfile) ) return 5; DWORD len = CorrectHeader(tempfile); ////////////////////////////////////////////////////////////////////////// // сообщаем длинну трэка: sec * 4 * 44100 if( !MySendMessage(fwwnd, MES_SENDLENGTH, pos, len) ) { DeleteFile(tempfile); return 0; } if( len ) { UINT newpriority = (UINT)SendMessage(fwwnd, MES_GETPRIORITY, 0, 0); SetPriorityClass(GetCurrentProcess(), newpriority ); if( !RunProcessing(tempfile, mode, fwwnd, pos) ) { DeleteFile(tempfile); return 0; // пытаемся безболезненно свалить :D } } DeleteFile(tempfile); if( !TrimFile(cmdl.outputfilename, pos) ) return 6; return 0; }