Skip to content

Commit

Permalink
Fix the NSIS installer and change its encoding to UTF-8 with BOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
PCMan committed Aug 16, 2015
1 parent ca5eb05 commit 861eb67
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 61 deletions.
10 changes: 2 additions & 8 deletions installer/README.txt
@@ -1,12 +1,6 @@
To build an installer:

1. Put libchewing/data/*.dat dictionary files in Dictionary subdir.
1. Build release version of PIMETextService.dll (both 64 bit and 32 bit versions are required)

2. Put 64-bit ChewingTextService.dll in x64 subdir.

3. Put 32-bit ChewingTextService.dll in x86 subdir.

4. Put `32-bit` ChewingPreferences.exe in this dir.

5. Compile installer.nsi with NSIS.
2. Compile installer.nsi with NSIS.

115 changes: 62 additions & 53 deletions installer/installer.nsi
@@ -1,5 +1,5 @@
;
; Copyright (C) 2013 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
;
; Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
;
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Library General Public
Expand All @@ -23,23 +23,25 @@
!include "LogicLib.nsh" ; for ${If}, ${Switch} commands

Unicode true ; turn on Unicode (This requires NSIS 3.0)
SetCompressor lzma ; use LZMA for best compression ratio
SetCompressor /SOLID lzma ; use LZMA for best compression ratio
SetCompressorDictSize 16 ; larger dictionary size for better compression ratio
AllowSkipFiles off ; cannot skip a file

; icons of the generated installer and uninstaller
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
!define PRODUCT_VERSION "git"

!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\ChewingTextService"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\PIME"
!define HOMEPAGE_URL "https://github.com/EasyIME/"

Name "新酷音輸入法"
BrandingText "新酷音輸入法"
Name "PIME 輸入法"
BrandingText "PIME 輸入法"

OutFile "windows-chewing-tsf.exe" ; The generated installer file name
OutFile "PIME-${PRODUCT_VERSION}-setup.exe" ; The generated installer file name

; We install everything to C:\Program Files (x86)
InstallDir "$PROGRAMFILES32\ChewingTextService"
InstallDir "$PROGRAMFILES32\PIME"

;Request application privileges (need administrator to install)
RequestExecutionLevel admin
Expand All @@ -55,8 +57,8 @@ RequestExecutionLevel admin
!insertmacro MUI_PAGE_INSTFILES

; finish page
!define MUI_FINISHPAGE_LINK_LOCATION "http://chewing.im/"
!define MUI_FINISHPAGE_LINK "新酷音專案網頁 ${MUI_FINISHPAGE_LINK_LOCATION}"
!define MUI_FINISHPAGE_LINK_LOCATION "${HOMEPAGE_URL}"
!define MUI_FINISHPAGE_LINK "PIME 專案網頁 ${MUI_FINISHPAGE_LINK_LOCATION}"
!insertmacro MUI_PAGE_FINISH

; uninstallation pages
Expand All @@ -73,7 +75,7 @@ Function uninstallOldVersion
ReadRegStr $R0 HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
${If} $R0 != ""
ClearErrors
MessageBox MB_OKCANCEL|MB_ICONQUESTION "偵測到已安裝舊版,是否要移除舊版後繼續安裝新版?" IDOK +2
MessageBox MB_OKCANCEL|MB_ICONQUESTION "偵測到已安裝舊版,是否要移除舊版後繼續安裝新版?" IDOK +2
Abort ; this is skipped if the user select OK

CopyFiles "$INSTDIR\Uninstall.exe" "$TEMP"
Expand All @@ -84,11 +86,11 @@ Function uninstallOldVersion
;ClearErrors
; Ensure that old files are all deleted
;${If} ${RunningX64}
; ${If} ${FileExists} "$INSTDIR\x64\ChewingTextService.dll"
; ${If} ${FileExists} "$INSTDIR\x64\PIMETextService.dll"
; Call onInstError
; ${EndIf}
;${EndIf}
;${If} ${FileExists} "$INSTDIR\x86\ChewingTextService.dll"
;${If} ${FileExists} "$INSTDIR\x86\PIMETextService.dll"
; Call onInstError
;${EndIf}
;${If} ${FileExists} "$INSTDIR\Dictionary\*.dat"
Expand All @@ -100,7 +102,7 @@ FunctionEnd
Function .onInit
; Currently, we're not able to support Windows xp since it has an incomplete TSF.
${IfNot} ${AtLeastWinVista}
MessageBox MB_ICONSTOP|MB_OK "抱歉,本程式目前只能支援 Windows Vista 以上版本"
MessageBox MB_ICONSTOP|MB_OK "抱歉,本程式目前只能支援 Windows Vista 以上版本"
Quit
${EndIf}

Expand All @@ -114,57 +116,65 @@ FunctionEnd

; called to show an error message when errors happen
Function .onInstFailed
MessageBox MB_ICONSTOP|MB_OK "安裝發生錯誤,無法完成。$\n$\n可能有檔案正在使用中,暫時無法刪除或覆寫$\n$\n建議重新開機後,再次執行安裝程式。"
MessageBox MB_ICONSTOP|MB_OK "安裝發生錯誤,無法完成。$\n$\n可能有檔案正在使用中,暫時無法刪除或覆寫$\n$\n建議重新開機後,再次執行安裝程式。"
FunctionEnd

; called to show an error message when errors happen
;Function onInstError
; MessageBox MB_ICONSTOP|MB_OK "安裝發生錯誤,舊版可能有檔案正在使用中,暫時無法覆寫$\n$\n請重開機後,再次執行安裝程式。"
; MessageBox MB_ICONSTOP|MB_OK "安裝發生錯誤,舊版可能有檔案正在使用中,暫時無法覆寫$\n$\n請重開機後,再次執行安裝程式。"
; Abort
;FunctionEnd

;Installer Sections
Section "新酷音輸入法" SecMain
SetOutPath "$INSTDIR"
Section "新酷音輸入法" SecMain

; TODO: may be we can automatically rebuild the dlls here.
; http://stackoverflow.com/questions/24580/how-do-you-automate-a-visual-studio-build
; For example, we can build the Visual Studio solution with the following command line.
; C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com "..\build\PIME.sln" /build Release

SetOverwrite on ; overwrite existing files
${If} ${RunningX64}
File /r "x64" ; put 64-bit ChewingTextService.dll in x64 folder
SetOutPath "$INSTDIR"
; FIXME: install python and pywin32 automatically as needed
; Download and install python 3.4.3
; nsisdl::download https://www.python.org/ftp/python/3.4.3/python-3.4.3.msi $0
; ExecWait '"msiexec" /i "$0"'

; Download and install pywin32
; nsisdl::download http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win32-py3.4.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpywin32%2Ffiles%2Fpywin32%2FBuild%2520219%2F&ts=1439740165 $0
; ExecWait "$0"

; Install the python server and input method modules
File /r /x __pycache__ ..\server
; File PIMELauncher.exe

; Install the text service dlls
${If} ${RunningX64} ; This is a 64-bit Windows system
SetOutPath "$INSTDIR\x64"
File "..\build64\pime\Release\PIMETextService.dll" ; put 64-bit PIMETextService.dll in x64 folder
${EndIf}
File /r "x86" ; put 32-bit ChewingTextService.dll in x86 folder
File /r Dictionary ; Install dictionary files
File ChewingPreferences.exe ; Configuration Tool
SetOutPath "$INSTDIR\x86"
File "..\build\pime\Release\PIMETextService.dll" ; put 32-bit PIMETextService.dll in x86 folder

; Register COM objects (NSIS RegDLL command is broken and cannot be used)
ExecWait '"$SYSDIR\regsvr32.exe" /s "$INSTDIR\x86\ChewingTextService.dll"'
ExecWait '"$SYSDIR\regsvr32.exe" /s "$INSTDIR\x86\PIMETextService.dll"'
${If} ${RunningX64}
ExecWait '"$SYSDIR\regsvr32.exe" /s "$INSTDIR\x64\ChewingTextService.dll"'
ExecWait '"$SYSDIR\regsvr32.exe" /s "$INSTDIR\x64\PIMETextService.dll"'
${EndIf}

; Special handling for Windows 8
${If} ${AtLeastWin8}
File SetupChewing.bat
${If} ${RunningX64}
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "SetupChewing" \
"rundll32.exe $\"$INSTDIR\x64\ChewingTextService.dll$\",ChewingSetup"
${Else}
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "SetupChewing" \
"rundll32.exe $\"$INSTDIR\x86\ChewingTextService.dll$\",ChewingSetup"
${EndIf}
; Run SetupChewing.bat as current user (ask explorer to open it for us)
; Reference: http:;mdb-blog.blogspot.tw/2013/01/nsis-lunch-program-as-user-from-uac.html
; Though it's more reliable to use the UAC plugin, I think this hack is enough for most cases.
ExecWait 'explorer.exe "$INSTDIR\SetupChewing.bat"'
${EndIf}
; Launch the python server on startup
; TODO: write the PIMELauncher program
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "PIMELauncher" "$INSTDIR\PIMELauncher.exe"

;Store installation folder in the registry
WriteRegStr HKLM "Software\ChewingTextService" "" $INSTDIR
WriteRegStr HKLM "Software\PIME" "" $INSTDIR
;Write an entry to Add & Remove applications
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "新酷音輸入法 (TSF)"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "PIME 輸入法"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "新酷音輸入法開發團隊"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\x86\ChewingTextService.dll"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "PIME 開發團隊"
; WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\x86\PIMETextService.dll"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "http://chewing.im/"
WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${HOMEPAGE_URL}"
WriteUninstaller "$INSTDIR\Uninstall.exe" ;Create uninstaller
SectionEnd

Expand All @@ -180,21 +190,20 @@ LangString DESC_SecMain ${LANG_ENGLISH} "A test section." ; What's this??
Section "Uninstall"

; Unregister COM objects (NSIS UnRegDLL command is broken and cannot be used)
ExecWait '"$SYSDIR\regsvr32.exe" /u /s "$INSTDIR\x86\ChewingTextService.dll"'
ExecWait '"$SYSDIR\regsvr32.exe" /u /s "$INSTDIR\x86\PIMETextService.dll"'
${If} ${RunningX64}
SetRegView 64 ; disable registry redirection and use 64 bit Windows registry directly
ExecWait '"$SYSDIR\regsvr32.exe" /u /s "$INSTDIR\x64\ChewingTextService.dll"'
ExecWait '"$SYSDIR\regsvr32.exe" /u /s "$INSTDIR\x64\PIMETextService.dll"'
RMDir /r "$INSTDIR\x64"
${EndIf}

RMDir /r "$INSTDIR\x86"
RMDir /r "$INSTDIR\Dictionary"
Delete "$INSTDIR\SetupChewing.bat"
Delete "$INSTDIR\ChewingPreferences.exe"
RMDir /r "$INSTDIR\server"
; Delete "$INSTDIR\PIMELauncher.exe"

DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ChewingTextService"
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "SetupChewing"
DeleteRegKey /ifempty HKLM "Software\ChewingTextService"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\PIME"
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "PIMELauncher"
DeleteRegKey /ifempty HKLM "Software\PIME"

Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
Expand Down

0 comments on commit 861eb67

Please sign in to comment.