Forráskód Böngészése

2024年5月19日版,目前支持 AutoCAD DWG中预览图

蘭雅sRGB 11 hónapja
szülő
commit
c4030ec919
8 módosított fájl, 174 hozzáadás és 6 törlés
  1. 2 0
      GuiAdobeThumbnail.cbp
  2. 4 4
      GuiApp/GuiMain.cpp
  3. 6 1
      GuiApp/GuiThumbnail.cpp
  4. 4 1
      atpch.h
  5. 1 0
      bin/ACThumbs.ini
  6. BIN
      bin/GuiAdobeThumbnail.exe
  7. 147 0
      dwg_thumbnail.cpp
  8. 10 0
      dwg_thumbnail.h

+ 2 - 0
GuiAdobeThumbnail.cbp

@@ -135,6 +135,8 @@
 		<Unit filename="coreldraw_riffinfo.h" />
 		<Unit filename="deAi7Thumb.cpp" />
 		<Unit filename="deAi7Thumb.h" />
+		<Unit filename="dwg_thumbnail.cpp" />
+		<Unit filename="dwg_thumbnail.h" />
 		<Unit filename="otherapi.cpp" />
 		<Unit filename="otherapi.h" />
 		<Unit filename="resource.h" />

+ 4 - 4
GuiApp/GuiMain.cpp

@@ -25,7 +25,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdL
     if (IsFileExist(ConfigFile))
         LoadConfigFile();
 
-    hWindow = XWnd_CreateWindow(0, 0, 960, 600, L"Adobe AI EPS INDD PDF和CorelDRAW 缩略图工具  版权所有 2013-2024 Hongwenjun (蘭雅)"); // 创建窗口
+    hWindow = XWnd_CreateWindow(0, 0, 960, 600, L"Adobe AI EPS INDD PDF和CorelDRAW DWG 缩略图工具  版权所有 2013-2024 Hongwenjun (蘭雅)"); // 创建窗口
     if (hWindow) {
         // 设置图标
         HICON logo_hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_ICON1);
@@ -113,7 +113,7 @@ void InitXC_Window(HWINDOW& hWindow)
     XList_AddColumn(hList, 100, L"文件版本", 2);
 
     // 创建静态文本
-    hStatic = XStatic_Create(1, 545, 650, 22, L"Adobe AI EPS INDD PDF和CorelDRAW 缩略图工具  版权所有 2013-2024 Hongwenjun (蘭雅)", hWindow);
+    hStatic = XStatic_Create(1, 545, 650, 22, L"Adobe AI EPS INDD PDF和CorelDRAW DWG 缩略图工具  版权所有 2013-2024 Hongwenjun (蘭雅)", hWindow);
 
     XStatic_Create(760, 165, 160, 18, L"兰雅VBA代码分享 lyvba.com", hWindow);
 
@@ -157,7 +157,7 @@ bool CALLBACK keyBtnClick(HELE hEle, HELE hEventEle)
     // 删除所有项目
     XList_DeleteAllItems(hList);
 
-    const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr))";  // 正则字符串,exp开始的单词
+    const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr|dwg|DWG|Dwg|DWg|dWG))";  // 正则字符串,exp开始的单词
     std::wregex expression(rs);                   // 字符串传递给构造函数,建立正则表达式
 
     //添加列表项      // Display results.
@@ -174,7 +174,7 @@ bool CALLBACK keyBtnClick(HELE hEle, HELE hEventEle)
     }
 
     wchar_t pText[MAX_PATH] = {0};
-    wsprintfW(pText, L"匹配: %d 个文档(AI CDR EPS INDD PDF格式), 鼠标双击: 打开文件,右键: 打开路径", id);
+    wsprintfW(pText, L"匹配: %d 个文档(AI CDR EPS INDD PDF DWG格式), 鼠标双击: 打开文件,右键: 打开路径", id);
     XStatic_SetText(hStatic, pText);
     XWnd_RedrawWnd(hWindow, true);
     return true;

+ 6 - 1
GuiApp/GuiThumbnail.cpp

@@ -10,6 +10,9 @@ void processFile(const std::wstring& srcFile, const std::wstring& thumbFile)
     // CorelDRAW CDR 文件导出缩略图
     if (!ret)
         ret = CorelThumbnail_W(srcFile.c_str(), thumbFile.c_str());
+    // DWG 文件导出缩略图
+    if (!ret)
+        ret = DWGThumbnail_W(srcFile.c_str(), thumbFile.c_str());
 
     // 可以在此处添加处理成功或失败的逻辑
     if (!ret){
@@ -33,7 +36,7 @@ bool GuiThumbnail(const wchar_t* keyWord, const wchar_t* savePath)
 
     std::vector<std::wstring> vec_files;
     std::vector<std::wstring> vec_names;
-    const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr))";  // 正则字符串,exp开始的单词
+    const wchar_t* rs = L"(.+)(\\.(?:ai|AI|indd|INDD|Indd|eps|EPS|Eps|pdf|PDF|cdr|CDR|Cdr|dwg|DWG|Dwg|DWg|dWG))";  // 正则字符串,exp开始的单词
     std::wregex expression(rs);                   // 字符串传递给构造函数,建立正则表达式
 
     for (int i = 0 ; i < Everything_GetNumResults(); i++) {
@@ -94,5 +97,7 @@ bool Thumbnail_TempPng(const wchar_t* src_filename, const wchar_t* tmppng)
     bool ret = AdobeThumbnail_W(src_filename, tmppng);
     if (!ret)
         ret = CorelThumbnail_W(src_filename, tmppng);
+    if (!ret)
+        ret = DWGThumbnail_W(src_filename, tmppng);
     return ret;
 }

+ 4 - 1
atpch.h

@@ -1,9 +1,10 @@
-#ifndef ATPCH_H_INCLUDED
+#ifndef ATPCH_H_INCLUDED
 #define ATPCH_H_INCLUDED
 
 
 #include "AdobeThumbnail.h"
 #include "corel_thumbnail.h"
+#include "dwg_thumbnail.h"
 #include "otherapi.h"
 #include "deAi7Thumb.h"
 
@@ -14,3 +15,5 @@ using std::string;
 // #define AITEST 0
 
 #endif // ATPCH_H_INCLUDED
+
+

+ 1 - 0
bin/ACThumbs.ini

@@ -1 +1,2 @@
+
 R:\www

BIN
bin/GuiAdobeThumbnail.exe


+ 147 - 0
dwg_thumbnail.cpp

@@ -0,0 +1,147 @@
+#include "dwg_thumbnail.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex>
+#include <string>
+#include <atlimage.h>
+
+using std::string;
+
+bool dwg_getbmp(const char *dwgfile, const char *thumb_bmpfile) {
+  FILE *fd = fopen(dwgfile, "rb");
+  if (fd == NULL) {
+//    fprintf(stderr, "无法打开文件\n");
+    return false;
+  }
+
+  fseek(fd, 13, SEEK_SET);
+  unsigned int sentinel_pos;
+  fread(&sentinel_pos, sizeof(unsigned int), 1, fd);
+  // printf("Hex: %X\n", sentinel_pos);
+
+  const int SIZE_SN = 39;
+
+  char buf[SIZE_SN] = {0};
+  unsigned char SN[] = {0x1F, 0x25, 0x6D, 0x07, 0xD4, 0x36, 0x28, 0x28,
+                        0x9D, 0x57, 0xCA, 0x3F, 0x9D, 0x44, 0x10, 0x2B};
+  fseek(fd, sentinel_pos, SEEK_SET);
+  fread(buf, SIZE_SN, 1, fd);
+
+  bool isdwg = true;
+  for (int i = 0; i != 16; i++) {
+    isdwg &= ((unsigned char)buf[i] == SN[i]);
+  }
+
+//  if (isdwg && buf[20] == 2) {
+//    for (int i = 0; i != sizeof(buf); i++)
+//      printf("%0.2X ", buf[i] & 0xFF);
+//  } else {
+//    return false;
+//  }
+
+  if (!isdwg && buf[20] != 2)
+    return false;
+
+  int data_size;
+  memcpy(&data_size, &buf[35], sizeof(int));
+
+  int pos;
+  memcpy(&pos, &buf[31], sizeof(int));
+
+  // printf("\ndata_size: 0x%0.4X", data_size);
+  // printf("\npos: 0x%0.4X\n", pos);
+
+  char *bmp_buf = new char[data_size];
+  memset(bmp_buf, 0, data_size);
+
+  fseek(fd, pos, SEEK_SET);
+  if (fread(bmp_buf, 1, data_size, fd) != data_size) {
+//    fprintf(stderr, "读取失败\n");
+    delete[] bmp_buf;
+    fclose(fd);
+    return false;
+  }
+
+  FILE *bmp_file = fopen(thumb_bmpfile, "wb");
+  if (bmp_file == NULL) {
+//    fprintf(stderr, "无法创建文件\n");
+    delete[] bmp_buf;
+    fclose(fd);
+    return false;
+  }
+  struct _BITMAP_HEADER {
+    char magic[2];
+    int file_size;
+    int reserved;
+    int offset;
+  } bmp_h;
+
+  /* Write bmp file header */
+  bmp_h.magic[0] = 'B';
+  bmp_h.magic[1] = 'M';
+  bmp_h.file_size = 14 + data_size; // file header + DIB data
+  bmp_h.reserved = 0;
+  bmp_h.offset = 14 + 40 + 4 * 256; // file header + DIB header + color table
+
+  // 写 BMP 文件头
+  fwrite(&bmp_h.magic[0], sizeof(char), 2, bmp_file);
+  fwrite(&bmp_h.file_size, 4, 3, bmp_file);
+
+  // 写bmp 图片数据
+  fwrite(bmp_buf, 1, data_size, bmp_file);
+
+  // printf ("Success. Written thumbnail image to '%s'\n", thumb_bmpfile);
+
+  delete[] bmp_buf;
+  fclose(fd);
+  fclose(bmp_file);
+  return true;
+}
+
+bool DWGThumbnail(const char* dwg_filename, const char* png_filename)
+{
+    string file_ext(dwg_filename);
+    string rs = "(.+)(\\.(?:dwg|DWG|Dwg|DWg|dWG))";
+    std::regex expression(rs);
+    bool ret = regex_match(file_ext, expression);
+    if (!ret) {
+        return ret ;
+    }
+
+    FILE* pfile = fopen(dwg_filename, "rb");
+    if(NULL == pfile){
+   //   MessageBoxA(NULL, cdr_filename, "错误File", MB_OK);
+      return false;
+    }
+
+    char temp_filename[128];
+    const char* tmpBmpFile =  tmpnam(temp_filename);
+    strcat(temp_filename,".bmp");
+
+    ret =  dwg_getbmp(dwg_filename , tmpBmpFile);
+
+    if (!ret)
+        return false ;
+
+    CImage image;  //  bmp 转换 png ,需要CImage类,头文件  atlimage.h
+    image.Load(tmpBmpFile);
+    image.Save(png_filename);
+
+    if (remove(tmpBmpFile) != 0)
+        perror("Error deleting file");
+
+    return ret;
+}
+
+bool DWGThumbnail_W(const wchar_t* dwg_filename, const wchar_t* png_filename)
+{
+    char fromfile[MAX_PATH] = {0};
+    char tofile[MAX_PATH] = {0};
+    WCHARTochar(fromfile, dwg_filename);
+    WCHARTochar(tofile, png_filename);
+    bool ret = DWGThumbnail(fromfile, tofile);
+    return ret;
+}
+
+

+ 10 - 0
dwg_thumbnail.h

@@ -0,0 +1,10 @@
+#ifndef DWG_THUMBNAIL_H_INCLUDED
+#define DWG_THUMBNAIL_H_INCLUDED
+
+#include "otherapi.h"
+
+
+bool DWGThumbnail(const char* dwg_filename, const char* png_filename);
+bool DWGThumbnail_W(const wchar_t* dwg_filename, const wchar_t* png_filename);
+
+#endif // DWG_THUMBNAIL_H_INCLUDED