make.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import os
  2. import shutil
  3. import subprocess
  4. # 设置路径
  5. dest_path = os.path.join(os.getcwd(), "AppFile", "laser")
  6. dest_files = os.path.join(os.getcwd(), "AppCode","laser", "app.nsh")
  7. target_nsi_file = r"I:\prox\laser_pc\AppCode\laser\app\laser_setup.nsi"
  8. # 删除文件
  9. if os.path.exists(dest_files):
  10. os.remove(dest_files)
  11. total = 0
  12. curr = 0
  13. def process_directory(directory):
  14. global curr
  15. global total
  16. # 设置输出路径
  17. output_path = directory.replace(dest_path, "$INSTDIR")
  18. if output_path !='$INSTDIR':
  19. with open(dest_files, "a", encoding="UTF-8") as f:
  20. f.write('SetOutPath "{}"\n'.format(output_path))
  21. # 处理当前目录下的文件
  22. for file in os.listdir(directory):
  23. file_path = os.path.join(directory, file)
  24. ##判断文件名不是.gitkeep
  25. if os.path.isfile(file_path) and not file.startswith(".gitkeep"):
  26. total += 1
  27. curr += 1
  28. with open(dest_files, "a", encoding="UTF-8") as f:
  29. f.write('Push ${APP_FILE_COUNT}\n')
  30. f.write('Push {}\n'.format(curr))
  31. f.write('Call ExtractCallback\n')
  32. f.write('SetOverwrite ifnewer\n')
  33. f.write('File "{}"\n'.format(file_path.replace(dest_path, "${APP_FILE_DIR}")))
  34. # 递归处理子目录
  35. for file in os.listdir(directory):
  36. file_path = os.path.join(directory, file)
  37. if os.path.isdir(file_path):
  38. process_directory(file_path)
  39. # 处理首级目录
  40. process_directory(dest_path)
  41. with open(dest_files, "a", encoding="UTF-8") as f:
  42. f.write('Push ${APP_FILE_COUNT}\n')
  43. f.write('Push ${APP_FILE_COUNT}\n')
  44. f.write('Call ExtractCallback\n')
  45. # 替换NSI文件中的值
  46. with open(target_nsi_file, "r", encoding="UTF-16 LE") as nsi_file:
  47. lines = nsi_file.readlines()
  48. # 寻找并替换特定行
  49. for i, line in enumerate(lines):
  50. if line.startswith("!define APP_FILE_COUNT"):
  51. lines[i] = '!define APP_FILE_COUNT {}\n'.format(total)
  52. break
  53. # 写入修改后的内容
  54. with open(target_nsi_file, "w", encoding="UTF-16 LE") as nsi_file:
  55. nsi_file.writelines(lines)
  56. print("总计:{}".format(total))
  57. print("执行打包命令>laser-nozip-N.bat")
  58. # 执行命令并获取输出结果
  59. process = subprocess.Popen("laser-nozip-N1.bat", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
  60. # 持续输出命令的结果
  61. for line in process.stdout:
  62. print(line, end='')
  63. # 等待命令执行完成
  64. process.wait()
  65. print("结束1")
  66. process = subprocess.Popen("laser-nozip-N1-lang.bat", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
  67. # 持续输出命令的结果
  68. for line in process.stdout:
  69. print(line, end='')
  70. # 等待命令执行完成
  71. # process.wait()
  72. print("结束2")