Skip to content

Commit

Permalink
feat: Enforce a proper application location
Browse files Browse the repository at this point in the history
Close #1301, Close #1298
  • Loading branch information
develar committed Mar 28, 2017
1 parent 7c6b4ab commit 958a7ae
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv": "^5.0.4-beta.0",
"ajv-keywords": "^2.0.1-beta.2",
"archiver": "^1.3.0",
"aws-sdk": "^2.32.0",
"aws-sdk": "^2.33.0",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand All @@ -48,7 +48,7 @@
"mime": "^1.3.4",
"minimatch": "^3.0.3",
"node-emoji": "^1.5.1",
"node-forge": "^0.7.0",
"node-forge": "^0.7.1",
"normalize-package-data": "^2.3.6",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
Expand All @@ -63,7 +63,7 @@
"yargs": "^7.0.2"
},
"devDependencies": {
"@types/electron": "^1.4.34",
"@types/electron": "^1.4.35",
"@types/ini": "^1.3.29",
"@types/jest": "^19.2.2",
"@types/js-yaml": "^3.5.29",
Expand All @@ -89,7 +89,7 @@
"source-map-support": "^0.4.14",
"ts-babel": "^3.0.0",
"tslint": "^4.5.1",
"typescript": "^2.2.1",
"typescript": "^2.2.2",
"typescript-json-schema": "0.10.0",
"whitespace": "^2.1.0",
"xml2js": "^0.4.17"
Expand Down
18 changes: 17 additions & 1 deletion packages/electron-builder/templates/nsis/boringInstaller.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,23 @@
!endif

!ifdef allowToChangeInstallationDirectory
!include StrContains.nsh

!insertmacro MUI_PAGE_DIRECTORY

# pageDirectory leave doesn't work (it seems because $INSTDIR is set after custom leave function)
# so, we yse instfiles pre
!define MUI_PAGE_CUSTOMFUNCTION_PRE instFilesPre

# Sanitize the MUI_PAGE_DIRECTORY result to make sure it has a application name sub-folder
Function instFilesPre
${If} ${FileExists} "$INSTDIR\*"
${StrContains} $0 "${APP_FILENAME}" $INSTDIR
${If} $0 == ""
StrCpy $INSTDIR "$INSTDIR\${APP_FILENAME}"
${endIf}
${endIf}
FunctionEnd
!endif
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
Expand All @@ -49,7 +65,7 @@
# special return value for outer instance so it knows we did not have admin rights
SetErrorLevel 0x666666
Quit
${EndIf}
${endIf}

!ifndef MULTIUSER_INIT_TEXT_ADMINREQUIRED
!define MULTIUSER_INIT_TEXT_ADMINREQUIRED "$(^Caption) requires administrator privileges."
Expand Down
48 changes: 48 additions & 0 deletions packages/electron-builder/templates/nsis/include/StrContains.nsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
; StrContains
; This function does a case sensitive searches for an occurrence of a substring in a string.
; It returns the substring if it is found.
; Otherwise it returns null("").
; Written by kenglish_hi
; Adapted from StrReplace written by dandaman32


Var STR_HAYSTACK
Var STR_NEEDLE
Var STR_CONTAINS_VAR_1
Var STR_CONTAINS_VAR_2
Var STR_CONTAINS_VAR_3
Var STR_CONTAINS_VAR_4
Var STR_RETURN_VAR

Function StrContains
Exch $STR_NEEDLE
Exch 1
Exch $STR_HAYSTACK
; Uncomment to debug
;MessageBox MB_OK 'STR_NEEDLE = $STR_NEEDLE STR_HAYSTACK = $STR_HAYSTACK '
StrCpy $STR_RETURN_VAR ""
StrCpy $STR_CONTAINS_VAR_1 -1
StrLen $STR_CONTAINS_VAR_2 $STR_NEEDLE
StrLen $STR_CONTAINS_VAR_4 $STR_HAYSTACK
loop:
IntOp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_1 + 1
StrCpy $STR_CONTAINS_VAR_3 $STR_HAYSTACK $STR_CONTAINS_VAR_2 $STR_CONTAINS_VAR_1
StrCmp $STR_CONTAINS_VAR_3 $STR_NEEDLE found
StrCmp $STR_CONTAINS_VAR_1 $STR_CONTAINS_VAR_4 done
Goto loop
found:
StrCpy $STR_RETURN_VAR $STR_NEEDLE
Goto done
done:
Pop $STR_NEEDLE ;Prevent "invalid opcode" errors and keep the
Exch $STR_RETURN_VAR
FunctionEnd

!macro _StrContainsConstructor OUT NEEDLE HAYSTACK
Push `${HAYSTACK}`
Push `${NEEDLE}`
Call StrContains
Pop `${OUT}`
!macroend

!define StrContains '!insertmacro "_StrContainsConstructor"'
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3217,8 +3217,8 @@ [email protected]:
yargs "^6.6.0"

typescript@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.1.tgz#4862b662b988a4c8ff691cc7969622d24db76ae9"
version "2.2.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.2.tgz#606022508479b55ffa368b58fee963a03dfd7b0c"

typescript@~2.1.5:
version "2.1.6"
Expand Down

0 comments on commit 958a7ae

Please sign in to comment.