package_x86_release_clean.bat 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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\ThCardReader\mhCardReader\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] Checking external configuration file...
  65. if not exist "%TEMP_DIR%\jiangsu_config.txt" (
  66. echo [WARNING] External config file not found in Release directory.
  67. echo [INFO] Attempting to copy from project source...
  68. copy "ThCardReader\jiangsu_config.txt" "%TEMP_DIR%\" >nul 2>&1
  69. if exist "%TEMP_DIR%\jiangsu_config.txt" (
  70. echo [SUCCESS] External config file copied successfully from project source.
  71. ) else (
  72. echo [INFO] External config file not found, but program will use default configuration.
  73. echo [INFO] Program will work with default settings if external config is missing.
  74. )
  75. ) else (
  76. echo [SUCCESS] External config file found in Release directory.
  77. )
  78. :: 验证外部配置文件的内容
  79. echo [INFO] Validating external config file...
  80. if exist "%TEMP_DIR%\jiangsu_config.txt" (
  81. findstr /c:"IP=" "%TEMP_DIR%\jiangsu_config.txt" >nul
  82. if errorlevel 1 (
  83. echo [WARNING] External config file may be incomplete, but program will use defaults.
  84. echo [WARNING] Missing config items will be replaced with default values.
  85. ) else (
  86. echo [SUCCESS] External config file appears to be valid.
  87. )
  88. ) else (
  89. echo [INFO] No external config file found, program will use default configuration.
  90. )
  91. :: 验证复制结果
  92. echo [INFO] Verifying copied files...
  93. dir "%TEMP_DIR%" /b | find /c /v "" > temp_count2.txt
  94. set /p COPIED_COUNT=<temp_count2.txt
  95. del temp_count2.txt
  96. echo [INFO] Copied %COPIED_COUNT% items successfully.
  97. echo.
  98. :: 显示复制的主要文件
  99. echo [INFO] Main files in package:
  100. if exist "%TEMP_DIR%\ThCardReader.exe" (
  101. echo ✓ ThCardReader.exe
  102. for %%f in ("%TEMP_DIR%\ThCardReader.exe") do echo Size: %%~zf bytes, Modified: %%~tf
  103. ) else (
  104. echo ✗ ThCardReader.exe [MISSING]
  105. )
  106. if exist "%TEMP_DIR%\ThCardReader.exe.config" (
  107. echo ✓ ThCardReader.exe.config
  108. ) else (
  109. echo ✗ ThCardReader.exe.config [MISSING]
  110. )
  111. if exist "%TEMP_DIR%\jiangsu_config.txt" (
  112. echo ✓ jiangsu_config.txt (REQUIRED - External Config)
  113. for %%f in ("%TEMP_DIR%\jiangsu_config.txt") do echo Size: %%~zf bytes, Modified: %%~tf
  114. ) else (
  115. echo ✗ jiangsu_config.txt [MISSING - CRITICAL ERROR]
  116. )
  117. echo.
  118. echo [INFO] All DLL files:
  119. dir "%TEMP_DIR%\*.dll" /b 2>nul
  120. echo.
  121. :: 创建ZIP包
  122. echo [INFO] Creating ZIP package...
  123. set ZIP_FILE=%PACKAGE_NAME%.zip
  124. :: 使用PowerShell创建ZIP(Windows 10+自带)
  125. powershell -Command "Compress-Archive -Path '%TEMP_DIR%\*' -DestinationPath '%ZIP_FILE%' -Force"
  126. if errorlevel 1 (
  127. echo [ERROR] Failed to create ZIP package.
  128. echo Please make sure PowerShell is available and try again.
  129. pause
  130. goto cleanup
  131. )
  132. :: 验证ZIP文件
  133. if exist "%ZIP_FILE%" (
  134. for %%f in ("%ZIP_FILE%") do (
  135. echo [SUCCESS] Package created successfully!
  136. echo File: %ZIP_FILE%
  137. echo Size: %%~zf bytes
  138. echo Created: %%~tf
  139. )
  140. echo.
  141. :: 显示ZIP内容统计(简化版本,兼容所有系统)
  142. echo [INFO] Package contents summary:
  143. echo Files: %COPIED_COUNT%
  144. for %%f in ("%ZIP_FILE%") do echo ZIP Size: %%~zf bytes
  145. ) else (
  146. echo [ERROR] ZIP package was not created.
  147. )
  148. :cleanup
  149. :: 清理临时目录
  150. echo [INFO] Cleaning up temporary files...
  151. if exist "%TEMP_DIR%" (
  152. rmdir /s /q "%TEMP_DIR%"
  153. echo [INFO] Temporary directory removed.
  154. )
  155. echo.
  156. echo ========================================
  157. echo Package operation completed!
  158. echo ========================================
  159. echo.
  160. echo IMPORTANT NOTES:
  161. echo - Source files were NOT modified in any way
  162. echo - Package contains EXACT copy of x86\Release
  163. echo - Package name: %PACKAGE_NAME%.zip
  164. echo - All files preserved as-is with original timestamps
  165. echo.
  166. echo CRITICAL CONFIGURATION CHANGES:
  167. echo - Program PRIORITIZES external config file (jiangsu_config.txt)
  168. echo - If external config file is missing, program uses default configuration
  169. echo - If config items are missing, program uses default values
  170. echo - Users can modify jiangsu_config.txt after deployment
  171. echo - Program will work even without external config file
  172. echo.
  173. echo DEPLOYMENT NOTES:
  174. echo - Extract the ZIP file to any directory
  175. echo - Modify jiangsu_config.txt as needed for your environment
  176. echo - Run ThCardReader.exe
  177. echo - All configuration changes require only file editing, no recompilation
  178. echo - Program will work with default settings if config file is missing
  179. echo.
  180. pause