// поток чтения пайпа DWORD Updater::read_update_progress_thread(LPVOID param) { Updater* updater = static_cast<Updater*>(param); updater->AddProgressInfo(prog_info::PROGRESS_START); for (;;) { std::string output; const int BUFSIZE = 1024; char chBuf[BUFSIZE]; DWORD dwRead; DWORD ec = 0; //exit code DWORD bytesAvailable = 0; while (PeekNamedPipe(updater->_hReadPipe, NULL, 0, NULL, &bytesAvailable, NULL) && bytesAvailable > 0) if (ReadFile(updater->_hReadPipe, chBuf, BUFSIZE - 1, &dwRead, NULL) && dwRead) { chBuf[dwRead] = '\0'; output += chBuf; LOG_DEBUG << output; updater->parse(output); } if (!GetExitCodeThread(updater->_pi.hThread, &ec) || ec != STILL_ACTIVE) break; } updater->AddProgressInfo(prog_info::PROGRESS_END); updater->DestroyHandle(); return 0; }
// поток, проверка наличия обновления DWORD Updater::read_check_update_thread(LPVOID param) { Updater* updater = static_cast<Updater*>(param); std::string output; for (;;) { const int BUFSIZE = 1024; char chBuf[BUFSIZE]; DWORD dwRead; DWORD ec = 0; //exit code DWORD bytesAvailable = 0; while (PeekNamedPipe(updater->_hReadPipe, NULL, 0, NULL, &bytesAvailable, NULL) && bytesAvailable > 0) if (ReadFile(updater->_hReadPipe, chBuf, BUFSIZE - 1, &dwRead, NULL) && dwRead) { chBuf[dwRead] = '\0'; output += chBuf; } if (!GetExitCodeThread(updater->_pi.hThread, &ec) || ec != STILL_ACTIVE) break; } LOG_DEBUG << output; int count_line = 0; for (std::string::iterator it = output.begin(); it != output.end(); ++it) { if (*it != '\n') continue; std::string line = output.substr(0, std::distance(output.begin(), it)); ++it; output.erase(output.begin(), it); it = output.begin(); if (0 != line.find("sending") && (line.size()-1) != line.find("/") && 0 != line.find("deleting") && 1 != line.find("sent") && 0 != line.find("total size") && 0 != line.size()) ++count_line; if (it == output.end()) break; } bool exist_update = count_line > 0; updater->_status_check.get_content(); // удаляем предыдущую информацию updater->_status_check.push_back(exist_update); updater->DestroyHandle(); return 0; }