diff --git a/SourceGit.sln b/SourceGit.sln index 80921840..871174a1 100644 --- a/SourceGit.sln +++ b/SourceGit.sln @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{773082AC build\build.linux.sh = build\build.linux.sh build\build.osx.command = build\build.osx.command build\build.windows.ps1 = build\build.windows.ps1 + build\build.windows.installer.nsi = build\build.windows.installer.nsi EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "resources", "resources", "{FD384607-ED99-47B7-AF31-FB245841BC92}" @@ -38,6 +39,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "app", "app", "{ABC98884-F02 ProjectSection(SolutionItems) = preProject build\resources\app\App.icns = build\resources\app\App.icns build\resources\app\App.plist = build\resources\app\App.plist + build\resources\app\App.ico = build\resources\app\App.ico EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_common", "_common", "{04FD74B1-FBDB-496E-A48F-3D59D71FF952}" diff --git a/build/build.windows.installer.nsi b/build/build.windows.installer.nsi new file mode 100644 index 00000000..e58910cf --- /dev/null +++ b/build/build.windows.installer.nsi @@ -0,0 +1,89 @@ +; Application properties +!define PRODUCT_NAME "SourceGit" +!define PRODUCT_VERSION ${VERSION} +!define PRODUCT_PUBLISHER "sourcegit-scm" +!define PRODUCT_WEB_SITE "https://github.com/sourcegit-scm/sourcegit" +!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\${PRODUCT_NAME}\SourceGit.exe" +!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" +!define PRODUCT_UNINST_ROOT_KEY "HKLM" + +; Set installation and uninstallation icons and name +!define MUI_ICON "resources\app\App.ico" +!define MUI_UNICON "resources\app\App.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" + +; Include language files +!include "MUI2.nsh" + +; Set pages +!insertmacro MUI_PAGE_WELCOME +!insertmacro MUI_PAGE_DIRECTORY +!insertmacro MUI_PAGE_INSTFILES +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES + +; Set language +!insertmacro MUI_LANGUAGE "English" +!insertmacro MUI_LANGUAGE "SimpChinese" +!insertmacro MUI_LANGUAGE "TradChinese" + +; Component descriptions +LangString DESC_SecDesktopShortcut ${LANG_ENGLISH} "Create a desktop shortcut." +LangString DESC_SecStartMenuShortcut ${LANG_ENGLISH} "Create a start menu shortcut." + +; Define some basic properties +Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" +Outfile "sourcegit_${VERSION}.win-x64.installer.exe" +InstallDir $PROGRAMFILES64\${PRODUCT_NAME} +InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" +ShowInstDetails show +ShowUnInstDetails show +RequestExecutionLevel admin + +Function .onInit + !insertmacro MUI_LANGDLL_DISPLAY +FunctionEnd + +; Start installation section +Section "Install" + + ; Set version + WriteRegStr HKLM "Software\${PRODUCT_NAME}" "Version" ${VERSION} + + ; Copy files to installation directory + SetOutPath $INSTDIR + File /r "SourceGit\*.*" + + CreateDirectory "$SMPROGRAMS\SourceGit" + CreateShortCut "$SMPROGRAMS\SourceGit\SourceGit.lnk" "$INSTDIR\SourceGit.exe" + CreateShortCut "$DESKTOP\SourceGit.lnk" "$INSTDIR\SourceGit.exe" + + WriteUninstaller "$INSTDIR\uninst.exe" + WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\SourceGit.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\uninst.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 + +; Start uninstallation section +Section "Uninstall" + + ; Delete all files and directories + RMDir /r $INSTDIR + + Delete "$DESKTOP\SourceGit.lnk" + Delete "$SMPROGRAMS\SourceGit\SourceGit.lnk" + RMDir "$SMPROGRAMS\SourceGit" + + ; Delete uninstallation information + DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" + DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" + +SectionEnd diff --git a/build/build.windows.ps1 b/build/build.windows.ps1 index a218d5cd..980b5aa2 100644 --- a/build/build.windows.ps1 +++ b/build/build.windows.ps1 @@ -21,3 +21,12 @@ dotnet publish ..\src\SourceGit.csproj -c Release -r win-x64 -o SourceGit -p:Pub Remove-Item SourceGit\*.pdb -Force Compress-Archive -Path SourceGit -DestinationPath "sourcegit_$version.win-x64.zip" + +# check nsis exist +$nsisPath = Join-Path -Path ${env:ProgramFiles(x86)} -ChildPath "NSIS\makensis.exe" +if (-not (Test-Path $nsisPath)) { + Write-Host "NSIS not found, please install NSIS from https://nsis.sourceforge.io/Download or run 'choco install nsis -y'" + exit 1 +} + +& $nsisPath /DVERSION=$version .\build.windows.installer.nsi diff --git a/build/resources/app/App.ico b/build/resources/app/App.ico new file mode 100644 index 00000000..9f4972e5 Binary files /dev/null and b/build/resources/app/App.ico differ