package_x86_release_clean.bat 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. @echo off
  2. chcp 65001 >nul
  3. echo ========================================
  4. echo ThCardReader x86 Release Package Script
  5. echo ========================================
  6. echo.
  7. :: 设置变量
  8. set SOURCE_DIR=E:\huaihaiProject\readCard\ThCardReader\ThCardReader\bin\x86\Release
  9. :: 获取英文格式的日期时间
  10. for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
  11. set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
  12. set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
  13. set "TIMESTAMP=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
  14. set PACKAGE_NAME=ThCardReader_x86_Release_%TIMESTAMP%
  15. set TEMP_DIR=%cd%\temp_%PACKAGE_NAME%
  16. echo Source Directory: %SOURCE_DIR%
  17. echo Package Name: %PACKAGE_NAME%
  18. echo Temp Directory: %TEMP_DIR%
  19. echo.
  20. :: 检查源目录是否存在
  21. if not exist "%SOURCE_DIR%" (
  22. echo [ERROR] Source directory does not exist: %SOURCE_DIR%
  23. echo Please make sure the path is correct and the project has been built.
  24. pause
  25. exit /b 1
  26. )
  27. :: 检查源目录是否有文件
  28. dir "%SOURCE_DIR%" >nul 2>&1
  29. if errorlevel 1 (
  30. echo [ERROR] Cannot access source directory or directory is empty.
  31. pause
  32. exit /b 1
  33. )
  34. echo [INFO] Checking source directory contents...
  35. dir "%SOURCE_DIR%" /b | find /c /v "" > temp_count.txt
  36. set /p FILE_COUNT=<temp_count.txt
  37. del temp_count.txt
  38. echo [INFO] Found %FILE_COUNT% items in source directory.
  39. echo.
  40. :: 创建临时目录
  41. if exist "%TEMP_DIR%" (
  42. echo [INFO] Removing existing temp directory...
  43. rmdir /s /q "%TEMP_DIR%"
  44. )
  45. echo [INFO] Creating temp directory...
  46. mkdir "%TEMP_DIR%"
  47. if errorlevel 1 (
  48. echo [ERROR] Failed to create temp directory.
  49. pause
  50. exit /b 1
  51. )
  52. :: 复制所有文件(不修改任何内容)
  53. echo [INFO] Copying all files from x86\Release directory...
  54. echo Source: %SOURCE_DIR%
  55. echo Target: %TEMP_DIR%
  56. echo.
  57. xcopy "%SOURCE_DIR%\*" "%TEMP_DIR%\" /E /I /H /Y /Q
  58. if errorlevel 1 (
  59. echo [ERROR] Failed to copy files from source directory.
  60. pause
  61. exit /b 1
  62. )
  63. :: 验证复制结果
  64. echo [INFO] Verifying copied files...
  65. dir "%TEMP_DIR%" /b | find /c /v "" > temp_count2.txt
  66. set /p COPIED_COUNT=<temp_count2.txt
  67. del temp_count2.txt
  68. echo [INFO] Copied %COPIED_COUNT% items successfully.
  69. echo.
  70. :: 显示复制的主要文件
  71. echo [INFO] Main files in package:
  72. if exist "%TEMP_DIR%\ThCardReader.exe" (
  73. echo ✓ ThCardReader.exe
  74. for %%f in ("%TEMP_DIR%\ThCardReader.exe") do echo Size: %%~zf bytes, Modified: %%~tf
  75. ) else (
  76. echo ✗ ThCardReader.exe [MISSING]
  77. )
  78. if exist "%TEMP_DIR%\ThCardReader.exe.config" (
  79. echo ✓ ThCardReader.exe.config
  80. ) else (
  81. echo ✗ ThCardReader.exe.config [MISSING]
  82. )
  83. echo.
  84. echo [INFO] All DLL files:
  85. dir "%TEMP_DIR%\*.dll" /b 2>nul
  86. echo.
  87. :: 创建ZIP包
  88. echo [INFO] Creating ZIP package...
  89. set ZIP_FILE=%PACKAGE_NAME%.zip
  90. :: 使用PowerShell创建ZIP(Windows 10+自带)
  91. powershell -Command "Compress-Archive -Path '%TEMP_DIR%\*' -DestinationPath '%ZIP_FILE%' -Force"
  92. if errorlevel 1 (
  93. echo [ERROR] Failed to create ZIP package.
  94. echo Please make sure PowerShell is available and try again.
  95. pause
  96. goto cleanup
  97. )
  98. :: 验证ZIP文件
  99. if exist "%ZIP_FILE%" (
  100. for %%f in ("%ZIP_FILE%") do (
  101. echo [SUCCESS] Package created successfully!
  102. echo File: %ZIP_FILE%
  103. echo Size: %%~zf bytes
  104. echo Created: %%~tf
  105. )
  106. echo.
  107. :: 显示ZIP内容统计(简化版本,兼容所有系统)
  108. echo [INFO] Package contents summary:
  109. echo Files: %COPIED_COUNT%
  110. for %%f in ("%ZIP_FILE%") do echo ZIP Size: %%~zf bytes
  111. ) else (
  112. echo [ERROR] ZIP package was not created.
  113. )
  114. :cleanup
  115. :: 清理临时目录
  116. echo [INFO] Cleaning up temporary files...
  117. if exist "%TEMP_DIR%" (
  118. rmdir /s /q "%TEMP_DIR%"
  119. echo [INFO] Temporary directory removed.
  120. )
  121. echo.
  122. echo ========================================
  123. echo Package operation completed!
  124. echo ========================================
  125. echo.
  126. echo IMPORTANT NOTES:
  127. echo - Source files were NOT modified in any way
  128. echo - Package contains EXACT copy of x86\Release
  129. echo - Package name: %PACKAGE_NAME%.zip
  130. echo - All files preserved as-is with original timestamps
  131. echo - No Chinese characters in package name
  132. echo.
  133. pause