EDU win installer: refactoring custom actions.

This commit is contained in:
Vladimir.Orlov
2018-10-18 12:09:06 +03:00
parent b55bfe1613
commit beee1cd822
3 changed files with 74 additions and 47 deletions
+36 -19
View File
@@ -108,6 +108,7 @@ ReserveFile "DeleteSettings.ini"
${EndIf}
FunctionEnd
Function ${un}compareFileInstallationTime
StrCpy $9 ""
get_first_file:
@@ -187,19 +188,37 @@ loop:
Goto loop
FunctionEnd
Function ${un}DeleteDirIfEmpty
Function ${un}deleteFiles
ClearErrors
FindFirst $2 $1 $0\*.*
loop:
StrCmp $1 "." next 0
StrCmp $1 ".." next 0
StrCmp $1 "" done
DetailPrint "delete file: $1"
Delete $1
next:
FindNext $2 $1
Goto loop
done:
FindClose $2
FunctionEnd
Function ${un}deleteDirIfEmpty
ClearErrors
FindFirst $R0 $R1 "$0\*.*"
strcmp $R1 "." 0 NoDelete
FindNext $R0 $R1
strcmp $R1 ".." 0 NoDelete
ClearErrors
FindNext $R0 $R1
IfErrors 0 NoDelete
FindClose $R0
Sleep 1000
RMDir "$0"
NoDelete:
FindClose $R0
StrCmp $R1 "." 0 done
FindNext $R0 $R1
StrCmp $R1 ".." 0 done
ClearErrors
FindNext $R0 $R1
IfErrors 0 done
Sleep 1000
RMDir "$0"
done:
FindClose $R0
FunctionEnd
!macroend
@@ -344,6 +363,7 @@ get_next_element:
FindNext $1 $2
IfErrors 0 next_elemement
done:
ClearErrors
FindClose $1
Pop $2
Pop $1
@@ -714,7 +734,7 @@ saveProperties:
Goto complete
fullRemove:
StrCpy $0 $3
Call DeleteDirIfEmpty
Call deleteDirIfEmpty
complete:
FunctionEnd
@@ -1255,7 +1275,7 @@ SectionEnd
Function .onInit
SetRegView 32
Call CreateLog
Call createLog
!insertmacro INSTALLOPTIONS_EXTRACT "Desktop.ini"
Call getInstallationOptionsPositions
IfSilent silent_mode uac_elevate
@@ -1451,9 +1471,6 @@ UAC_Admin:
UAC_Done:
!insertmacro MUI_UNGETLANGUAGE
!insertmacro INSTALLOPTIONS_EXTRACT "DeleteSettings.ini"
Call un.CreateLog
${LogText} "un.onInit"
FunctionEnd
@@ -1738,11 +1755,11 @@ skip_delete_settings:
IfFileExists "$INSTDIR\jre32\*.*" 0 no_jre32
Delete "$INSTDIR\jre32\bin\server\classes.jsa"
StrCpy $0 "$INSTDIR\jre32\lib\applet"
Call un.DeleteDirIfEmpty
Call un.deleteDirIfEmpty
no_jre32:
!include "unidea_win.nsh"
StrCpy $0 "$INSTDIR"
Call un.DeleteDirIfEmpty
Call un.deleteDirIfEmpty
; remove desktop shortcuts
desktop_shortcut_launcher32:
+1 -1
View File
@@ -3,7 +3,7 @@
var logFile
!macro INST_UNINST_LOGGING_SWITCH un
Function ${un}CreateLog
Function ${un}createLog
Push $R0
Push $R1
Push $R2
@@ -6,6 +6,7 @@
Var internetConnection
${StrTok}
Function customPreInstallActions
IfFileExists "$TEMP\python.txt" deletePythonFileInfo getPythonFileInfo
deletePythonFileInfo:
@@ -129,11 +130,12 @@ loop:
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field $R0" "State" $R3
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Field $R0" "Text" "$0"
${LogText} " association: $0, state: $R3"
goto loop
Goto loop
update_settings:
ClearErrors
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" "Settings" "NumFields" "$R0"
goto done
Goto done
no_silent_config:
Call IncorrectSilentInstallParameters
done:
@@ -147,8 +149,9 @@ Function customInstallActions
; info about 2 and 3 version of python
StrCmp $R0 ${PYTHON_VERSIONS} getPythonInfo
cantOpenFile:
ClearErrors
StrCpy $internetConnection "No"
goto check_python
Goto check_python
getPythonInfo:
Call getPythonInfo
StrCmp $0 "Error" skip_python_download
@@ -159,7 +162,7 @@ getPythonInfo:
StrCmp $R2 1 "" python3
StrCpy $R2 $0
StrCpy $R3 $1
goto check_python
Goto check_python
python3:
!insertmacro INSTALLOPTIONS_READ $R2 "Desktop.ini" "Field 9" "State"
StrCpy $R7 ""
@@ -175,15 +178,10 @@ install:
StrCmp $R2 1 "" skip_python_download
StrCpy $R2 $R0
StrCpy $R3 $R1
check_python:
ReadRegStr $1 "HKCU" "Software\Python\PythonCore\$R2\InstallPath" ""
StrCmp $1 "" installation_for_all_users
goto verefy_python_launcher
installation_for_all_users:
ReadRegStr $1 "HKLM" "Software\Python\PythonCore\$R2\InstallPath" ""
StrCmp $1 "" get_python
verefy_python_launcher:
IfFileExists $1python.exe python_exists get_python
check_python:
Call searchPython
StrCmp $4 "Absent" get_python python_exists
get_python:
StrCmp $internetConnection "No" skip_python_download
CreateDirectory "$INSTDIR\python"
@@ -204,14 +202,24 @@ skip_python_download:
done:
FunctionEnd
Function customPostInstallActions
DetailPrint "There are no custom post-install actions."
FunctionEnd
Function un.customUninstallActions
DetailPrint "There are no custom uninstall actions."
DetailPrint "customUninstallActions"
StrCpy $0 "$INSTDIR\..\python"
DetailPrint "install dir: $0"
IfFileExists "$0\*.*" 0 no_python
DetailPrint "delete python installer"
Call un.deleteFiles
Call un.deleteDirIfEmpty
no_python:
FunctionEnd
Function updatePythonControls
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "Text" "Python $R2 (installed)"
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R4 "Flags" "DISABLED"
@@ -221,13 +229,15 @@ Function updatePythonControls
!insertmacro INSTALLOPTIONS_WRITE "Desktop.ini" $R5 "State" "0"
FunctionEnd
Function getPythonInfo
${LogText} "get Python info"
ClearErrors
FileOpen $3 $Temp\python.txt r
; file can not be open.
IfErrors cantOpenFile
${If} ${RunningX64}
goto getPythonInfo
Goto getPythonInfo
${Else}
FileRead $3 $4
FileRead $3 $4
@@ -241,12 +251,13 @@ getPythonInfo:
FileRead $3 $4
${StrTok} $R0 $4 " " "1" "1"
${StrTok} $R1 $4 " " "2" "1"
goto done
Goto done
cantOpenFile:
StrCpy $0 "Error"
done:
FunctionEnd
Function searchPython
; $R2 - version of python
${LogText} "search a Python version"
@@ -254,31 +265,30 @@ Function searchPython
StrCpy $1 "Software\Python\PythonCore\$R2\InstallPath"
StrCpy $2 ""
SetRegView 64
call OMReadRegStr
Call OMReadRegStr
SetRegView 32
StrCmp $3 "" CU_32bit verifyPythonLauncher
CU_32bit:
call OMReadRegStr
Call OMReadRegStr
StrCmp $3 "" installationForAllUsers verifyPythonLauncher
installationForAllUsers:
StrCpy $0 "HKLM"
call OMReadRegStr
Call OMReadRegStr
SetRegView 64
call OMReadRegStr
Call OMReadRegStr
SetRegView 32
StrCmp $3 "" LM_32bit verifyPythonLauncher
LM_32bit:
call OMReadRegStr
Call OMReadRegStr
StrCmp $3 "" pythonAbsent
verifyPythonLauncher:
IfFileExists $3python.exe pythonExists pythonAbsent
pythonAbsent:
StrCpy $4 "Absent"
goto done
pythonExists:
IfFileExists $3python.exe 0 pythonAbsent
StrCpy $4 "Exists"
done:
Goto done
pythonAbsent:
StrCpy $4 "Absent"
done:
FunctionEnd