SetCompressor /SOLID lzma

; Script generated by the HM NIS Edit Script Wizard.
;!include PathMani.nsh

; HM NIS Edit Wizard helper defines
!define GNM_NAME		"Gnumeric"
!define GNM_LONGNAME		"Gnumeric Spreadsheet"
!define GNM_APPNAME		"Gnumeric Spreadsheet"
!define GNM_VERSION		"1.12.18"
!define GNM_VERSION_TAG		"20141015"
!define GNM_VERSION_FULL	"${GNM_VERSION}-${GNM_VERSION_TAG}"
!define GNM_UNINST_KEY		"Software\Microsoft\Windows\CurrentVersion\Uninstall\${GNM_NAME}"
!define GNM_STARTMENU_REG_VAL	"NSIS:StartMenuDir"
!define GNM_HELP_DIR		"share\gnumeric\${GNM_VERSION}\doc\C"
!define GNM_HELP		"${GNM_HELP_DIR}\gnumeric.chm"

!define GOFFICE_VERSION		"0.10.15"

;!define GTK_VERSION		"3.9"
;!define GTK_VENDORRC		"0"
;!define GTK_VENDORVERSION	"${GTK_VERSION}.${GTK_VENDORRC}"

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

;ReserveFile "op1.ini"
;ReserveFile "op3.ini"
;!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;!insertmacro MUI_RESERVEFILE_LANGDLL

; 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"

!define MUI_WELCOMEPAGE_TITLE_3LINES
!define MUI_WELCOMEPAGE_TEXT "You can always get the newest version from:\r\n\r\nhttp://www.gnumeric.org/\r\n\r\nThis wizard will guide you through the installation of $(^NameDA).\r\n\r\nIt is recommended that you close all other applications before starting Setup. This will make it possible to update relevant system files without having to reboot your computer.\r\n\r\n$_CLICK"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "COPYING-gpl2"

Page custom CustomPageShortcut
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY

var ICONS_GROUP
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Gnumeric"
!insertmacro MUI_PAGE_STARTMENU Application $ICONS_GROUP
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_TITLE_3LINES
!define MUI_FINISHPAGE_LINK "Visit the Gnumeric website for the latest news"
!define MUI_FINISHPAGE_LINK_LOCATION "http://www.gnumeric.org/"
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

InstType "Standard"
InstType "Minimal"
InstType "Full"

; MUI end ------

Var SHORTINSTDIR
Var ISADMIN
Var INI_VALUE

Name "${GNM_LONGNAME} ${GNM_VERSION_FULL}"
OutFile			"gnumeric-${GNM_VERSION_FULL}.exe"
Icon			"share\pixmaps\win32-gnumeric.ico"
InstallDir		"$PROGRAMFILES\${GNM_NAME}"
InstallDirRegKey	HKLM "Software\GNOME\${GNM_NAME}" "Path"
ShowInstDetails		hide
ShowUnInstDetails	show

!define GNM_ROOT	"$INSTDIR\${GNM_VERSION}"

!macro CopyDir THEDIR
    SetOutPath "${GNM_ROOT}\${THEDIR}"
    File /r "${THEDIR}\*"
!macroend

Section "Gnumeric (required)" SEC01
    SectionIn 1 2 3 RO

    SetOutPath "${GNM_ROOT}\bin"
    File /x "libpython*.dll" "bin\*.dll"
    File "bin\gnumeric.exe"
    File "bin\ssconvert.exe"
    File "bin\ssgrep.exe"
    File "bin\ssdiff.exe"
    File "bin\gsf.exe"
    ;File "bin\gsf-vba-dump.exe"
    File "bin\gtk-update-icon-cache.exe"
    File "bin\gdk-pixbuf-query-loaders.exe"
    File "bin\pango-querymodules.exe"

    # required for g_spawn_*
    File "bin\gspawn-win32-helper-console.exe"
    File "bin\gspawn-win32-helper.exe"

    SetOutPath "${GNM_ROOT}\lib"
    File /r /x "*.a" /x "*.la" /x "*.lib" /x "*.def" /x "pkgconfig" /x "include" /x "Python2.7" /x "*Conf.sh" "lib\*"

    !insertmacro CopyDir "etc"
    !insertmacro CopyDir "share\themes"
    !insertmacro CopyDir "share\gnumeric"
    !insertmacro CopyDir "share\libthai"
    !insertmacro CopyDir "share\pixmaps"
    !insertmacro CopyDir "share\icons"
    !insertmacro CopyDir "share\glib-2.0\schemas"

    SetOutPath "${GNM_ROOT}\${GNM_HELP_DIR}"
    File "${GNM_HELP}"
    File "${GNM_HELP_DIR}\gnumeric.hhmap"

    WriteRegStr SHCTX "Software\GNOME\${GNM_NAME}" "Path" "${GNM_ROOT}\bin"
    WriteRegStr SHCTX "Software\GNOME\${GNM_NAME}" "Version" "${GNM_VERSION_FULL}"

    GetFullPathName /SHORT $SHORTINSTDIR ${GNM_ROOT}
    StrCmp $ISADMIN "1" 0 +5
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.dialogs.reg"
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.reg"
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.plugin.reg"
    Goto +4
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.dialogs.hkcu.reg"
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.hkcu.reg"
	ExecWait "regedit /s $SHORTINSTDIR\etc\win32\reg\org.gnome.gnumeric.plugin.hkcu.reg"

    ExecWait "${GNM_ROOT}\bin\gdk-pixbuf-query-loaders.exe --update-cache"
    ExecWait "${GNM_ROOT}\bin\pango-querymodules.exe --update-cache"
    ;ExecWait "${GNM_ROOT}\gtk-update-icon-cache.exe ${GNM_ROOT}\share\icons\gnome"
    ;ExecWait "${GNM_ROOT}\gtk-update-icon-cache.exe ${GNM_ROOT}\share\icons\hicolor"

    WriteRegStr HKCR "GNOME.Gnumeric"					"" "Gnumeric Spreadsheet"
    WriteRegStr HKCR "GNOME.Gnumeric\shell"				"" "Open"
    WriteRegStr HKCR "GNOME.Gnumeric\DefaultIcon"			"" "${GNM_ROOT}\bin\gnumeric.exe,0"
    WriteRegStr HKCR "GNOME.Gnumeric\shell\Open\command"		"" '"${GNM_ROOT}\bin\gnumeric.exe" "%1"'
    WriteRegStr HKCR "Applications\gnumeric.exe\shell\Open\command"	"" '"${GNM_ROOT}\bin\gnumeric.exe" "%1"'
SectionEnd

#############################################################################

SectionGroup "File Handlers"
Section "Gnumeric (.gnumeric)"
    SectionIn 1 2 3
    WriteRegStr HKCR ".gnumeric" ""		"GNOME.Gnumeric"
    WriteRegStr HKCR ".gnumeric" "Content Type" "application/x-gnumeric"
SectionEnd

Section "MS Excel (tm)"
    SectionIn 3
    WriteRegStr HKCR ".xls" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".xls" "Content Type"	"application/vnd.ms-excel"

    WriteRegStr HKCR ".xlw" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".xlw" "Content Type"	"application/vnd.ms-excel"

    WriteRegStr HKCR ".xlt" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".xlt" "Content Type"	"application/vnd.ms-excel"

    WriteRegStr HKCR ".xlsx" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".xlsx" "Content Type"	"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    WriteRegStr HKCR ".xltx" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".xltx" "Content Type"	"application/vnd.openxmlformats-officedocument.spreadsheetml.template"
SectionEnd
Section "OpenOffice.org ODF"
    SectionIn 3
    WriteRegStr HKCR ".ods" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".ods" "Content Type"	"vnd.oasis.opendocument.spreadsheet"
    WriteRegStr HKCR ".ots" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".ots" "Content Type"	"vnd.oasis.opendocument.spreadsheet-template"
    WriteRegStr HKCR ".sxc" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".sxc" "Content Type"	"application/vnd.sun.xml.calc"
    WriteRegStr HKCR ".stc" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".stc" "Content Type"	"application/vnd.sun.xml.calc.template"
SectionEnd
Section "Lotus 123 (tm)"
    SectionIn 3
    WriteRegStr HKCR ".wk1" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wk1" "Content Type"	"application/vnd.lotus-1-2-3"
    WriteRegStr HKCR ".wk4" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wk4" "Content Type"	"application/vnd.lotus-1-2-3"
    WriteRegStr HKCR ".wr1" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wr1" "Content Type"	"application/vnd.lotus-1-2-3"
    WriteRegStr HKCR ".wks" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wks" "Content Type"	"application/vnd.lotus-1-2-3"
    WriteRegStr HKCR ".123" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".123" "Content Type"	"application/vnd.lotus-1-2-3"
SectionEnd
Section "Applix (.as)"
    SectionIn 1 3
    WriteRegStr HKCR ".as" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".as" "Content Type"	"application/x-applix-spreadsheet"
SectionEnd
Section "Quattro Pro (tm)"
    SectionIn 1 3
    WriteRegStr HKCR ".wb1" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wb1" "Content Type"	"application/x-quattro-pro"
    WriteRegStr HKCR ".wb2" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wb2" "Content Type"	"application/x-quattro-pro"
    WriteRegStr HKCR ".wb3" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".wb3" "Content Type"	"application/x-quattro-pro"
SectionEnd
Section "Plan Perfect (tm)"
    SectionIn 1 3
    WriteRegStr HKCR ".pln" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".pln" "Content Type"	"application/x-planperfect"
SectionEnd
Section "Psiconv"
    SectionIn 1 3
    WriteRegStr HKCR ".psisheet" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".psisheet" "Content Type"	"application/x-psiconv"
SectionEnd
Section "Data Interchange Format (.dif)"
    SectionIn 1 3
    WriteRegStr HKCR ".dif" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".dif" "Content Type"	"application/x-dif-spreadsheet"
SectionEnd
Section "Multiplan SYLK"
    SectionIn 1 3
    WriteRegStr HKCR ".slk" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".slk" "Content Type"	"application/x-sylk"
    WriteRegStr HKCR ".sylk" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".sylk" "Content Type"	"application/x-sylk"
SectionEnd
Section "GNU Oleo"
    SectionIn 1 3
    WriteRegStr HKCR ".oleo" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".oleo" "Content Type"	"application/x-oleo"
SectionEnd
Section "Paradox Database (tm)"
    SectionIn 1 3
    WriteRegStr HKCR ".px" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".px" "Content Type"	"application/x-paradox-db"
SectionEnd
Section "XBase Database (tm)"
    SectionIn 1 3
    WriteRegStr HKCR ".dbf" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".dbf" "Content Type"	"application/dbf"
SectionEnd
Section "MPS linear and integer programs"
    SectionIn 1 3
    WriteRegStr HKCR ".mps" ""			"GNOME.Gnumeric"
    WriteRegStr HKCR ".mps" "Content Type"	"application/x-mps"
SectionEnd

SectionGroupEnd

#############################################################################

!macro Locale LOCALE
Section "${LOCALE} Translation"
    SectionIn 1 3
    SetOutPath "${GNM_ROOT}\share\locale\${LOCALE}\LC_MESSAGES"
    File "share\locale\${LOCALE}\LC_MESSAGES\gtk30.mo"
    File "share\locale\${LOCALE}\LC_MESSAGES\glib20.mo"
    File /nonfatal "share\locale\${LOCALE}\LC_MESSAGES\goffice-${GOFFICE_VERSION}.mo"
    File "share\locale\${LOCALE}\LC_MESSAGES\gnumeric-${GNM_VERSION}.mo"
    File "share\locale\${LOCALE}\LC_MESSAGES\gnumeric-${GNM_VERSION}-functions.mo"
SectionEnd
!macroend

SectionGroup "Translations"
    !insertmacro Locale "am"
    !insertmacro Locale "ar"
    !insertmacro Locale "ast"
    !insertmacro Locale "az"
    !insertmacro Locale "bg"
    !insertmacro Locale "ca"
    !insertmacro Locale "ca@valencia"
    !insertmacro Locale "cs"
    !insertmacro Locale "da"
    !insertmacro Locale "de"
    !insertmacro Locale "dz"
    !insertmacro Locale "el"
    !insertmacro Locale "en_CA"
    !insertmacro Locale "en_GB"
    !insertmacro Locale "eo"
    !insertmacro Locale "es"
    !insertmacro Locale "et"
    !insertmacro Locale "eu"
    !insertmacro Locale "fi"
    !insertmacro Locale "fr"
    !insertmacro Locale "ga"
    !insertmacro Locale "gl"
    !insertmacro Locale "gu"
    !insertmacro Locale "he"
    !insertmacro Locale "hr"
    !insertmacro Locale "hu"
    !insertmacro Locale "id"
    !insertmacro Locale "it"
    !insertmacro Locale "ja"
    !insertmacro Locale "kk"
    !insertmacro Locale "ko"
    !insertmacro Locale "lt"
    !insertmacro Locale "lv"
    !insertmacro Locale "mk"
    !insertmacro Locale "ml"
    !insertmacro Locale "mr"
    !insertmacro Locale "ms"
    !insertmacro Locale "nb"
    !insertmacro Locale "ne"
    !insertmacro Locale "nl"
    !insertmacro Locale "nn"
    !insertmacro Locale "oc"
    !insertmacro Locale "pl"
    !insertmacro Locale "pt"
    !insertmacro Locale "pt_BR"
    !insertmacro Locale "ro"
    !insertmacro Locale "ru"
    !insertmacro Locale "rw"
    !insertmacro Locale "sk"
    !insertmacro Locale "sl"
    !insertmacro Locale "sr"
    !insertmacro Locale "sr@latin"
    !insertmacro Locale "sv"
    !insertmacro Locale "te"
    !insertmacro Locale "tr"
    !insertmacro Locale "uk"
    !insertmacro Locale "vi"
    !insertmacro Locale "zh_CN"
    !insertmacro Locale "zh_HK"
    !insertmacro Locale "zh_TW"
SectionGroupEnd

#############################################################################

Section -AdditionalIcons
    SetOutPath "${GNM_ROOT}\bin"
    CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
    CreateShortCut  "$SMPROGRAMS\$ICONS_GROUP\${GNM_APPNAME}.lnk"	"${GNM_ROOT}\bin\gnumeric.exe"
    CreateShortCut  "$SMPROGRAMS\$ICONS_GROUP\${GNM_APPNAME} Help.lnk"	"${GNM_ROOT}\${GNM_HELP}"
    CreateShortCut  "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"		"${GNM_ROOT}\bin\uninst.exe"
SectionEnd

Section -Post
    SetOutPath "$INSTDIR"
    WriteUninstaller "${GNM_ROOT}\bin\uninst.exe"

    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "DisplayName"			"$(^Name)"
    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "UninstallString"		"${GNM_ROOT}\bin\uninst.exe"
    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "DisplayVersion"		"${GNM_VERSION_FULL}"
    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "${GNM_STARTMENU_REG_VAL}"	"$ICONS_GROUP"
    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "Context"			"$ISADMIN"
    WriteRegStr SHCTX "${GNM_UNINST_KEY}" "RootDir"			"$INSTDIR"
SectionEnd

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

LangString TEXT_IO_TITLE_OP1	${LANG_ENGLISH} "Install Option"
LangString TEXT_IO_SUBTITLE_OP1 ${LANG_ENGLISH} "You can choose to install ${GNM_NAME} for anyone who uses this computer or only you."

Function CustomPageShortcut
    ClearErrors
    UserInfo::GetName
    IfErrors Win9x
	Pop $0
	UserInfo::GetAccountType
	Pop $1
	StrCmp $1 "Admin" 0 not_admin
    Win9x:
	!insertmacro MUI_HEADER_TEXT			"$(TEXT_IO_TITLE_OP1)" "$(TEXT_IO_SUBTITLE_OP1)"
	!insertmacro MUI_INSTALLOPTIONS_DISPLAY		"op1.ini"
	!insertmacro MUI_INSTALLOPTIONS_READ $INI_VALUE "op1.ini" "Field 2" "State"
	StrCmp $INI_VALUE "1" 0 not_admin
	StrCpy $ISADMIN "1"
	SetShellVarContext all
	Goto done
    not_admin:
	StrCpy $ISADMIN "0"
	SetShellVarContext current
    done:
FunctionEnd

Function .onInit
	InitPluginsDir
;  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "op1.ini"
;  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "op3.ini"
FunctionEnd

Function un.onInit
    MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
    Abort
FunctionEnd
Function un.onUninstSuccess
    HideWindow
    MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd
Section Uninstall
    Push $1

    ReadRegStr $INSTDIR SHCTX "${GNM_UNINST_KEY}" "RootDir"
    SetOutPath "$INSTDIR"
    RMDir /r /REBOOTOK "${GNM_ROOT}"

    ReadRegStr $ISADMIN SHCTX "${GNM_UNINST_KEY}" "Context"
    StrCmp $ISADMIN "1" 0 +2
	SetShellVarContext all

    ReadRegStr $ICONS_GROUP SHCTX "${GNM_UNINST_KEY}" "${GNM_STARTMENU_REG_VAL}"
    Delete "$SMPROGRAMS\$ICONS_GROUP\${GNM_APPNAME}.lnk"
    Delete "$SMPROGRAMS\$ICONS_GROUP\${GNM_APPNAME} Help.lnk"
    Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"
    RMDir "$SMPROGRAMS\$ICONS_GROUP"

    GetFullPathName /SHORT $SHORTINSTDIR ${GNM_ROOT}

    DeleteRegKey SHCTX "${GNM_UNINST_KEY}"

    ReadRegStr $1 SHCTX "Software\GNOME\${GNM_NAME}" "Path"
    StrCmp $1 "${GNM_ROOT}" 0 +2
	DeleteRegValue SHCTX "Software\GNOME\${GNM_NAME}" "Path"

    DeleteRegKey /ifempty SHCTX "Software\GNOME\${GNM_NAME}"
    DeleteRegKey /ifempty SHCTX "Software\GNOME"

#    SetAutoClose true

    Pop $1
SectionEnd

