[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}ContribModern UISystem.nsh"
!include "${NSISDIR}includeSections.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}contribiconsmodern-install.ico"
!define MUI_UNICON "${NSISDIR}contribiconsmodern-uninstall.ico"
!define MUI_SPECIALBITMAP "gsdl2.bmp"


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

InstallDir "$PROGRAMFILESgsdl"


;--------------------------------
;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 "$INSTDIRserver.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" "$INSTDIRgsdlsite.cfg" w
FileWrite "$R5" "[gsdl]$r$ "
FileWrite "$R5" "gsdlhome=$INSTDIR$r$ "
FileWrite "$R5" "gdbmhome=$INSTDIR$r$ "

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

FileClose "$R5"


AddSize 5120
ClearErrors
CreateDirectory "$INSTDIRbin"

CreateDirectory "$INSTDIRetc"
CreateDirectory "$INSTDIRimages"
CreateDirectory "$INSTDIRmacros"
CreateDirectory "$INSTDIRmappings"
CreateDirectory "$INSTDIRnet16"
CreateDirectory "$INSTDIR et32"


ClearErrors
CopyFiles /SILENT "$EXEDIRgsdlserver.exe" "$INSTDIR"

CopyFiles /SILENT "$EXEDIRgsdletc*.*" "$INSTDIRetc"
CopyFiles /SILENT "$EXEDIRgsdlimages*.*" "$INSTDIRimages"
CopyFiles /SILENT "$EXEDIRgsdlmacros*.*" "$INSTDIRmacros"
CopyFiles /SILENT "$EXEDIRgsdlmappings*.*" "$INSTDIRmappings"
CopyFiles /SILENT "$EXEDIRgsdl et16*.*" "$INSTDIR et16"
CopyFiles /SILENT "$EXEDIRgsdl et32*.*" "$INSTDIR et32"


Call WriteRegAndShortcuts
SectionEnd

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

DetailPrint "pocitadlo $R9"


FileOpen "$R5" "$INSTDIRgsdlsite.cfg" w
FileWrite "$R5" "[gsdl]$r$ "
FileWrite "$R5" "gsdlhome=$EXEDIRgsdl$r$ "
FileWrite "$R5" "gdbmhome=$INSTDIR$r$ "
;FileWrite "$R5" "staticpath=$EXEDIR$r$ "

StrCpy "$R6" "$EXEDIRgsdl" #path from where collections are
installed; gsdlhome
Call WriteIniCopyPortable

FileClose "$R5"


AddSize 5120
CreateDirectory "$INSTDIRetc"
CreateDirectory "$INSTDIR et16"
CreateDirectory "$INSTDIR et32"
ClearErrors
CopyFiles /SILENT "$EXEDIRgsdlserver.exe" "$INSTDIR"
CopyFiles /SILENT "$EXEDIRgsdletcmain.cfg" "$INSTDIRetcmain.cfg"
CopyFiles /SILENT "$EXEDIRgsdl et16*.*" "$INSTDIR et16"
CopyFiles /SILENT "$EXEDIRgsdl et32*.*" "$INSTDIR et32"

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 "$EXEDIRgsdlcollect$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" "$INSTDIRcollect$0"
CreateDirectory "$R8"
DetailPrint "Collection $R8"
CopyFiles /SILENT "$EXEDIRgsdlcollect$0*.*" "$R8"
ClearErrors

DetailPrint $0

StrCpy $R2 "collections=$0#$R9$r$ "
StrCpy $R4
"[$0#$R9]$r$ gsdlhome=$R6$r$ gdbmhome=$INSTDIR$r$ staticpath=$R6$r$ $r$ "
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$ "
FileWrite "$R5" "$r$ "

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 "$EXEDIRgsdlcollect$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" "$INSTDIRcollect$0index ext"
CreateDirectory "$R8"
DetailPrint "directory $R8"
CopyFiles /SILENT "$EXEDIRgsdlcollect$0index ext$0.ldb" "$R8"
ClearErrors

DetailPrint $0

StrCpy $R2 "collections=$0#$R9$r$ "
StrCpy $R4
"[$0#$R9]$r$ gsdlhome=$R6$r$ gdbmhome=$INSTDIR$r$ staticpath=$R6$r$ $r$ "
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$ "
FileWrite "$R5" "$r$ "

FileWrite $R5 "$R3"


FunctionEnd


Function CopyTheRest


FunctionEnd

Function .onInit

!insertmacro MUI_LANGDLL_DISPLAY
;!insertmacro UnselectSection ${sec2}


#reads values from ini file

FileOpen "$R5" "$EXEDIRinstall.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" "$ " 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" "$ " 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"
"$INSTDIRserver.exe" "" "$INSTDIRserver.exe" 0
CreateShortCut "$SMPROGRAMS${MUI_PRODUCT}Uninstall.lnk"
"$INSTDIRUninstall.exe" "" "$INSTDIRUninstall.exe" 0


;Desktop shortcut

CreateShortCut "$DESKTOP$9.lnk" "$INSTDIRserver.exe" ""
"$INSTDIRserver.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
"SoftwareMicrosoftWindowsCurrentVersionUninstall${MUI_PRODUCT}"
"DisplayName" "${MUI_PRODUCT} ($9)"
WriteRegStr HKLM
"SoftwareMicrosoftWindowsCurrentVersionUninstall${MUI_PRODUCT}"
"UninstallString" "$INSTDIRUninstall.exe"

WriteUninstaller "$INSTDIRUninstall.exe"


FunctionEnd

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

;Delete Uninstaller And Unistall Registry Entries
Delete "$INSTDIRuninstall.exe"


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

;MessageBox MB_OK "$9"

DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE${MUI_PRODUCT}"
DeleteRegKey HKEY_LOCAL_MACHINE
"SOFTWAREMicrosoftWindowsCurrentVersionUninstall${MUI_PRODUCT}"
#this was not so easy as one would think about removing

;Delete Files

ClearErrors
FindFirst $0 $1 "$INSTDIRcollect*.*"
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 "$INSTDIRcollect$1indexassoc*.*"
Delete "$INSTDIRcollect$1*.*"
Sleep "100"
RMDir /r "$INSTDIRcollect$1"
Sleep "100"
GoTo RemoveNext

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

;Remove the installation directory

Delete "$INSTDIRetc*.*"
Delete "$INSTDIRimages*.*"
Delete "$INSTDIRmacros*.*"
Delete "$INSTDIRmappings*.*"
Delete "$INSTDIR et16*.*"
Delete "$INSTDIR et32*.*"

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