1
1

GuiThumbnail.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "GuiThumbnail.h"
  2. #include <string.h>
  3. #include <wchar.h>
  4. #include <thread>
  5. void processFile(const std::wstring& srcFile, const std::wstring& thumbFile)
  6. {
  7. // AI EPS INDD 文件导出缩略图
  8. bool ret = AdobeThumbnail_W(srcFile.c_str(), thumbFile.c_str());
  9. // CorelDRAW CDR 文件导出缩略图
  10. if (!ret)
  11. ret = CorelThumbnail_W(srcFile.c_str(), thumbFile.c_str());
  12. // DWG 文件导出缩略图
  13. if (!ret)
  14. ret = DWGThumbnail_W(srcFile.c_str(), thumbFile.c_str());
  15. // 可以在此处添加处理成功或失败的逻辑
  16. if (!ret){
  17. char bad_File[MAX_PATH] = "001_Bad_Filelist.txt";
  18. FILE * pf = fopen(bad_File, "a+");
  19. WCHARTochar(bad_File, srcFile.c_str());
  20. fprintf(pf, "Name: %s\n", bad_File);
  21. fclose(pf);
  22. }
  23. }
  24. // 执行提取缩略图 主功能
  25. bool GuiThumbnail(const wchar_t* keyWord, const wchar_t* savePath)
  26. {
  27. wchar_t src_filename[MAX_PATH] = {0};
  28. wchar_t thumb_filename[MAX_PATH] = {0};
  29. Everything_SetSearch(keyWord);
  30. if (false == Everything_Query(TRUE))
  31. return false;
  32. std::vector<std::wstring> vec_files;
  33. std::vector<std::wstring> vec_names;
  34. const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr|dwg|DWG|Dwg|DWg|dWG))"; // 正则字符串,exp开始的单词
  35. std::wregex expression(rs); // 字符串传递给构造函数,建立正则表达式
  36. for (int i = 0 ; i < Everything_GetNumResults(); i++) {
  37. bool ret = std::regex_match((wchar_t*)Everything_GetResultFileName(i), expression);
  38. if (ret) {
  39. Everything_GetResultFullPathNameW(i, src_filename, MAX_PATH);
  40. vec_files.push_back(src_filename);
  41. vec_names.push_back((wchar_t*)Everything_GetResultFileName(i));
  42. }
  43. }
  44. // 如果没有目录建立,进入目录
  45. _wmkdir(savePath);
  46. _wchdir(savePath);
  47. // // 文件导出缩略图
  48. // for (int i = 0 ; i != vec_files.size(); i++) {
  49. // wcscpy(src_filename, vec_files[i].c_str());
  50. // wcscpy(thumb_filename, vec_names[i].c_str());
  51. // wcscat(thumb_filename, L"_T.jpg");
  52. // // AI EPS INDD 文件导出缩略图
  53. // bool ret = AdobeThumbnail_W(src_filename, thumb_filename);
  54. // if (!ret) // CorelDRAW CDR 文件导出缩略图
  55. // ret = CorelThumbnail_W(src_filename, thumb_filename);
  56. // }
  57. const int trn = 8;
  58. std::vector<std::thread> threads;
  59. while (vec_files.size() > trn) {
  60. for (int i = 0; i < trn; i++) {
  61. const std::wstring& srcFilename = vec_files[i];
  62. const std::wstring& thumbFilename = vec_names[i] + L"_T.jpg";
  63. threads.emplace_back(std::thread(processFile, srcFilename, thumbFilename));
  64. }
  65. // 等待所有线程执行完毕
  66. for (auto& trd : threads) trd.join();
  67. threads.clear();
  68. vec_files.erase(vec_files.begin(), vec_files.begin() + trn);
  69. vec_names.erase(vec_names.begin(), vec_names.begin() + trn);
  70. }
  71. for (int i = 0; i < vec_files.size(); i++) {
  72. const std::wstring& srcFilename = vec_files[i];
  73. const std::wstring& thumbFilename = vec_names[i] + L"_T.jpg";
  74. threads.emplace_back(std::thread(processFile, srcFilename, thumbFilename));
  75. }
  76. // 等待所有线程执行完毕
  77. for (auto& trd : threads) trd.join();
  78. return true;
  79. }
  80. // 临时PNG显示文件
  81. bool Thumbnail_TempPng(const wchar_t* src_filename, const wchar_t* tmppng)
  82. {
  83. bool ret = AdobeThumbnail_W(src_filename, tmppng);
  84. if (!ret)
  85. ret = CorelThumbnail_W(src_filename, tmppng);
  86. if (!ret)
  87. ret = DWGThumbnail_W(src_filename, tmppng);
  88. return ret;
  89. }