extractAppPackage.nsh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. !macro extractEmbeddedAppPackage
  2. !ifdef COMPRESS
  3. SetCompress off
  4. !endif
  5. Var /GLOBAL packageArch
  6. !insertmacro identify_package
  7. !insertmacro compute_files_for_current_arch
  8. !ifdef COMPRESS
  9. SetCompress "${COMPRESS}"
  10. !endif
  11. !insertmacro decompress
  12. !insertmacro custom_files_post_decompression
  13. !macroend
  14. !macro identify_package
  15. !ifdef APP_32
  16. StrCpy $packageArch "32"
  17. !endif
  18. !ifdef APP_64
  19. ${if} ${RunningX64}
  20. ${OrIf} ${IsNativeARM64}
  21. StrCpy $packageArch "64"
  22. ${endif}
  23. !endif
  24. !ifdef APP_ARM64
  25. ${if} ${IsNativeARM64}
  26. StrCpy $packageArch "ARM64"
  27. ${endif}
  28. !endif
  29. !macroend
  30. !macro compute_files_for_current_arch
  31. ${if} $packageArch == "ARM64"
  32. !ifdef APP_ARM64
  33. !insertmacro arm64_app_files
  34. !endif
  35. ${elseif} $packageArch == "64"
  36. !ifdef APP_64
  37. !insertmacro x64_app_files
  38. !endif
  39. ${else}
  40. !ifdef APP_32
  41. !insertmacro ia32_app_files
  42. !endif
  43. ${endIf}
  44. !macroend
  45. !macro custom_files_post_decompression
  46. ${if} $packageArch == "ARM64"
  47. !ifmacrodef customFiles_arm64
  48. !insertmacro customFiles_arm64
  49. !endif
  50. ${elseif} $packageArch == "64"
  51. !ifmacrodef customFiles_x64
  52. !insertmacro customFiles_x64
  53. !endif
  54. ${else}
  55. !ifmacrodef customFiles_ia32
  56. !insertmacro customFiles_ia32
  57. !endif
  58. ${endIf}
  59. !macroend
  60. !macro arm64_app_files
  61. File /oname=$PLUGINSDIR\app-arm64.${COMPRESSION_METHOD} "${APP_ARM64}"
  62. !macroend
  63. !macro x64_app_files
  64. File /oname=$PLUGINSDIR\app-64.${COMPRESSION_METHOD} "${APP_64}"
  65. !macroend
  66. !macro ia32_app_files
  67. File /oname=$PLUGINSDIR\app-32.${COMPRESSION_METHOD} "${APP_32}"
  68. !macroend
  69. !macro decompress
  70. !ifdef ZIP_COMPRESSION
  71. nsisunz::Unzip "$PLUGINSDIR\app-$packageArch.zip" "$INSTDIR"
  72. Pop $R0
  73. StrCmp $R0 "success" +3
  74. MessageBox MB_OK|MB_ICONEXCLAMATION "$(decompressionFailed)$\n$R0"
  75. Quit
  76. !else
  77. !insertmacro extractUsing7za "$PLUGINSDIR\app-$packageArch.7z"
  78. !endif
  79. !macroend
  80. !macro extractUsing7za FILE
  81. Push $OUTDIR
  82. CreateDirectory "$PLUGINSDIR\7z-out"
  83. ClearErrors
  84. SetOutPath "$PLUGINSDIR\7z-out"
  85. Nsis7z::Extract "${FILE}"
  86. Pop $R0
  87. SetOutPath $R0
  88. # Retry counter
  89. StrCpy $R1 0
  90. LoopExtract7za:
  91. IntOp $R1 $R1 + 1
  92. # Attempt to copy files in atomic way
  93. CopyFiles /SILENT "$PLUGINSDIR\7z-out\*" $OUTDIR
  94. IfErrors 0 DoneExtract7za
  95. DetailPrint `Can't modify "${PRODUCT_NAME}"'s files.`
  96. ${if} $R1 < 5
  97. # Try copying a few times before asking for a user action.
  98. Goto RetryExtract7za
  99. ${else}
  100. MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "$(appCannotBeClosed)" /SD IDRETRY IDCANCEL AbortExtract7za
  101. ${endIf}
  102. # As an absolutely last resort after a few automatic attempts and user
  103. # intervention - we will just overwrite everything with `Nsis7z::Extract`
  104. # even though it is not atomic and will ignore errors.
  105. # Clear the temporary folder first to make sure we don't use twice as
  106. # much disk space.
  107. RMDir /r "$PLUGINSDIR\7z-out"
  108. Nsis7z::Extract "${FILE}"
  109. Goto DoneExtract7za
  110. AbortExtract7za:
  111. Quit
  112. RetryExtract7za:
  113. Sleep 1000
  114. Goto LoopExtract7za
  115. DoneExtract7za:
  116. !macroend