Skip to content

Commit

Permalink
fix: Stub Executables missing in Squirrel.Windows 1.5.1
Browse files Browse the repository at this point in the history
Closes #1011
  • Loading branch information
develar committed Dec 20, 2016
1 parent f01a9f7 commit 0ce1a3c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 30 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"7zip-bin": "^2.0.4",
"ansi-escapes": "^1.4.0",
"archiver": "^1.3.0",
"archiver-utils": "^1.3.0",
"asar-electron-builder": "^0.13.5",
"bluebird-lst-c": "^1.0.5",
"chalk": "^1.1.3",
Expand Down
54 changes: 29 additions & 25 deletions src/targets/squirrelPack.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as path from "path"
import BluebirdPromise from "bluebird-lst-c"
import { remove, copy, createWriteStream, unlink, ensureDir } from "fs-extra-p"
import { remove, copy, createWriteStream, unlink, ensureDir, stat } from "fs-extra-p"
import { spawn, exec, prepareArgs, execWine, debug } from "../util/util"
import { WinPackager } from "../winPackager"
import { log } from "../util/log"
import { walk, copyFile } from "../util/fs"

const archiverUtil = require("archiver-utils")
const archiver = require("archiver")

export function convertVersion(version: string): string {
Expand Down Expand Up @@ -79,7 +79,7 @@ export async function buildInstaller(options: SquirrelOptions, outputDirectory:
const setupPath = path.join(outputDirectory, setupExe || `${options.name || options.productName}Setup.exe`)

await BluebirdPromise.all<any>([
pack(options, appOutDir, appUpdate, nupkgPath, version, options.packageCompressionLevel),
pack(options, appOutDir, appUpdate, nupkgPath, version, packager),
copy(path.join(options.vendorPath, "Setup.exe"), setupPath),
])

Expand All @@ -91,8 +91,7 @@ export async function buildInstaller(options: SquirrelOptions, outputDirectory:
embeddedArchive.finalize()
await embeddedArchivePromise

const writeZipToSetup = path.join(options.vendorPath, "WriteZipToSetup.exe")
await execWine(writeZipToSetup, [setupPath, embeddedArchiveFile])
await execWine(path.join(options.vendorPath, "WriteZipToSetup.exe"), [setupPath, embeddedArchiveFile])

await packager.signAndEditResources(setupPath)
if (options.msi && process.platform === "win32") {
Expand All @@ -103,8 +102,8 @@ export async function buildInstaller(options: SquirrelOptions, outputDirectory:
}
}

async function pack(options: SquirrelOptions, directory: string, updateFile: string, outFile: string, version: string, packageCompressionLevel?: number) {
const archive = archiver("zip", {zlib: {level: packageCompressionLevel == null ? 9 : packageCompressionLevel}})
async function pack(options: SquirrelOptions, directory: string, updateFile: string, outFile: string, version: string, packager: WinPackager) {
const archive = archiver("zip", {zlib: {level: options.packageCompressionLevel == null ? 9 : options.packageCompressionLevel}})
const archiveOut = createWriteStream(outFile)
const archivePromise = new BluebirdPromise(function (resolve, reject) {
archive.on("error", reject)
Expand Down Expand Up @@ -169,7 +168,7 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
</coreProperties>`.replace(/\n/, "\r\n"), {name: "1.psmdcp", prefix: "package/services/metadata/core-properties"})

archive.file(updateFile, {name: "Update.exe", prefix: "lib/net45"})
encodedZip(archive, directory, "lib/net45")
await encodedZip(archive, directory, "lib/net45", options.vendorPath, packager)
await archivePromise
}

Expand Down Expand Up @@ -219,27 +218,32 @@ async function msi(options: SquirrelOptions, nupkgPath: string, setupPath: strin
])
}

function encodedZip(archive: any, dir: string, prefix: string) {
archiverUtil.walkdir(dir, function (error: any, files: any) {
if (error) {
archive.emit("error", error)
async function encodedZip(archive: any, dir: string, prefix: string, vendorPath: string, packager: WinPackager) {
await walk(dir, null, async (file, stats) => {
if (stats.isDirectory()) {
return
}

for (const file of files) {
if (file.stats.isDirectory()) {
continue
}

// GBK file name encoding (or Non-English file name) caused a problem
const entryData = {
name: encodeURI(file.relative.replace(/\\/g, "/")).replace(/%5B/g, "[").replace(/%5D/g, "]"),
// GBK file name encoding (or Non-English file name) caused a problem
const relativeSafeFilePath = encodeURI(file.substring(dir.length + 1).replace(/\\/g, "/")).replace(/%5B/g, "[").replace(/%5D/g, "]")
archive._append(file, {
name: relativeSafeFilePath,
prefix: prefix,
stats: stats,
})

// createExecutableStubForExe
if (file.endsWith(".exe") && !file.includes("squirrel.exe")) {
const tempFile = await packager.getTempFile("stub.exe")
await copyFile(path.join(vendorPath, "StubExecutable.exe"), tempFile, null, false)
await execWine(path.join(vendorPath, "WriteZipToSetup.exe"), ["--copy-stub-resources", file, tempFile])

archive._append(tempFile, {
name: relativeSafeFilePath.substring(0, relativeSafeFilePath.length - 4) + "_ExecutionStub.exe",
prefix: prefix,
stats: file.stats,
}
archive._append(file.path, entryData)
stats: await stat(tempFile),
})
}

archive.finalize()
})
archive.finalize()
}
4 changes: 2 additions & 2 deletions src/targets/squirrelWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { buildInstaller, convertVersion, SquirrelOptions } from "./squirrelPack"
import { SquirrelWindowsOptions } from "../options/winOptions"
import { Target } from "./targetFactory"

const SW_VERSION = "1.5.1"
const SW_VERSION = "1.5.1.3"
//noinspection SpellCheckingInspection
const SW_SHA2 = "b9bff7b239d05258170c1c2f096aea0966bea442b61eff71f7333c0096664708"
const SW_SHA2 = "526701c61fffed97f622b110cfd15c4a1197ce082705437e9ef938c0cb8f4172"

export default class SquirrelWindowsTarget extends Target {
private readonly options: SquirrelWindowsOptions = Object.assign({}, this.packager.platformSpecificBuildOptions, this.packager.config.squirrelWindows)
Expand Down
4 changes: 2 additions & 2 deletions src/util/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function exists(file: string): Promise<boolean> {
}
}

export async function walk(initialDirPath: string, filter?: Filter, consumer?: (file: string, stat: Stats, parent: string) => any): Promise<Array<string>> {
export async function walk(initialDirPath: string, filter?: Filter | null, consumer?: (file: string, stat: Stats, parent: string) => any): Promise<Array<string>> {
const result: Array<string> = []
const queue: Array<string> = [initialDirPath]
let addDirToResult = false
Expand Down Expand Up @@ -89,7 +89,7 @@ const _isUseHardLink = process.platform != "win32" && process.env.USE_HARD_LINKS
* Hard links is used if supported and allowed.
* File permission is fixed — allow execute for all if owner can, allow read for all if owner can.
*/
export function copyFile(src: string, dest: string, stats?: Stats, isUseHardLink = _isUseHardLink): Promise<any> {
export function copyFile(src: string, dest: string, stats?: Stats | null, isUseHardLink = _isUseHardLink): Promise<any> {
if (stats != null) {
const originalModeNumber = stats.mode
const mode = new Mode(stats)
Expand Down
1 change: 1 addition & 0 deletions test/src/helpers/expectedContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const expectedWinContents = [
"lib/net45/node.dll",
"lib/net45/snapshot_blob.bin",
"lib/net45/TestApp.exe",
"lib/net45/TestApp_ExecutionStub.exe",
"lib/net45/ui_resources_200_percent.pak",
"lib/net45/Update.exe",
"lib/net45/views_resources_200_percent.pak",
Expand Down
6 changes: 6 additions & 0 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
}
return `lib/net45/${encodeURI(appInfo.productFilename).replace(/%5B/g, "[").replace(/%5D/g, "]")}.exe`
}
else if (it === "lib/net45/TestApp_ExecutionStub.exe") {
if (appInfo.productFilename === "Test App ßW") {
return `lib/net45/Test%20App%20%C3%9FW_ExecutionStub.exe`
}
return `lib/net45/${encodeURI(appInfo.productFilename).replace(/%5B/g, "[").replace(/%5D/g, "]")}_ExecutionStub.exe`
}
else {
return it
}
Expand Down

0 comments on commit 0ce1a3c

Please sign in to comment.