Commit 8a8e82c9 by Csók Tamás

client: created a choosable agressive Python search NSIS solution

parent 1eae6d5e
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
;Include Modules ;Include Modules
!include "MUI2.nsh" !include "MUI2.nsh"
!include "LogicLib.nsh" !include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "x64.nsh" !include "x64.nsh"
;-------------------------------- ;--------------------------------
...@@ -18,10 +19,44 @@ ...@@ -18,10 +19,44 @@
!define IconName "cloud" !define IconName "cloud"
!define Show_output "True" !define Show_output "True"
!define DefaulLocation "$LOCALAPPDATA\CIRCLE" !define DefaulLocation "$LOCALAPPDATA\CIRCLE"
!define LowestSupportedPythonVersion "6"
!define HighestSupportedPythonVersion "7"
!define LogInformationTime 2000
;File/Directory/Drives manipulations
!define Drives "!insertmacro GetDrivesCaller"
;String manipulations
!define Explode "!insertmacro Explode"
!define StrCase "!insertmacro StrCase"
!define StrTrimNewLines "!insertmacro StrTrimNewLines"
;-------------------------------- ;--------------------------------
;General ;General
!macro Explode Length Separator String
Push `${Separator}`
Push `${String}`
Call Explode
Pop `${Length}`
!macroend
!macro StrCase ResultVar String Case
Push "${String}"
Push "${Case}"
Call StrCase
Pop "${ResultVar}"
!macroend
!macro GetDrivesCaller _DRV _FUNC
Push $0
Push `${_DRV}`
GetFunctionAddress $0 `${_FUNC}`
Push `$0`
Call Drives
Pop $0
!macroend
!macro StrTrimNewLines ResultVar String
Push "${String}"
Call StrTrimNewLines
Pop "${ResultVar}"
!macroend
;Properly display all languages (Installer will not work on Windows 95, 98 or ME!) ;Properly display all languages (Installer will not work on Windows 95, 98 or ME!)
Unicode true Unicode true
...@@ -146,56 +181,136 @@ ...@@ -146,56 +181,136 @@
!insertmacro MUI_RESERVEFILE_LANGDLL !insertmacro MUI_RESERVEFILE_LANGDLL
;-------------------------------- ;--------------------------------
;Languanges ;Language strings
;Language strings ;SectionGroup names
LangString NAME_Install ${LANG_ENGLISH} "Components"
LangString NAME_Install ${LANG_HUNGARIAN} "Komponensek"
LangString NAME_Functions ${LANG_ENGLISH} "Functions"
LangString NAME_Functions ${LANG_HUNGARIAN} "Funkcik"
;CIRCLE Client (SecInstall)
;NAME
LangString NAME_SecInstall ${LANG_ENGLISH} "CIRCLE Client" LangString NAME_SecInstall ${LANG_ENGLISH} "CIRCLE Client"
LangString NAME_SecInstall ${LANG_HUNGARIAN} "CIRCLE Kliens" LangString NAME_SecInstall ${LANG_HUNGARIAN} "CIRCLE Kliens"
LangString NAME_NXClient ${LANG_ENGLISH} "NoMachine NX Client" ;DESC
LangString NAME_NXClient ${LANG_HUNGARIAN} "NoMachine NX Kliens"
LangString DESC_NXClient ${LANG_ENGLISH} "Check whether you want to install a CIRCLE compatible NX Client by NoMachine.$\r$\n\
Used for [NX] type of connections."
LangString DESC_NXClient ${LANG_HUNGARIAN} "Vlassza ki, ha fel szeretn telepteni a NoMachine ltal gyrtott NX Klienst.$\r$\n\
[NX] fle kapcsolatokhoz hasznlt."
LangString DESC_SecInstall ${LANG_ENGLISH} "Install the core of the CIRCLE Client.$\r$\n\ LangString DESC_SecInstall ${LANG_ENGLISH} "Install the core of the CIRCLE Client.$\r$\n\
Used for [RDP / SSH] type of connections.$\r$\n\ Used for [RDP / SSH] type of connections.$\r$\n\
Automates all installed, third party connection tools." Automates all installed, third party connection tools."
LangString DESC_SecInstall ${LANG_HUNGARIAN} "A CIRCLE Kliens alapjnak teleptse.$\r$\n\ LangString DESC_SecInstall ${LANG_HUNGARIAN} "A CIRCLE Kliens alapjnak teleptse.$\r$\n\
[RDP / SSH] fle kapcsolatokhoz hasznlt.$\r$\n\ [RDP / SSH] fle kapcsolatokhoz hasznlt.$\r$\n\
Automatizlja az installlt, harmadik fltl szrmaz szoftverek hasznlatt." Automatizlja az installlt, harmadik fltl szrmaz szoftverek hasznlatt."
;Python search (PythonLookup)
;NAME
LangString NAME_PythonLookup ${LANG_ENGLISH} "Search Python"
LangString NAME_PythonLookup ${LANG_HUNGARIAN} "Python keress"
;DESC
LangString DESC_PythonLookup ${LANG_ENGLISH} "Use ONLY if necessary!$\r$\n\
Search the filesystem for Python installation. Usefull when Python was installed without accessing registry before.$\r$\n\
Installation will take more time."
LangString DESC_PythonLookup ${LANG_HUNGARIAN} "Csak szksg esetn!$\r$\n\
A fjlrendszer keresse Python utn. Hasznos, ha a Python-t Registry nlkli opcival lett teleptve korbban.$\r$\n\
A teleptst jelentsen lelasstja."
;-------------------------------- ;STATUS
;Installer Sections LangString STATUS_PythonSearch ${LANG_ENGLISH} "Searching for Python. This could take some time. Looking at drive:"
Section $(NAME_SecInstall) SecInstall LangString STATUS_PythonSearch ${LANG_HUNGARIAN} "Python keresse a fjlrendszerben. Ez eltarthat egy darabig. Keress alapja:"
SectionIn RO
SetOutPath "$INSTDIR" LangString STATUS_PythonFound ${LANG_ENGLISH} "Python found at "
LangString STATUS_PythonFound ${LANG_HUNGARIAN} "Python megtallva az albbi knyvtrban: "
;ADD OWN FILES HERE---------------------------------------- LangString STATUS_PythonVersionSearch ${LANG_ENGLISH} "Determining Python version."
File /r /x *nxclient-3.5.0-9.exe /x *nx_client_installer.py installer LangString STATUS_PythonVersionSearch ${LANG_HUNGARIAN} "Teleptett Python verzi kidertse."
File /r uninstaller
;Store installation folder LangString STATUS_PythonVersionFound ${LANG_ENGLISH} "Installed Python version is:"
WriteRegStr HKCU "Software\${Company} ${AppName}" "install_directory" $INSTDIR LangString STATUS_PythonVersionFound ${LANG_HUNGARIAN} "A teleptett Python verzija:"
;Create uninstaller LangString STATUS_PythonArchitectSearch ${LANG_ENGLISH} "Deteremining installed Python mode (32bit or 64bit)."
WriteUninstaller "$INSTDIR\${AppUninstaller}" LangString STATUS_PythonArchitectSearch ${LANG_HUNGARIAN} "Installlt Python futtatsi mdjnak kidertse (32bit vagy 64bit)."
;Creating ShortCuts LangString STATUS_PythonArchitectFound ${LANG_ENGLISH} "Installed Python mode is:"
CreateDirectory '$SMPROGRAMS\${Company}\${AppName}' LangString STATUS_PythonArchitectFound ${LANG_HUNGARIAN} "A teleptett Python mdja:"
StrCmp $LANGUAGE ${LANG_HUNGARIAN} 0 +3
WriteINIStr "$SMPROGRAMS\${Company}\Ltogasd meg a ${AppUrlName}-t.url" "InternetShortcut" "URL" "${AppUrl}" LangString STATUS_PythonNotSupported ${LANG_ENGLISH} "The installed Python version is not supported!$\r$\n\
Goto +2 To procede please uninstall Python first."
WriteINIStr "$SMPROGRAMS\${Company}\Visit the ${AppUrlName}.url" "InternetShortcut" "URL" "${AppUrl}" LangString STATUS_PythonNotSupported ${LANG_HUNGARIAN} "A felteleptett Python verzija nem tmogatott!$\r$\n\
CreateShortCut '$SMPROGRAMS\${Company}\${AppName}\Uninstall ${AppName}.lnk' '$INSTDIR\${AppUninstaller}' "" '$INSTDIR\${AppUninstaller}' 0 A sikeres teleptshez el kell elbb tvoltania a Python-t."
LangString STATUS_PythonNotFound ${LANG_ENGLISH} "Python not found in the filesystem!"
LangString STATUS_PythonNotFound ${LANG_HUNGARIAN}} "Nem tallhat Python a fjlrendszerben!"
SectionEnd LangString STATUS_PythonArchitectNotFound ${LANG_ENGLISH} "Could NOT determine the installed Python mode!$\r$\n\
Section /o $(NAME_NXClient) NXClient To procede please uninstall Python first."
SetOutPath "$INSTDIR\installer" LangString STATUS_PythonArchitectNotFound ${LANG_HUNGARIAN} "Nem sikerlt kiderteni a felteleptett Python mdjt!$\r$\n\
File 'installer\nxclient-3.5.0-9.exe' A sikeres teleptshez el kell elbb tvoltania a Python-t."
File 'installer\nx_client_installer.py'
SectionEnd ;NX Client (NXClient)
;NAME
LangString NAME_NXClient ${LANG_ENGLISH} "NX Client"
LangString NAME_NXClient ${LANG_HUNGARIAN} "NX Kliens"
;DESC
LangString DESC_NXClient ${LANG_ENGLISH} "Check whether you want to install a CIRCLE compatible NX Client by NoMachine.$\r$\n\
Used for [NX] type of connections."
LangString DESC_NXClient ${LANG_HUNGARIAN} "Vlassza ki, ha fel szeretn telepteni a NoMachine ltal gyrtott NX Klienst.$\r$\n\
[NX] fle kapcsolatokhoz hasznlt."
;Setup
LangString STATUS_ExecutingScript ${LANG_ENGLISH} "Executing setup script. Log files can be found at:"
LangString STATUS_ExecutingScript ${LANG_HUNGARIAN} "Installcis script futtatsa. A folyamat naplja:"
;--------------------------------
;Global variables
Var /GLOBAL python_location
Var /GLOBAL python_version
Var /GLOBAL python_architect
Var /GLOBAL found_python
Var /GLOBAL nx_install
Var /GLOBAL append
;--------------------------------
;Installer Sections
SectionGroup /e '!$(NAME_Install)'
Section $(NAME_SecInstall) SecInstall
SectionIn RO
SetOutPath "$INSTDIR"
;ADD OWN FILES HERE----------------------------------------
File /r /x *nxclient-3.5.0-9.exe /x *nx_client_installer.py installer
File /r uninstaller
;Store installation folder
WriteRegStr HKCU "Software\${Company} ${AppName}" "install_directory" $INSTDIR
;Create uninstaller
WriteUninstaller "$INSTDIR\${AppUninstaller}"
;Creating ShortCuts
CreateDirectory '$SMPROGRAMS\${Company}\${AppName}'
StrCmp $LANGUAGE ${LANG_HUNGARIAN} 0 +3
WriteINIStr "$SMPROGRAMS\${Company}\Ltogasd meg a ${AppUrlName}-t.url" "InternetShortcut" "URL" "${AppUrl}"
Goto +2
WriteINIStr "$SMPROGRAMS\${Company}\Visit the ${AppUrlName}.url" "InternetShortcut" "URL" "${AppUrl}"
CreateShortCut '$SMPROGRAMS\${Company}\${AppName}\Uninstall ${AppName}.lnk' '$INSTDIR\${AppUninstaller}' "" '$INSTDIR\${AppUninstaller}' 0
SectionEnd
Section /o $(NAME_NXClient) NXClient
SetOutPath "$INSTDIR\installer"
File 'installer\nxclient-3.5.0-9.exe'
File 'installer\nx_client_installer.py'
SectionEnd
SectionGroupEnd
SectionGroup /e $(NAME_Functions)
Section /o $(NAME_PythonLookup) PythonLookup
StrCpy $found_python "false"
${GetDrives} "HDD" "PythonSearch"
StrCmp $found_python "true" appendExec
Goto LookupEnd
appendExec:
StrCpy $append ' $python_version $python_architect "$python_location\"'
LookupEnd:
SectionEnd
SectionGroupEnd
;-------------------------------- ;--------------------------------
;Installer Functions ;Installer Functions
...@@ -204,24 +319,703 @@ Function .onInit ...@@ -204,24 +319,703 @@ Function .onInit
${DisableX64FSRedirection} ${DisableX64FSRedirection}
SetRegView 64 SetRegView 64
${EndIf} ${EndIf}
!insertmacro MUI_LANGDLL_DISPLAY !insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd FunctionEnd
Function PythonSearch
StrCpy $python_location ""
DetailPrint '$(STATUS_PythonSearch) "$9"'
Push "easy_install.exe" ;File or folder to search. Wildcards are supported.
Push $9 ;Path where to search for the file or folder.
Push $0
GetFunctionAddress $0 "CallbackFunction" ;Custom callback function name
Exch $0
Push "1" ;Include subfolders in search. (0 = false, 1 = true)
Push "0" ;Enter subfolders with ".". This only works if "Include subfolders in search" is set to 1 (true). (0 = false, 1 = true)
Call SearchFile
StrCmp $python_location "" PythonNotFound
Var /GLOBAL explodeChar
StrCpy $explodeChar ' '
DetailPrint $(STATUS_PythonVersionSearch)
nsExec::ExecToStack '"$python_location\python.exe" -V'
Pop $0
${If} $0 = 0
Pop $0
${StrTrimNewLines} $python_version $0
loop:
${Explode} $0 $explodeChar $python_version
${For} $1 1 $0
Pop $2
StrCmp $explodeChar ' ' CutPython
StrCmp $1 "2" secondNumber
StrCmp $2 "2" versionCount
wrongVersion:
MessageBox MB_OK $(STATUS_PythonNotSupported)
Abort $(STATUS_PythonNotSupported)
Goto PythonFin
versionCount:
StrCpy $4 $2
Goto loopNext
secondNumber:
${If} $2 S>= ${LowestSupportedPythonVersion}
${If} $2 S<= ${HighestSupportedPythonVersion}
StrCpy $python_version "$4$explodeChar$2"
DetailPrint '$(STATUS_PythonVersionFound) $python_version'
StrCpy $found_python "true"
Goto PythonMode
${Else}
Goto wrongVersion
${EndIf}
${Else}
Goto wrongVersion
${EndIf}
Goto loopNext
CutPython:
${StrCase} $3 $2 "U"
StrCmp $3 "PYTHON" loopNext
StrCpy $python_version $2
StrCpy $explodeChar '.'
Goto loop
loopNext:
${Next}
${Else}
PythonNotFound:
MessageBox MB_OK $(STATUS_PythonNotFound)
Abort $(STATUS_PythonNotFound)
Goto PythonFin
${EndIf}
PythonMode:
DetailPrint $(STATUS_PythonArchitectSearch)
nsExec::ExecToStack '"$python_location\python.exe" -c $\"import struct;print( 8 * struct.calcsize($\'P$\'))$\"'
Pop $0
${If} $0 = 0
Pop $0
${StrTrimNewLines} $python_architect $0
DetailPrint '$(STATUS_PythonArchitectFound) $python_architectbit'
${Else}
MessageBox MB_OK $(STATUS_PythonArchitectNotFound)
Abort $(STATUS_PythonArchitectNotFound)
${EndIf}
StrCpy $6 StopGetDrives
PythonFin:
Push $6
FunctionEnd
Function Done Function Done
SectionGetFlags ${NXClient} $0 SectionGetFlags ${NXClient} $9
Var /GLOBAL nx_install IntOp $9 $9 & ${SF_SELECTED}
IntOp $0 $0 & ${SF_SELECTED} IntCmp $9 ${SF_SELECTED} equal
IntCmp $0 ${SF_SELECTED} equal
StrCpy $nx_install "False" StrCpy $nx_install "False"
Goto done Goto done
equal: equal:
StrCpy $nx_install "True" StrCpy $nx_install "True"
done: done:
ExecWait '"$INSTDIR\installer\install.cmd" "$INSTDIR" ${Show_output} $nx_install "${AppUrl}" >"$INSTDIR\install.log" 2>"$INSTDIR\install_error.log"' DetailPrint '$(STATUS_ExecutingScript) $INSTDIR\install(_error).log'
Sleep ${LogInformationTime}
ExecWait '"$INSTDIR\installer\install.cmd" "$INSTDIR" ${Show_output} $nx_install "${AppUrl}" $append >"$INSTDIR\install.log" 2>"$INSTDIR\install_error.log"'
RMDir /r "$INSTDIR\installer" RMDir /r "$INSTDIR\installer"
FunctionEnd FunctionEnd
Function CallbackFunction
${GetParent} $R0 $python_location
DetailPrint '$(STATUS_PythonFound) "$python_location\"'
Push "Stop"
FunctionEnd
Function SearchFile
Exch 4
Exch
Exch 3
Exch $R0 ; directory in which to search
Exch 4
Exch
Exch $R1 ; file or folder name to search in
Exch 3
Exch 2
Exch $R2
Exch 2
Exch $R3
Exch
Push $R4
Exch
Push $R5
Exch
Push $R6
Exch
Exch $R7 ;search folders with "."
StrCpy $R5 $R2 ;$R5 = custom function name
StrCpy $R6 $R3 ;$R6 = include subfolders
StrCpy $R2 ""
StrCpy $R3 ""
# Remove \ from end (if any) from the file name or folder name to search
StrCpy $R2 $R1 1 -1
StrCmp $R2 \ 0 +2
StrCpy $R1 $R1 -1
# Detect if the search path have backslash to add the backslash
StrCpy $R2 $R0 1 -1
StrCmp $R2 \ +2
StrCpy $R0 "$R0\"
# File (or Folder) Search
##############
# Get first file or folder name
FindFirst $R2 $R3 "$R0$R1"
FindNextFile:
# This loop, search for files or folders with the same conditions.
StrCmp $R3 "" NoFiles
StrCpy $R4 "$R0$R3"
# Preparing variables for the Callback function
Push $R7
Push $R6
Push $R5
Push $R4
Push $R3
Push $R2
Push $R1
Push $R0
# Call the Callback function
Call $R5
# Returning variables
Push $R8
Exch
Pop $R8
Exch
Pop $R0
Exch
Pop $R1
Exch
Pop $R2
Exch
Pop $R3
Exch
Pop $R4
Exch
Pop $R5
Exch
Pop $R6
Exch
Pop $R7
StrCmp $R8 "Stop" 0 +3
Pop $R8
Goto Done
Pop $R8
# Detect if have another file
FindNext $R2 $R3
Goto FindNextFile ;and loop!
# If don't have any more files or folders with the condictions
NoFiles:
FindClose $R2
# Search in Subfolders
#############
# If you don't want to search in subfolders...
StrCmp $R6 0 NoSubfolders 0
# SEARCH FOLDERS WITH DOT
# Find the first folder with dot
StrCmp $R7 1 0 EndWithDot
FindFirst $R2 $R3 "$R0*.*"
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolderWithDot 0
StrCmp $R3 ".." FindNextSubfolderWithDot 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction 0
# Now, detect the next folder with dot
FindNextSubfolderWithDot:
FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
StrCmp $R3 "." FindNextSubfolder 0
StrCmp $R3 ".." FindNextSubfolder 0
IfFileExists "$R0$R3\*.*" RecallingOfFunction FindNextSubfolderWithDot
EndWithDot:
# SEARCH FOLDERS WITHOUT DOT
# Skip ., and .. (C:\ don't have .., so have to detect if is :\)
FindFirst $R2 $R3 "$R0*."
Push $R6
StrCpy $R6 $R0 "" 1
StrCmp $R6 ":\" +2
FindNext $R2 $R3
Pop $R6
# Now detect the "really" subfolders, and loop
FindNextSubfolder:
FindNext $R2 $R3
StrCmp $R3 "" NoSubfolders
IfFileExists "$R0$R3\" FindNextSubfolder
# Now Recall the function (making a LOOP)!
RecallingOfFunction:
Push $R1
Push "$R0$R3\"
Push "$R5"
Push "$R6"
Push "$R7"
Call SearchFile
# Now, find the next Subfolder
Goto FindNextSubfolder
# If don't exist more subfolders...
NoSubfolders:
FindClose $R2
# Returning Values to User
Done:
Pop $R7
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
Function Explode
; Initialize variables
Var /GLOBAL explString
Var /GLOBAL explSeparator
Var /GLOBAL explStrLen
Var /GLOBAL explSepLen
Var /GLOBAL explOffset
Var /GLOBAL explTmp
Var /GLOBAL explTmp2
Var /GLOBAL explTmp3
Var /GLOBAL explArrCount
; Get input from user
Pop $explString
Pop $explSeparator
; Calculates initial values
StrLen $explStrLen $explString
StrLen $explSepLen $explSeparator
StrCpy $explArrCount 1
${If} $explStrLen <= 1 ; If we got a single character
${OrIf} $explSepLen > $explStrLen ; or separator is larger than the string,
Push $explString ; then we return initial string with no change
Push 1 ; and set array's length to 1
Return
${EndIf}
; Set offset to the last symbol of the string
StrCpy $explOffset $explStrLen
IntOp $explOffset $explOffset - 1
; Clear temp string to exclude the possibility of appearance of occasional data
StrCpy $explTmp ""
StrCpy $explTmp2 ""
StrCpy $explTmp3 ""
; Loop until the offset becomes negative
${Do}
; If offset becomes negative, it is time to leave the function
${IfThen} $explOffset == -1 ${|} ${ExitDo} ${|}
; Remove everything before and after the searched part ("TempStr")
StrCpy $explTmp $explString $explSepLen $explOffset
${If} $explTmp == $explSeparator
; Calculating offset to start copy from
IntOp $explTmp2 $explOffset + $explSepLen ; Offset equals to the current offset plus length of separator
StrCpy $explTmp3 $explString "" $explTmp2
Push $explTmp3 ; Throwing array item to the stack
IntOp $explArrCount $explArrCount + 1 ; Increasing array's counter
StrCpy $explString $explString $explOffset 0 ; Cutting all characters beginning with the separator entry
StrLen $explStrLen $explString
${EndIf}
${If} $explOffset = 0 ; If the beginning of the line met and there is no separator,
; copying the rest of the string
${If} $explSeparator == "" ; Fix for the empty separator
IntOp $explArrCount $explArrCount - 1
${Else}
Push $explString
${EndIf}
${EndIf}
IntOp $explOffset $explOffset - 1
${Loop}
Push $explArrCount
FunctionEnd
Function StrCase
/*After this point:
------------------------------------------
$0 = String (input)
$1 = Case (input)
$2 = StrLength (temp)
$3 = StartChar (temp)
$4 = EndChar (temp)
$5 = ResultStr (temp)
$6 = CurrentChar (temp)
$7 = LastChar (temp)
$8 = Temp (temp)*/
;Get input from user
Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
Push $5
Push $6
Push $7
Push $8
;Initialize variables
StrCpy $2 ""
StrCpy $3 ""
StrCpy $4 ""
StrCpy $5 ""
StrCpy $6 ""
StrCpy $7 ""
StrCpy $8 ""
;Upper and lower cases are simple to use
${If} $1 == "U"
;Upper Case:
;-----------
;Convert all characters to upper case.
System::Call "User32::CharUpper(t r0 r5)i"
Goto StrCase_End
${ElseIf} $1 == "L"
;Lower Case:
;-----------
;Convert all characters to lower case.
System::Call "User32::CharLower(t r0 r5)i"
Goto StrCase_End
${EndIf}
;For the rest of cases:
;Get "String" length
StrLen $2 $0
;Make a loop until the end of "String"
${For} $3 0 $2
;Add 1 to "EndChar" counter also
IntOp $4 $3 + 1
# Step 1: Detect one character at a time
;Remove characters before "StartChar" except when
;"StartChar" is the first character of "String"
${If} $3 <> 0
StrCpy $6 $0 `` $3
${EndIf}
;Remove characters after "EndChar" except when
;"EndChar" is the last character of "String"
${If} $4 <> $2
${If} $3 = 0
StrCpy $6 $0 1
${Else}
StrCpy $6 $6 1
${EndIf}
${EndIf}
# Step 2: Convert to the advanced case user chose:
${If} $1 == "T"
;Title Case:
;------------------
; Convert all characters after a non-alphabetic character to upper case.
; Else convert to lower case.
;Use "IsCharAlpha" for the job
System::Call "*(&t1 r7) i .r8"
System::Call "*$8(&i1 .r7)"
System::Free $8
System::Call "user32::IsCharAlpha(i r7) i .r8"
;Verify "IsCharAlpha" result and convert the character
${If} $8 = 0
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${ElseIf} $1 == "S"
;Sentence Case:
;------------------
; Convert all characters after a ".", "!" or "?" character to upper case.
; Else convert to lower case. Spaces or tabs after these marks are ignored.
;Detect current characters and ignore if necessary
${If} $6 == " "
${OrIf} $6 == "$\t"
Goto IgnoreLetter
${EndIf}
;Detect last characters and convert
${If} $7 == "."
${OrIf} $7 == "!"
${OrIf} $7 == "?"
${OrIf} $7 == ""
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${ElseIf} $1 == "<>"
;Switch Case:
;------------------
; Switch all characters cases to their inverse case.
;Use "IsCharUpper" for the job
System::Call "*(&t1 r6) i .r8"
System::Call "*$8(&i1 .r7)"
System::Free $8
System::Call "user32::IsCharUpper(i r7) i .r8"
;Verify "IsCharUpper" result and convert the character
${If} $8 = 0
System::Call "User32::CharUpper(t r6 r6)i"
${Else}
System::Call "User32::CharLower(t r6 r6)i"
${EndIf}
${EndIf}
;Write the character to "LastChar"
StrCpy $7 $6
IgnoreLetter:
;Add this character to "ResultStr"
StrCpy $5 `$5$6`
${Next}
StrCase_End:
/*After this point:
------------------------------------------
$0 = ResultVar (output)*/
; Copy "ResultStr" to "ResultVar"
StrCpy $0 $5
;Return output to user
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd
Function Drives
Exch $1
Exch
Exch $0
Exch
Push $2
Push $3
Push $4
Push $5
Push $6
Push $8
Push $9
System::Alloc /NOUNLOAD 1024
Pop $2
System::Call /NOUNLOAD 'kernel32::GetLogicalDriveStringsA(i,i) i(1024, r2)'
StrCmp $0 ALL drivestring
StrCmp $0 '' 0 typeset
StrCpy $0 ALL
goto drivestring
typeset:
StrCpy $6 -1
IntOp $6 $6 + 1
StrCpy $8 $0 1 $6
StrCmp $8$0 '' enumex
StrCmp $8 '' +2
StrCmp $8 '+' 0 -4
StrCpy $8 $0 $6
IntOp $6 $6 + 1
StrCpy $0 $0 '' $6
StrCmp $8 'FDD' 0 +3
StrCpy $6 2
goto drivestring
StrCmp $8 'HDD' 0 +3
StrCpy $6 3
goto drivestring
StrCmp $8 'NET' 0 +3
StrCpy $6 4
goto drivestring
StrCmp $8 'CDROM' 0 +3
StrCpy $6 5
goto drivestring
StrCmp $8 'RAM' 0 typeset
StrCpy $6 6
drivestring:
StrCpy $3 $2
enumok:
System::Call /NOUNLOAD 'kernel32::lstrlenA(t) i(i r3) .r4'
StrCmp $4$0 '0ALL' enumex
StrCmp $4 0 typeset
System::Call /NOUNLOAD 'kernel32::GetDriveTypeA(t) i(i r3) .r5'
StrCmp $0 ALL +2
StrCmp $5 $6 letter enumnext
StrCmp $5 2 0 +3
StrCpy $8 FDD
goto letter
StrCmp $5 3 0 +3
StrCpy $8 HDD
goto letter
StrCmp $5 4 0 +3
StrCpy $8 NET
goto letter
StrCmp $5 5 0 +3
StrCpy $8 CDROM
goto letter
StrCmp $5 6 0 enumex
StrCpy $8 RAM
letter:
System::Call /NOUNLOAD '*$3(&t1024 .r9)'
Push $0
Push $1
Push $2
Push $3
Push $4
Push $5
Push $6
Push $8
Call $1
Pop $9
Pop $8
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
StrCmp $9 'StopGetDrives' enumex
enumnext:
IntOp $3 $3 + $4
IntOp $3 $3 + 1
goto enumok
enumex:
System::Free $2
Pop $9
Pop $8
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
Function StrTrimNewLines
/*After this point:
------------------------------------------
$R0 = String (input)
$R1 = TrimCounter (temp)
$R2 = Temp (temp)*/
;Get input from user
Exch $R0
Push $R1
Push $R2
;Initialize trim counter
StrCpy $R1 0
loop:
;Subtract to get "String"'s last characters
IntOp $R1 $R1 - 1
;Verify if they are either $\r or $\n
StrCpy $R2 $R0 1 $R1
${If} $R2 == '$\r'
${OrIf} $R2 == '$\n'
Goto loop
${EndIf}
;Trim characters (if needed)
IntOp $R1 $R1 + 1
${If} $R1 < 0
StrCpy $R0 $R0 $R1
${EndIf}
/*After this point:
------------------------------------------
$R0 = ResultVar (output)*/
;Return output to user
Pop $R2
Pop $R1
Exch $R0
FunctionEnd
;-------------------------------- ;--------------------------------
;Descriptions ;Descriptions
...@@ -229,6 +1023,7 @@ FunctionEnd ...@@ -229,6 +1023,7 @@ FunctionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall) !insertmacro MUI_DESCRIPTION_TEXT ${SecInstall} $(DESC_SecInstall)
!insertmacro MUI_DESCRIPTION_TEXT ${NXClient} $(DESC_NXClient) !insertmacro MUI_DESCRIPTION_TEXT ${NXClient} $(DESC_NXClient)
!insertmacro MUI_DESCRIPTION_TEXT ${PythonLookup} $(DESC_PythonLookup)
!insertmacro MUI_FUNCTION_DESCRIPTION_END !insertmacro MUI_FUNCTION_DESCRIPTION_END
...@@ -279,7 +1074,6 @@ Section "Uninstall" ...@@ -279,7 +1074,6 @@ Section "Uninstall"
StrCmp $INSTDIR "${DefaulLocation}" 0 +2 StrCmp $INSTDIR "${DefaulLocation}" 0 +2
RMDir /r "$INSTDIR" RMDir /r "$INSTDIR"
SectionEnd SectionEnd
;-------------------------------- ;--------------------------------
;Uninstaller Functions ;Uninstaller Functions
Function un.onInit Function un.onInit
......
...@@ -34,7 +34,27 @@ IF NOT "%4"=="" ( ...@@ -34,7 +34,27 @@ IF NOT "%4"=="" (
SET my_site=!site:"=! SET my_site=!site:"=!
SET "website= -t ^"!my_site!^"" SET "website= -t ^"!my_site!^""
SET "32PythonOn64=False" rem Set Python version if we know it
IF NOT "%5"=="" (
SET "version=%5"
) else (
SET "version="
)
rem Set Python bit count (32 or 64) if we know it
IF NOT "%6"=="" (
SET "architecture=%6"
) else (
SET "architecture="
)
rem Set Python location if we know it
IF NOT "%7"=="" (
SET "python_location=%7"
SET install_path=!python_location:"=!
) else (
SET "install_path="
)
:BatchCheckElevated :BatchCheckElevated
:------------------------------------- :-------------------------------------
...@@ -53,7 +73,8 @@ if '%errorlevel%' NEQ '0' ( ...@@ -53,7 +73,8 @@ if '%errorlevel%' NEQ '0' (
:UACPrompt :UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > ^"%temp%\getadmin.vbs^" echo Set UAC = CreateObject^("Shell.Application"^) > ^"%temp%\getadmin.vbs^"
set vbs_site=!site:"=""! set vbs_site=!site:"=""!
echo UAC.ShellExecute "cmd.exe", "/c %~s0 !output_on_screen! !install_nx! !vbs_site!", "", "runas", 1 >> "%temp%\getadmin.vbs" set vbs_installpath=!python_location:"=""!
echo UAC.ShellExecute "cmd.exe", "/c %~s0 !install_location! !output_on_screen! !install_nx! !vbs_site! !version! !architecture! !vbs_installpath!", "", "runas", 1 >> "%temp%\getadmin.vbs"
^"%temp%\getadmin.vbs^" ^"%temp%\getadmin.vbs^"
del "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
...@@ -75,8 +96,16 @@ IF NOT "!output_on_screen!"=="False" ( ...@@ -75,8 +96,16 @@ IF NOT "!output_on_screen!"=="False" (
) )
@echo Starting CIRCLE Client install script @echo Starting CIRCLE Client install script
@echo. @echo.
call :SUB_ARCHITECTURE architecture IF NOT "!install_path!"=="" (
IF NOT "!output_on_screen!"=="False" (
@echo Python location got from input parameter.>CON
)
@echo Python location got from input parameter.
GOTO HASPYTHON
)
if "!architecture!"=="" (
call :SUB_ARCHITECTURE architecture
)
:PYTHON_CHECK_MODULE :PYTHON_CHECK_MODULE
rem Decide whether python 2.x is installed or not rem Decide whether python 2.x is installed or not
SET "python_registry=" SET "python_registry="
...@@ -88,7 +117,7 @@ SET index=8 ...@@ -88,7 +117,7 @@ SET index=8
if "!architecture!"=="64" ( if "!architecture!"=="64" (
if "%python_registry%"=="" ( if "%python_registry%"=="" (
SET "python_registry=Wow6432Node\" SET "python_registry=Wow6432Node\"
SET "32PythonOn64=True" SET "architecture=32"
GOTO PYTHON_CHECK GOTO PYTHON_CHECK
) else ( ) else (
GOTO NOPYTHON GOTO NOPYTHON
...@@ -98,7 +127,7 @@ SET index=8 ...@@ -98,7 +127,7 @@ SET index=8
) )
) )
SET version=2.%index% SET version=2.%index%
SET @query="hklm\SOFTWARE\%python_registry%Python\PythonCore\%version%" SET @query="hklm\SOFTWARE\%python_registry%Python\PythonCore\!version!"
reg>nul query %@query% 2>nul reg>nul query %@query% 2>nul
IF ERRORLEVEL 1 GOTO loop IF ERRORLEVEL 1 GOTO loop
IF ERRORLEVEL 0 GOTO HASPYTHON IF ERRORLEVEL 0 GOTO HASPYTHON
...@@ -116,7 +145,7 @@ IF NOT "!output_on_screen!"=="False" ( ...@@ -116,7 +145,7 @@ IF NOT "!output_on_screen!"=="False" (
@echo 64 bit system detected, commencing the install>CON @echo 64 bit system detected, commencing the install>CON
) )
@echo 64 bit system detected, commencing the install @echo 64 bit system detected, commencing the install
start "Phyton Installer" /WAIT ^"%running_directory%x64^\python-2.7.7.amd64.msi^" start "Phyton Installer" /WAIT ^"%running_directory%x64^\python-2.7.10.amd64.msi^"
GOTO NOWHASPYTHON GOTO NOWHASPYTHON
) )
if "!architecture!"=="32" ( if "!architecture!"=="32" (
...@@ -124,7 +153,7 @@ IF NOT "!output_on_screen!"=="False" ( ...@@ -124,7 +153,7 @@ IF NOT "!output_on_screen!"=="False" (
@echo 32 bit system detected, commencing the install>CON @echo 32 bit system detected, commencing the install>CON
) )
@echo 32 bit system detected, commencing the install @echo 32 bit system detected, commencing the install
start "Phyton Installer" /WAIT ^"%running_directory%x86^\python-2.7.7.msi^" start "Phyton Installer" /WAIT ^"%running_directory%x86^\python-2.7.10.msi^"
GOTO NOWHASPYTHON GOTO NOWHASPYTHON
) )
GOTO ERR GOTO ERR
...@@ -171,20 +200,21 @@ IF NOT "!output_on_screen!"=="False" ( ...@@ -171,20 +200,21 @@ IF NOT "!output_on_screen!"=="False" (
rem We have Python but let's check if it's in the PATH rem We have Python but let's check if it's in the PATH
:HASPYTHON :HASPYTHON
IF NOT "!output_on_screen!"=="False" ( IF NOT "!output_on_screen!"=="False" (
@echo %version% Python is found, checking PATH variable>CON @echo !version! Python is found, checking PATH variable>CON
) )
@echo %version% Python is found, checking PATH variable @echo !version! Python is found, checking PATH variable
rem Check Python install path rem Check Python install path
set install_path= IF "!install_path!"=="" (
for /f "tokens=2,*" %%a in ('reg query "hklm\SOFTWARE\%python_registry%Python\PythonCore\%version%\InstallPath"') do ( for /f "tokens=2,*" %%a in ('reg query "hklm\SOFTWARE\%python_registry%Python\PythonCore\!version!\InstallPath"') do (
set install_path=%%b set install_path=%%b
)
) )
rem Check whether python.exe is in the install path (python uninstall doesn't delete registry entrys) rem Check whether python.exe is in the install path (python uninstall doesn't delete registry entrys)
if NOT EXIST "%install_path%python.exe" ( if NOT EXIST "!install_path!python.exe" (
IF NOT "!output_on_screen!"=="False" ( IF NOT "!output_on_screen!"=="False" (
@echo %version% Python was installed but it is NOT now. Restarting the search for python^^!>CON @echo !version! Python was installed but it is NOT now. Restarting the search for python^^!>CON
) )
@echo %version% Python was installed but it is NOT now. Restarting the search for python^^! @echo !version! Python was installed but it is NOT now. Restarting the search for python^^!
goto loop goto loop
) else ( ) else (
set test=%install_path:~0,-1% set test=%install_path:~0,-1%
...@@ -247,7 +277,7 @@ IF NOT "!output_on_screen!"=="False" ( ...@@ -247,7 +277,7 @@ IF NOT "!output_on_screen!"=="False" (
rem Try to install the PIP packages via PIP rem Try to install the PIP packages via PIP
:PIP_PACKAGE_INSTALL :PIP_PACKAGE_INSTALL
if "!pip_program!"=="pywin32" ( if "!pip_program!"=="pywin32" (
call python %running_directory%pywin_installer.py call python ^"%running_directory%pywin_installer.py^" ^-m !architecture!
) else ( ) else (
call python -m pip install -r !pip_program! call python -m pip install -r !pip_program!
) )
......
...@@ -11,6 +11,11 @@ import subprocess ...@@ -11,6 +11,11 @@ import subprocess
import windowsclasses import windowsclasses
import argparse import argparse
if windowsclasses.DecideArchitecture.Is64Windows():
default_mode = '64'
else:
default_mode = '32'
def parse_arguments(): def parse_arguments():
""" """
...@@ -21,10 +26,9 @@ def parse_arguments(): ...@@ -21,10 +26,9 @@ def parse_arguments():
""" """
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"change_architect", type=str, "-m", "--mode",
help=("Whether the 32 bit Python version" help="Python running mode (32bit or 64bit)", type=str,
"is installed on a 64bit system"), required=True, choices=['32', '64'], default=default_mode)
nargs='?', default=False)
args = parser.parse_args() args = parser.parse_args()
return args return args
...@@ -37,6 +41,10 @@ def main(): ...@@ -37,6 +41,10 @@ def main():
Install Pywin32 to the computer Install Pywin32 to the computer
""" """
args = parse_arguments() args = parse_arguments()
if args.mode != default_mode:
change_architect = True
else:
change_architect = False
if sys.hexversion < 0x02060000: if sys.hexversion < 0x02060000:
print "Not a 2.6+ version Python is running, commencing update" print "Not a 2.6+ version Python is running, commencing update"
subprocess.Popen( subprocess.Popen(
...@@ -47,7 +55,7 @@ def main(): ...@@ -47,7 +55,7 @@ def main():
pywin32_version = str(219) pywin32_version = str(219)
if sys.hexversion < 0x02070000: if sys.hexversion < 0x02070000:
if (windowsclasses.DecideArchitecture.Is64Windows() if (windowsclasses.DecideArchitecture.Is64Windows()
and not args.change_architect): and not change_architect):
subprocess.Popen( subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.6.exe" % ( "%s\\x64\\pywin32-%s.win-amd64-py2.6.exe" % (
os.path.dirname(os.path.realpath(__file__)), os.path.dirname(os.path.realpath(__file__)),
...@@ -59,7 +67,7 @@ def main(): ...@@ -59,7 +67,7 @@ def main():
pywin32_version)).wait() pywin32_version)).wait()
elif sys.hexversion < 0x02080000: elif sys.hexversion < 0x02080000:
if (windowsclasses.DecideArchitecture.Is64Windows() if (windowsclasses.DecideArchitecture.Is64Windows()
and not args.change_architect): and not change_architect):
subprocess.Popen( subprocess.Popen(
"%s\\x64\\pywin32-%s.win-amd64-py2.7.exe" % ( "%s\\x64\\pywin32-%s.win-amd64-py2.7.exe" % (
os.path.dirname(os.path.realpath(__file__)), os.path.dirname(os.path.realpath(__file__)),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment