Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: NSIS #132

Merged
merged 7 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,49 @@ jobs:
steps:
- id: deployment
uses: actions/deploy-pages@v4

pack:
needs: build
runs-on: windows-latest
strategy:
matrix:
OS:
- windows
ARCH:
- amd64
- arm64
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Download build
uses: actions/download-artifact@v4
with:
name: lip-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}

- name: Set up NSIS
run: |
C:\msys64\usr\bin\wget.exe -q https://sourceforge.net/projects/nsis/files/NSIS%203/3.09/nsis-3.09.zip -O nsis.zip
C:\msys64\usr\bin\wget.exe -q https://sourceforge.net/projects/nsis/files/NSIS%203/3.09/nsis-3.09-strlen_8192.zip -O nsis-strlen.zip
C:\msys64\usr\bin\wget.exe -q https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -O EnVar_plugin.zip
unzip -q -o nsis.zip
mv nsis-3.09 nsis-portable
unzip -q -o nsis-strlen.zip -d nsis-portable
unzip -q -o EnVar_plugin.zip -d nsis-portable

- name: Set up NSIS building folder
run: |
mkdir nsis
cp ./scripts/make_installer.nsi ./nsis/
cp ./lip.exe ./nsis/
cp ./COPYING ./nsis/

- name: Build setup program
run: |
.\nsis-portable\makensis /DLIP_VERSION=${{ github.ref_name }} /DLIP_OS=${{ matrix.OS }} /DLIP_ARCH=${{ matrix.ARCH }} ./nsis/make_installer.nsi

- name: Upload build
uses: actions/upload-artifact@v4
with:
name: lip-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}-setup
path: nsis/lip-${{ matrix.OS }}-${{ matrix.ARCH }}-setup.exe
54 changes: 53 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,52 @@ jobs:
with:
name: lip-${{ matrix.GOOS }}-${{ matrix.GOARCH }}-${{ github.sha }}
path: bin

pack:
needs: build
runs-on: windows-latest
strategy:
matrix:
OS:
- windows
ARCH:
- amd64
- arm64
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Download build
uses: actions/download-artifact@v4
with:
name: lip-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}

- name: Set up NSIS
futrime marked this conversation as resolved.
Show resolved Hide resolved
run: |
C:\msys64\usr\bin\wget.exe -q https://sourceforge.net/projects/nsis/files/NSIS%203/3.09/nsis-3.09.zip -O nsis.zip
C:\msys64\usr\bin\wget.exe -q https://sourceforge.net/projects/nsis/files/NSIS%203/3.09/nsis-3.09-strlen_8192.zip -O nsis-strlen.zip
C:\msys64\usr\bin\wget.exe -q https://nsis.sourceforge.io/mediawiki/images/7/7f/EnVar_plugin.zip -O EnVar_plugin.zip
unzip -q -o nsis.zip
mv nsis-3.09 nsis-portable
unzip -q -o nsis-strlen.zip -d nsis-portable
unzip -q -o EnVar_plugin.zip -d nsis-portable

- name: Set up NSIS building folder
run: |
mkdir nsis
cp ./scripts/make_installer.nsi ./nsis/
cp ./lip.exe ./nsis/
cp ./COPYING ./nsis/

- name: Build setup program
run: |
.\nsis-portable\makensis /DLIP_VERSION=${{ github.ref_name }} /DLIP_OS=${{ matrix.OS }} /DLIP_ARCH=${{ matrix.ARCH }} ./nsis/make_installer.nsi

- name: Upload build
uses: actions/upload-artifact@v4
with:
name: lip-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}-setup
path: nsis/lip-${{ matrix.OS }}-${{ matrix.ARCH }}-setup.exe

update-release-notes:
permissions:
Expand All @@ -54,8 +100,8 @@ jobs:

upload-to-release:
needs:
- build
PA733 marked this conversation as resolved.
Show resolved Hide resolved
- update-release-notes
- pack
permissions:
contents: write
runs-on: ubuntu-latest
Expand All @@ -70,6 +116,11 @@ jobs:
with:
name: lip-${{ matrix.GOOS }}-${{ matrix.GOARCH }}-${{ github.sha }}
path: artifact

- uses: actions/download-artifact@v4
if: matrix.GOOS == 'windows'
with:
name: lip-${{ matrix.GOOS }}-${{ matrix.GOARCH }}-${{ github.sha }}-setup

- name: Copy essential files
run: |
Expand All @@ -93,6 +144,7 @@ jobs:
with:
files: |
lip-${{ matrix.GOOS }}-${{ matrix.GOARCH }}.zip
lip-${{ matrix.GOOS }}-${{ matrix.GOARCH }}-setup.exe

- name: Upload artifact to release (Others)
if: matrix.GOOS != 'windows'
Expand Down
152 changes: 152 additions & 0 deletions scripts/make_installer.nsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Unicode True

!define PRODUCT_NAME "Lip"
!define PRODUCT_PUBLISHER "LiteLDev"
!define PRODUCT_WEB_SITE "https://github.com/LipPkg/Lip"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\lip.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

!ifdef LIP_VERSION
!define PRODUCT_VERSION "${LIP_VERSION}"
!else
!define PRODUCT_VERSION "0.0.0"
!endif

!ifdef LIP_OS
!else
!define LIP_OS "windows"
!endif

!ifdef LIP_ARCH
!else
!define LIP_ARCH "amd64"
!endif

SetCompressor /SOLID lzma
SetCompressorDictSize 32

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!define MUI_LICENSEPAGE_CHECKBOX
!insertmacro MUI_PAGE_LICENSE "COPYING"
; Components page
!insertmacro MUI_PAGE_COMPONENTS
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

; MUI end ------

Name "${PRODUCT_NAME}"
OutFile "lip-${LIP_OS}-${LIP_ARCH}-setup.exe"
InstallDir "$PROGRAMFILES64\Lip"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd

Section "Lip (required)" SEC01
SectionIn RO
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "lip.exe"
SectionEnd

Section "Add to PATH" SEC02
; Check for write access
EnVar::Check "NULL" "NULL"

; Set to HKLM
EnVar::SetHKLM

; Append a value
EnVar::AddValue "PATH" "$INSTDIR"
SectionEnd

Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\lip.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninst.exe$\""
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$\"$INSTDIR\lip.exe$\""
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

; Section descriptions
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SEC01} ""
!insertmacro MUI_DESCRIPTION_TEXT ${SEC02} ""
!insertmacro MUI_FUNCTION_DESCRIPTION_END



Function un.onInit
ReadRegStr $0 "${PRODUCT_UNINST_ROOT_KEY}" "${PRODUCT_UNINST_KEY}" "NSIS:Language"
${If} $0 == "1033"
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
Abort
${ElseIf} $0 == "2052"
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "你确定要完全移除 $(^Name) 及其所有组件吗?" IDYES +2
Abort
${EndIf}
FunctionEnd

Function un.onUninstSuccess
HideWindow
${If} $0 == "1033"
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) has been successfully removed."
${ElseIf} $0 == "2052"
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功移除。"
${EndIf}
FunctionEnd

Section Uninstall
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\lip.exe"

RMDir /r "$INSTDIR\.lip"
RMDir "$INSTDIR"

DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
; Check for write access
EnVar::Check "NULL" "NULL"
; Set to HKLM
EnVar::SetHKLM
; Delete Lip install directory from PATH
EnVar::DeleteValue "PATH" "$INSTDIR"
SetAutoClose true
SectionEnd