1
1

GuiThumbnail.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // 可以在此处添加处理成功或失败的逻辑
  13. }
  14. // 执行提取缩略图 主功能
  15. bool GuiThumbnail(const wchar_t* keyWord, const wchar_t* savePath)
  16. {
  17. wchar_t src_filename[MAX_PATH] = {0};
  18. wchar_t thumb_filename[MAX_PATH] = {0};
  19. Everything_SetSearch(keyWord);
  20. if (false==Everything_Query(TRUE))
  21. return false;
  22. std::vector<std::wstring> vec_files;
  23. std::vector<std::wstring> vec_names;
  24. const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr))"; // 正则字符串,exp开始的单词
  25. std::wregex expression(rs); // 字符串传递给构造函数,建立正则表达式
  26. for (int i = 0 ; i < Everything_GetNumResults(); i++) {
  27. bool ret = std::regex_match((wchar_t*)Everything_GetResultFileName(i), expression);
  28. if (ret) {
  29. Everything_GetResultFullPathNameW(i, src_filename, MAX_PATH);
  30. vec_files.push_back(src_filename);
  31. vec_names.push_back((wchar_t*)Everything_GetResultFileName(i));
  32. }
  33. }
  34. // 如果没有目录建立,进入目录
  35. _wmkdir(savePath);
  36. _wchdir(savePath);
  37. // // 文件导出缩略图
  38. // for (int i = 0 ; i != vec_files.size(); i++) {
  39. // wcscpy(src_filename, vec_files[i].c_str());
  40. // wcscpy(thumb_filename, vec_names[i].c_str());
  41. // wcscat(thumb_filename, L"_T.jpg");
  42. // // AI EPS INDD 文件导出缩略图
  43. // bool ret = AdobeThumbnail_W(src_filename, thumb_filename);
  44. // if (!ret) // CorelDRAW CDR 文件导出缩略图
  45. // ret = CorelThumbnail_W(src_filename, thumb_filename);
  46. // }
  47. std::vector<std::thread> threads;
  48. for (int i = 0; i < vec_files.size(); i++) {
  49. const std::wstring& srcFilename = vec_files[i];
  50. const std::wstring& thumbFilename = vec_names[i] + L"_T.jpg";
  51. threads.emplace_back(std::thread(processFile, srcFilename, thumbFilename));
  52. }
  53. // 等待所有线程执行完毕
  54. for (auto& trd : threads) trd.join();
  55. return true;
  56. }
  57. // 临时PNG显示文件
  58. bool Thumbnail_TempPng(const wchar_t* src_filename, const wchar_t* tmppng)
  59. {
  60. bool ret = AdobeThumbnail_W(src_filename, tmppng);
  61. if (!ret)
  62. ret = CorelThumbnail_W(src_filename, tmppng);
  63. return ret;
  64. }