1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| class FileMD5Thread { private: char* listFile; char* outMD5File; unsigned short int threadCount = 24; static std::mutex logLock; std::mutex* plck; ...... }
int FileMD5Thread::fileMd5Sum(sql::Statement* state, ThreadsAction action) { constexpr int FILE_NAME_PATH_SIZE = 512; char buff[FILE_NAME_PATH_SIZE * 2] = { 0 }; char buffMD5[128] = { 0 }; char fileName[FILE_NAME_PATH_SIZE] = { 0 }; char filePath[FILE_NAME_PATH_SIZE] = { 0 }; while (inFile.getline(buff, FILE_NAME_PATH_SIZE)) { try { strcpy(buffMD5, getFileMD5(buff).c_str()); } catch (...) { this->endResetZero(buffMD5, 128); std::lock_guard<std::mutex> lockguard(logLock); errors++; outLog << "无法定位文件: " << buff << endl; cout << "无法定位文件: " << buff << endl; } cutStr(buff, filePath, fileName, '\\'); switch (action) { case FileMD5Thread::ThreadsAction::TO_MYSQL: { sprintf(buff, "insert into mods_test(md5,filename,path) value(\"%s\",\"%s\",\"%s\")", buffMD5, fileName, filePath); gbkToUTF8(buff, FILE_NAME_PATH_SIZE); try { std::lock_guard<std::mutex> lockguard(*plck); state->executeUpdate(buff); } catch (...) { std::lock_guard<std::mutex> lockguard(logLock); errors++; outLog << buff << endl; } } break; case FileMD5Thread::ThreadsAction::TO_FILE: { std::lock_guard<std::mutex> lockguard(*plck); outLog << fileName << " " << filePath << endl; outLog << buff << endl << endl; } break; default: { cout << "别乱搞!" << endl; return 404; } break; } this->endResetZero(buff, FILE_NAME_PATH_SIZE); this->endResetZero(fileName, FILE_NAME_PATH_SIZE); this->endResetZero(filePath, FILE_NAME_PATH_SIZE); } return errors; }
|