From 958a7ae2bfe1b86cb7318e12c60bff25d65c9221 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 28 Mar 2017 09:01:48 +0200 Subject: [PATCH] feat: Enforce a proper application location Close #1301, Close #1298 --- package.json | 8 ++-- .../templates/nsis/boringInstaller.nsh | 18 ++++++- .../templates/nsis/include/StrContains.nsh | 48 +++++++++++++++++++ yarn.lock | 4 +- 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 packages/electron-builder/templates/nsis/include/StrContains.nsh diff --git a/package.json b/package.json index 5f9456ed4eb..83a79a1641f 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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", @@ -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" diff --git a/packages/electron-builder/templates/nsis/boringInstaller.nsh b/packages/electron-builder/templates/nsis/boringInstaller.nsh index e6adcef14ea..7990dfd563f 100644 --- a/packages/electron-builder/templates/nsis/boringInstaller.nsh +++ b/packages/electron-builder/templates/nsis/boringInstaller.nsh @@ -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 @@ -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." diff --git a/packages/electron-builder/templates/nsis/include/StrContains.nsh b/packages/electron-builder/templates/nsis/include/StrContains.nsh new file mode 100644 index 00000000000..c7d395cd816 --- /dev/null +++ b/packages/electron-builder/templates/nsis/include/StrContains.nsh @@ -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"' \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 58e0a2d8352..43ce1b4e689 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3217,8 +3217,8 @@ typescript-json-schema@0.10.0: 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"