[greenstone-devel] for those who want to export colls

From roman chyla
DateThu, 05 Jun 2003 16:55:32 +0200 (CEST)
Subject [greenstone-devel] for those who want to export colls
Hi,

i had to do my own installer and this is something as byproduct.

It would be nice to put it in your export.zip package (as a second
option ; and of course if it si without bugs)
I did it because of many hours I lost with gssetup.exe (setup.exe) -
so others do not need to undergo the same.

some features:

easy
install as many collections as you want
multilingual (I think that the russian is strange; what do you
think?)
write uninstall

please consider it serious, here is address of it
vosk.webpark.cz/installer

and here is code ('cause you are hardworking and I must attach your
attention:)

roman


´------------------------------------------------------------

;
; It will install collections into a directory that the user selects,
;takes coll names from install.ini

;--------------------------------

!include "${NSISDIR}\Contrib\Modern UI\System.nsh"
!include "${NSISDIR}\include\Sections.nsh"

; -------------------------------
; Start


!define MUI_PRODUCT "Greenstone collection(s)"
!define MUI_VERSION "1.0"
!define MUI_BRANDINGTEXT "Ikaros Digital Collection "
CRCCheck On
;--------------------------------
;General

OutFile "install.exe"
ShowInstDetails "nevershow"
ShowUninstDetails "nevershow"
;SetCompressor "bzip2"

!define MUI_ICON "${NSISDIR}\contrib\icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\contrib\icons\modern-uninstall.ico"
!define MUI_SPECIALBITMAP "gsdl2.bmp"


;--------------------------------
;Folder selection page

InstallDir "$PROGRAMFILES\gsdl"


;--------------------------------
;Modern UI Configuration

!define MUI_WELCOMEPAGE

!define MUI_COMPONENTSPAGE
!define MUI_COMPONENTSPAGE_NODESC
!define MUI_DIRECTORYPAGE
!define MUI_FINISHPAGE
;!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN "$INSTDIR\server.exe"

!define MUI_ABORTWARNING

!define MUI_UNINSTALLER
!define MUI_UNCONFIRMPAGE

;--------------------------------
;Language

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "French"
!insertmacro MUI_LANGUAGE "Spanish"
!insertmacro MUI_LANGUAGE "German"
!insertmacro MUI_LANGUAGE "Russian"
!insertmacro MUI_LANGUAGE "Czech"

; Registry key to check for directory (so if you install again, it
will
; overwrite the old one automatically)

InstallDirRegKey HKLM "Software\${MUI_PRODUCT}" "Install_Dir"


;--------------------------------

; The stuff to install
#you must not use these variables after on init function finished
#$R9 - counter of colls
#$9 - installer name for shortcuts and regkeys (if empty defaulting
to MUI_PRODUCT
#stack - do not push anything in it (it holds coll names)
;---------
#here is refference of used variables
;$R3, $R4 - collection strings
;$R1 $R2 - collections=collname#.number
;$R5 - handle of opened collect.cfg
;$0 - coll name taken out from stack

#=========================================================================================
Section "Load collections to computer" sec1

SetOutPath "$INSTDIR"
File "gsdlsite.cfg"

DetailPrint "pocitadlo $R9"


FileOpen "$R5" "$INSTDIR\gsdlsite.cfg" w
FileWrite "$R5" "[gsdl]$\r$\n"
FileWrite "$R5" "gsdlhome=$INSTDIR$\r$\n"
FileWrite "$R5" "gdbmhome=$INSTDIR$\r$\n"

StrCpy "$R6" "$INSTDIR" #portable collection have different path
Call WriteIniAndCopy

FileClose "$R5"


AddSize 5120
ClearErrors
CreateDirectory "$INSTDIR\bin"

CreateDirectory "$INSTDIR\etc"
CreateDirectory "$INSTDIR\images"
CreateDirectory "$INSTDIR\macros"
CreateDirectory "$INSTDIR\mappings"
CreateDirectory "$INSTDIR\net16"
CreateDirectory "$INSTDIR\net32"


ClearErrors
CopyFiles /SILENT "$EXEDIR\gsdl\server.exe" "$INSTDIR"

CopyFiles /SILENT "$EXEDIR\gsdl\etc\*.*" "$INSTDIR\etc"
CopyFiles /SILENT "$EXEDIR\gsdl\images\*.*" "$INSTDIR\images"
CopyFiles /SILENT "$EXEDIR\gsdl\macros\*.*" "$INSTDIR\macros"
CopyFiles /SILENT "$EXEDIR\gsdl\mappings\*.*" "$INSTDIR\mappings"
CopyFiles /SILENT "$EXEDIR\gsdl\net16\*.*" "$INSTDIR\net16"
CopyFiles /SILENT "$EXEDIR\gsdl\net32\*.*" "$INSTDIR\net32"


Call WriteRegAndShortcuts
SectionEnd

#==========================================================================================
Section "Search collections from CD disk" sec2
SetOutPath "$INSTDIR"
File "gsdlsite.cfg"

DetailPrint "pocitadlo $R9"


FileOpen "$R5" "$INSTDIR\gsdlsite.cfg" w
FileWrite "$R5" "[gsdl]$\r$\n"
FileWrite "$R5" "gsdlhome=$EXEDIR\gsdl$\r$\n"
FileWrite "$R5" "gdbmhome=$INSTDIR$\r$\n"
;FileWrite "$R5" "staticpath=$EXEDIR$\r$\n"

StrCpy "$R6" "$EXEDIR\gsdl" #path from where collections are
installed; gsdlhome
Call WriteIniCopyPortable

FileClose "$R5"


AddSize 5120
CreateDirectory "$INSTDIR\etc"
CreateDirectory "$INSTDIR\net16"
CreateDirectory "$INSTDIR\net32"
ClearErrors
CopyFiles /SILENT "$EXEDIR\gsdl\server.exe" "$INSTDIR"
CopyFiles /SILENT "$EXEDIR\gsdl\etc\main.cfg" "$INSTDIR\etc\main.cfg"
CopyFiles /SILENT "$EXEDIR\gsdl\net16\*.*" "$INSTDIR\net16"
CopyFiles /SILENT "$EXEDIR\gsdl\net32\*.*" "$INSTDIR\net32"

Call WriteRegAndShortcuts

SectionEnd

;.............................................................
Function WriteIniAndCopy
StrCpy $R1 ""
StrCpy $R3 ""
ClearErrors


znovu:

Pop $0 #take the coll name from stack (it is the last one)
IfErrors lbl_write

;IfFileExists "$EXEDIR\gsdl\collect\$0\*.*" CollectionExists "" #if
directory does not exist, let us not write ini string
;IntOp $R9 $R9 - 1
;DetailPrint "neexistuje - snizeno na $R9"
;StrCmp $R9 0 lbl_write -6

;CollectionExists:

StrCpy "$R8" "$INSTDIR\collect\$0"
CreateDirectory "$R8"
DetailPrint "Collection $R8"
CopyFiles /SILENT "$EXEDIR\gsdl\collect\$0\*.*" "$R8"
ClearErrors

DetailPrint $0

StrCpy $R2 "collections=$0#$R9$\r$\n"
StrCpy $R4
"[$0#$R9]$\r$\ngsdlhome=$R6$\r$\ngdbmhome=$INSTDIR$\r$\nstaticpath=$R6$\r$\n$\r$\n"
IntOp $R9 $R9 - 1

DetailPrint $R4

StrCpy $R1 "$R2$R1"
StrCpy $R3 "$R4$R3" #pool the coll strings together, the new
at beginning 5+x;4+x;3+x...
IfErrors +2
GoTo znovu

lbl_write:

FileWrite "$R5" "$R1" #write the rest strings into collect.cfg
FileWrite "$R5" "$\r$\n"
FileWrite "$R5" "$\r$\n"

FileWrite $R5 "$R3"


FunctionEnd

Function WriteIniCopyPortable
StrCpy $R1 ""
StrCpy $R3 ""
ClearErrors


znovu:

Pop $0 #take the coll name from stack (it is the last one)
IfErrors lbl_write

;IfFileExists "$EXEDIR\gsdl\collect\$0\*.*" CollectionExists "" #if
directory does not exist, let us not write ini string
;IntOp $R9 $R9 - 1
;DetailPrint "neexistuje - snizeno na $R9"
;StrCmp $R9 0 lbl_write -6

;CollectionExists:

StrCpy "$R8" "$INSTDIR\collect\$0\index\text"
CreateDirectory "$R8"
DetailPrint "directory $R8"
CopyFiles /SILENT "$EXEDIR\gsdl\collect\$0\index\text\$0.ldb" "$R8"
ClearErrors

DetailPrint $0

StrCpy $R2 "collections=$0#$R9$\r$\n"
StrCpy $R4
"[$0#$R9]$\r$\ngsdlhome=$R6$\r$\ngdbmhome=$INSTDIR$\r$\nstaticpath=$R6$\r$\n$\r$\n"
IntOp $R9 $R9 - 1

DetailPrint $R4

StrCpy $R1 "$R2$R1"
StrCpy $R3 "$R4$R3" #pool the coll strings together, the new
at beginning 5+x;4+x;3+x...
IfErrors +2
GoTo znovu

lbl_write:

FileWrite "$R5" "$R1" #write the rest strings into collect.cfg
FileWrite "$R5" "$\r$\n"
FileWrite "$R5" "$\r$\n"

FileWrite $R5 "$R3"


FunctionEnd


Function CopyTheRest


FunctionEnd

Function .onInit

!insertmacro MUI_LANGDLL_DISPLAY
;!insertmacro UnselectSection ${sec2}


#reads values from ini file

FileOpen "$R5" "$EXEDIR\install.ini" r

loop:
FileRead "$R5" "$R1"
IfErrors konec
DetailPrint "$R1"
Call Trim

StrCmp "$R1" "[installer name]" "" lbl_1
FileRead "$R5" "$R1"
Call Trim
StrCpy $9 "$R1"
StrCmp $9 "" "" loop
StrCpy "$9" "${MUI_PRODUCT}"

GoTo loop

lbl_1:
StrCmp "$R1" "[collections]" "" loop

loopColl:
FileRead "$R5" "$R1"
IfErrors konec
DetailPrint "$R1"
Call Trim
DetailPrint "o?ezaná kolekce $R1"

StrCmp $R1 "" loopColl
IntOp $R9 $R9 + 1
Push $R1

GoTo loopColl

konec:
FileClose "$R5"

!insertmacro UnselectSection ${sec2}
FunctionEnd


;----------------
Function .onSelChange

SectionGetFlags ${sec2} $R2
;MessageBox MB_OK "$R2 _ $2"


StrCmp $R2 $2 "" nejsouStejne
StrCmp $R2 "1" "" jePrazdna
!insertmacro ReverseSection ${sec2}
GoTo skip
jePrazdna:
!insertmacro ReverseSection ${sec1}
GoTo skip

nejsouStejne:
StrCmp $R2 "1" "" zaskrtnuta
!insertmacro UnselectSection ${sec1}
GoTo skip

zaskrtnuta:
!insertmacro SelectSection ${sec1}


skip:

SectionGetFlags ${sec2} $2

FunctionEnd


; Trim
; Removes leading & trailing whitespace from a string
;
Function Trim
;Exch $R1 ; Original string
;Push $R2

Loop:
StrCpy $R2 "$R1" 1
StrCmp "$R2" " " TrimLeft
StrCmp "$R2" "$\r" TrimLeft
StrCmp "$R2" "$\n" TrimLeft
StrCmp "$R2" "" TrimLeft ; this is a tab.
GoTo Loop2
TrimLeft:
StrCpy $R1 "$R1" "" 1
Goto Loop

Loop2:
StrCpy $R2 "$R1" 1 -1
StrCmp "$R2" " " TrimRight
StrCmp "$R2" "$\r" TrimRight
StrCmp "$R2" "$\n" TrimRight
StrCmp "$R2" "" TrimRight ; this is a tab
GoTo Done
TrimRight:
StrCpy $R1 "$R1" -1
Goto Loop2

Done:
;Pop $R2
;Exch $R1
FunctionEnd

Function WriteRegAndShortcuts

;create start-menu items
CreateDirectory "$SMPROGRAMS\${MUI_PRODUCT}"
CreateShortCut "$SMPROGRAMS\${MUI_PRODUCT}\$9.lnk"
"$INSTDIR\server.exe" "" "$INSTDIR\server.exe" 0
CreateShortCut "$SMPROGRAMS\${MUI_PRODUCT}\Uninstall.lnk"
"$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0


;Desktop shortcut

CreateShortCut "$DESKTOP\$9.lnk" "$INSTDIR\server.exe" ""
"$INSTDIR\server.exe" 0

;write RegKeys
WriteRegStr HKLM "Software\${MUI_PRODUCT}" "Install_Dir" "$INSTDIR"
WriteRegStr HKLM "Software\${MUI_PRODUCT}" "Installer Name" "$9"

;write uninstall information to the registry
WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
"DisplayName" "${MUI_PRODUCT} ($9)"
WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
"UninstallString" "$INSTDIR\Uninstall.exe"

WriteUninstaller "$INSTDIR\Uninstall.exe"


FunctionEnd

;--------------------------------
;Uninstaller Section
Section "Uninstall"

;Delete Uninstaller And Unistall Registry Entries
Delete "$INSTDIR\uninstall.exe"


ReadRegStr "$9" HKLM "SOFTWARE\${MUI_PRODUCT}" "Installer Name"

;MessageBox MB_OK "$9"

DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\${MUI_PRODUCT}"
DeleteRegKey HKEY_LOCAL_MACHINE
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"
#this was not so easy as one would think about removing

;Delete Files

ClearErrors
FindFirst $0 $1 "$INSTDIR\collect\*.*"
IfErrors NotFound

DoFindNext:
FindNext $0 $1
IfErrors NotFound

StrCmp $1 "." DoFindNext
StrCmp $1 ".." DoFindNext

Push $1
GoTo DoFindNext


NotFound:
FindClose $0

RemoveNext:
ClearErrors
Pop $1

IfErrors CloseRMDir
StrCmp "$1" "" CloseRMDir ""
DetailPrint "Removing collect/$1 ... Please wait"

Delete "$INSTDIR\collect\$1\index\assoc\*.*"
Delete "$INSTDIR\collect\$1\*.*"
Sleep "100"
RMDir /r "$INSTDIR\collect\$1"
Sleep "100"
GoTo RemoveNext

CloseRMDir:
;MessageBox MB_OK|MB_YESNO "Close rmdir" IDNO RemoveNext

;Remove the installation directory

Delete "$INSTDIR\etc\*.*"
Delete "$INSTDIR\images\*.*"
Delete "$INSTDIR\macros\*.*"
Delete "$INSTDIR\mappings\*.*"
Delete "$INSTDIR\net16\*.*"
Delete "$INSTDIR\net32\*.*"

Delete "$INSTDIR\*.*"
RMDir /r "$INSTDIR"
;MessageBox MB_OK "je problem tady?"
;Delete Start Menu Shortcuts
Delete "$DESKTOP\$9.lnk"
Delete "$SMPROGRAMS\${MUI_PRODUCT}\*.*"
RMDir "$SMPROGRAMS\${MUI_PRODUCT}"


SectionEnd


;--------------------------------
;MessageBox Section


;Function that calls a messagebox when installation finished
correctly


Function un.onUninstSuccess
MessageBox MB_OK "You have successfully uninstalled
${MUI_PRODUCT}."
FunctionEnd


______________________________________________________________________
Reklama:
Jsi p?ipraven na nejvyhodnej?i surfování p?es http://ad2.seznam.cz/redir.cgi?instance=55048%26url=http://www.razdva.cz