Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-compiled mbed CLI version, remove pip dependency #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions prerequisites/download-prerequisites.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ $url = "https://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.e
$file = "$storageDir\mbedWinSerial_16466.exe"
$webclient.DownloadFile($url,$file)
#Download mbed-cli
$url = "https://github.com/ARMmbed/mbed-cli/archive/1.2.2.zip"
$file = "$storageDir\mbed-cli-1.2.2.zip"
$url = "https://raw.githubusercontent.com/ARMmbed/mbed-cli-binaries/60e771045aef34d566dd2bcaadbf021af79eb24f/mbed-cli-win-1.2.2.exe"
$file = "$storageDir\mbed-cli-win-1.2.2.exe"
$webclient.DownloadFile($url,$file)
130 changes: 120 additions & 10 deletions source/cliInstall.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ ${StrTrimNewLines}
;--------------------------------
;Config Section
!define PRODUCT_NAME "Mbed CLI for Windows"
!define PRODUCT_VERSION "0.4.2"
!define MBED_CLI_ZIP "mbed-cli-1.2.2.zip"
!define PRODUCT_VERSION "0.4.3"
!define MBED_CLI_EXE "mbed-cli-win-1.2.2.exe"
!define MBED_CLI_VERSION "mbed-cli-1.2.2"
!define PRODUCT_PUBLISHER "Arm Mbed"
!define PYTHON_INSTALLER "python-2.7.13.msi"
Expand Down Expand Up @@ -105,6 +105,118 @@ InstType /CUSTOMSTRING=Advanced
InstType /COMPONENTSONLYONCUSTOM
InstType "Default"

;--------------------------------
;Functions from https://www.smartmontools.org/browser/trunk/smartmontools/os_win32/installer.nsi?rev=4110#L636

; StrStr - find substring in a string
;
; Usage:
; Push "this is some string"
; Push "some"
; Call StrStr
; Pop $0 ; "some string"

!macro StrStr un
Function ${un}StrStr
Exch $R1 ; $R1=substring, stack=[old$R1,string,...]
Exch ; stack=[string,old$R1,...]
Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...]
Push $R3
Push $R4
Push $R5
StrLen $R3 $R1
StrCpy $R4 0
; $R1=substring, $R2=string, $R3=strlen(substring)
; $R4=count, $R5=tmp
loop:
StrCpy $R5 $R2 $R3 $R4
StrCmp $R5 $R1 done
StrCmp $R5 "" done
IntOp $R4 $R4 + 1
Goto loop
done:
StrCpy $R1 $R2 "" $R4
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Exch $R1 ; $R1=old$R1, stack=[result,...]
FunctionEnd
!macroend
!insertmacro StrStr ""

!include "WinMessages.nsh"
!define Environ 'HKCU "Environment"'

Function AddToPath
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be moved to separate file. Are you using a modified version of this script? Basic script to add to the path in NSIS is not safe. NSIS_MAX_STRLEN is not solving all issues.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the script that was recommended by NSIS to get around PATH truncation issues. It does not use internal NSIS strings.

Exch $0
Push $1
Push $2
Push $3
Push $4

; NSIS ReadRegStr returns empty string on string overflow
; Native calls are used here to check actual length of PATH

; $4 = RegOpenKey(HKEY_CURRENT_USER, "Environment", &$3)
System::Call "advapi32::RegOpenKey(i 0x80000001, t'Environment', *i.r3) i.r4"
IntCmp $4 0 0 done done
; $4 = RegQueryValueEx($3, "PATH", (DWORD*)0, (DWORD*)0, &$1, ($2=NSIS_MAX_STRLEN, &$2))
; RegCloseKey($3)
System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
System::Call "advapi32::RegCloseKey(i $3)"

IntCmp $4 234 0 +4 +4 ; $4 == ERROR_MORE_DATA
DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}"
Goto done

IntCmp $4 0 +5 ; $4 != NO_ERROR
IntCmp $4 2 +3 ; $4 != ERROR_FILE_NOT_FOUND
DetailPrint "AddToPath: unexpected error code $4"
Goto done
StrCpy $1 ""

; Check if already in PATH
Push "$1;"
Push "$0;"
Call StrStr
Pop $2
StrCmp $2 "" 0 done
Push "$1;"
Push "$0\;"
Call StrStr
Pop $2
StrCmp $2 "" 0 done

; Prevent NSIS string overflow
StrLen $2 $0
StrLen $3 $1
IntOp $2 $2 + $3
IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";")
IntCmp $2 ${NSIS_MAX_STRLEN} +4 +4 0
DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}"
MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}."
Goto done

; Append dir to PATH
DetailPrint "Add to PATH: $0"
StrCpy $2 $1 1 -1
StrCmp $2 ";" 0 +2
StrCpy $1 $1 -1 ; remove trailing ';'
StrCmp $1 "" +2 ; no leading ';'
StrCpy $0 "$1;$0"
WriteRegExpandStr ${Environ} "PATH" $0
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

done:
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

;--------------------------------
;Installer Sections

Expand Down Expand Up @@ -145,15 +257,13 @@ SectionEnd
Section "mbed" SecMbed
SectionIn 1
; --- install Mbed CLI ---
ReadRegStr $0 HKLM "SOFTWARE\Python\PythonCore\2.7\InstallPath" ""
File "..\prerequisites\${MBED_CLI_ZIP}"
nsisunz::Unzip "$INSTDIR\${MBED_CLI_ZIP}" "$INSTDIR\mbed-cli"
DELETE "$INSTDIR\${MBED_CLI_ZIP}"
File "..\source\pip_install_mbed.bat"
nsExec::ExecToStack '$INSTDIR\pip_install_mbed.bat $0 $INSTDIR\mbed-cli\${MBED_CLI_VERSION}'
DELETE "$INSTDIR\pip_install_mbed.bat"
File "..\prerequisites\${MBED_CLI_EXE}"
Rename "$INSTDIR\${MBED_CLI_EXE}" "$INSTDIR\mbed.exe"
; --- add shortcut and batch script to windows ---
File "..\source\p.ico"
; --- add to PATH ---
Push "$INSTDIR"
Call AddToPath
SectionEnd

Section "git-scm" SecGit
Expand Down Expand Up @@ -205,11 +315,11 @@ SectionEnd
;--------------------------------

Section "Uninstall"
nsExec::ExecToStack 'pip uninstall -y mbed-cli' ;uninstall mbed-cli
RMDir /r "$INSTDIR\mbed-cli"
Delete "$INSTDIR\${MBED_SERIAL_DRIVER}"
Delete "$INSTDIR\p.ico"
Delete "$INSTDIR\mbed_uninstall.exe"
Delete "$INSTDIR\mbed.exe"
RMDir "$INSTDIR\" ;remove install folder(only if empty)
DeleteRegKey SHCTX "${UNINST_KEY}"
SectionEnd
Expand Down
23 changes: 0 additions & 23 deletions source/pip_install_mbed.bat

This file was deleted.