summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-17 11:03:51 +0800
committerGitHub <[email protected]>2023-11-17 11:03:51 +0800
commitcf3afe37b546efb93079fd6314c0769884ca0fb1 (patch)
tree732f74fe2fd2922f3c95e8542de82cb6ee108f1c /xmake/scripts
parentb6bb372d19bd2f6ac931d3e0e096b4fa07024cfb (diff)
parente0f074c79be1f712d09df9f7b4b32245ba95f1c9 (diff)
Merge pull request #4392 from xmake-io/emptydirs
improve os.rm to support remove emptydirs
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/xpack/nsis/makensis.nsi143
1 files changed, 116 insertions, 27 deletions
diff --git a/xmake/scripts/xpack/nsis/makensis.nsi b/xmake/scripts/xpack/nsis/makensis.nsi
index 5d1a99dc0..ffcb39c7c 100644
--- a/xmake/scripts/xpack/nsis/makensis.nsi
+++ b/xmake/scripts/xpack/nsis/makensis.nsi
@@ -120,40 +120,128 @@ VIAddVersionKey /LANG=0 ProductVersion "${VERSION_FULL}"
; helper functions
Function TrimQuote
- Exch $R1 ; Original string
- Push $R2
+ Exch $R1 ; Original string
+ Push $R2
Loop:
- StrCpy $R2 "$R1" 1
- StrCmp "$R2" "'" TrimLeft
- StrCmp "$R2" "$\"" TrimLeft
- StrCmp "$R2" "$\r" TrimLeft
- StrCmp "$R2" "$\n" TrimLeft
- StrCmp "$R2" "$\t" TrimLeft
- StrCmp "$R2" " " TrimLeft
- GoTo Loop2
+ StrCpy $R2 "$R1" 1
+ StrCmp "$R2" "'" TrimLeft
+ StrCmp "$R2" "$\"" TrimLeft
+ StrCmp "$R2" "$\r" TrimLeft
+ StrCmp "$R2" "$\n" TrimLeft
+ StrCmp "$R2" "$\t" TrimLeft
+ StrCmp "$R2" " " TrimLeft
+ GoTo Loop2
TrimLeft:
- StrCpy $R1 "$R1" "" 1
- Goto Loop
+ StrCpy $R1 "$R1" "" 1
+ Goto Loop
Loop2:
- StrCpy $R2 "$R1" 1 -1
- StrCmp "$R2" "'" TrimRight
- StrCmp "$R2" "$\"" TrimRight
- StrCmp "$R2" "$\r" TrimRight
- StrCmp "$R2" "$\n" TrimRight
- StrCmp "$R2" "$\t" TrimRight
- StrCmp "$R2" " " TrimRight
- GoTo Done
+ StrCpy $R2 "$R1" 1 -1
+ StrCmp "$R2" "'" TrimRight
+ StrCmp "$R2" "$\"" TrimRight
+ StrCmp "$R2" "$\r" TrimRight
+ StrCmp "$R2" "$\n" TrimRight
+ StrCmp "$R2" "$\t" TrimRight
+ StrCmp "$R2" " " TrimRight
+ GoTo Done
TrimRight:
- StrCpy $R1 "$R1" -1
- Goto Loop2
+ StrCpy $R1 "$R1" -1
+ Goto Loop2
Done:
- Pop $R2
- Exch $R1
+ Pop $R2
+ Exch $R1
FunctionEnd
+; remove directory if it exists
+Function RMDirIfExists
+!define RMDirIfExists '!insertmacro RMDirIfExistsCall'
+!macro RMDirIfExistsCall _PATH
+ push '${_PATH}'
+ Call RMDirIfExists
+!macroend
+ Exch $0
+ IfFileExists "$0" 0 fileDoesNotExist
+ RMDir /r "$0"
+ fileDoesNotExist:
+FunctionEnd
+
+Function unRMDirIfExists
+!define unRMDirIfExists '!insertmacro un.RMDirIfExistsCall'
+!macro unRMDirIfExistsCall _PATH
+ push '${_PATH}'
+ Call un.RMDirIfExists
+!macroend
+ Exch $0
+ IfFileExists "$0" 0 fileDoesNotExist
+ RMDir /r "$0"
+ fileDoesNotExist:
+FunctionEnd
+
+; remove file if it exists
+Function RMFileIfExists
+!define RMFileIfExists '!insertmacro RMFileIfExistsCall'
+!macro RMFileIfExistsCall _PATH
+ push '${_PATH}'
+ Call RMFileIfExists
+!macroend
+ Exch $0
+ IfFileExists "$0" 0 fileDoesNotExist
+ Delete "$0"
+ fileDoesNotExist:
+FunctionEnd
+
+Function un.RMFileIfExists
+!define unRMFileIfExists '!insertmacro unRMFileIfExistsCall'
+!macro unRMFileIfExistsCall _PATH
+ push '${_PATH}'
+ Call un.RMFileIfExists
+!macroend
+ Exch $0
+ IfFileExists "$0" 0 fileDoesNotExist
+ Delete "$0"
+ fileDoesNotExist:
+FunctionEnd
+
+; remove it's parent directories if they are empty
+Function RMEmptyParentDirs
+!define RMEmptyParentDirs '!insertmacro RMEmptyParentDirsCall'
+!macro RMEmptyParentDirsCall _PATH
+ push '${_PATH}'
+ Call RMEmptyParentDirs
+!macroend
+ ClearErrors
+
+ Exch $0
+ RMDir "$0\.."
+
+ IfErrors Skip
+ ${RMEmptyParentDirs} "$0\.."
+ Skip:
+
+ Pop $0
+FunctionEnd
+
+Function un.RMEmptyParentDirs
+!define unRMEmptyParentDirs '!insertmacro unRMEmptyParentDirsCall'
+!macro unRMEmptyParentDirsCall _PATH
+ push '${_PATH}'
+ Call un.RMEmptyParentDirs
+!macroend
+ ClearErrors
+
+ Exch $0
+ RMDir "$0\.."
+
+ IfErrors Skip
+ ${unRMEmptyParentDirs} "$0\.."
+ Skip:
+
+ Pop $0
+FunctionEnd
+
+
; setup installer
Var BinDir
Var NoAdmin
@@ -208,7 +296,7 @@ Section "${PACKAGE_NAME} (required)" InstallExeutable
; Write the uninstall keys for Windows
!macro AddReg RootKey
WriteRegStr ${RootKey} ${RegUninstall} "NoAdmin" "$NoAdmin"
- WriteRegStr ${RootKey} ${RegUninstall} "DisplayName" "${PACKAGE_NAME} (${PACKAGE_ARCH})"
+ WriteRegStr ${RootKey} ${RegUninstall} "DisplayName" "${PACKAGE_NSIS_DISPLAY_NAME}"
WriteRegStr ${RootKey} ${RegUninstall} "DisplayIcon" '"$InstDir\${PACKAGE_BINDIR}\${PACKAGE_FILENAME}"' ; TODO
WriteRegStr ${RootKey} ${RegUninstall} "Comments" "${PACKAGE_DESCRIPTION}"
WriteRegStr ${RootKey} ${RegUninstall} "Publisher" "${PACKAGE_COPYRIGHT}"
@@ -282,7 +370,6 @@ Function un.onInit
!else
StrCpy $BinDir "$InstDir\${PACKAGE_BINDIR}"
!endif
-
FunctionEnd
Section "Uninstall"
@@ -304,6 +391,8 @@ Section "Uninstall"
${EndIf}
; remove uninstall.exe
- Delete "$InstDir\uninstall.exe"
+ ${unRMFileIfExists} "$InstDir\uninstall.exe"
+ ${unRMEmptyParentDirs} "$InstDir\uninstall.exe"
+
SectionEnd