-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinstaller_windows.ts
112 lines (100 loc) · 3.51 KB
/
installer_windows.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { Installer, InstallResult, DownloadResult } from "./installer";
import { Platform } from "./platform";
import { waitInstall } from "./watch";
import * as versions from "./params";
import path from "path";
import os from "os";
import fs from "fs";
import cp from "child_process";
import * as tc from "@actions/tool-cache";
import * as io from "@actions/io";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
const isENOENT = (e: unknown): boolean => {
return (
typeof e === "object" && e !== null && "code" in e && e.code === "ENOENT"
);
};
export class WindowsInstaller implements Installer {
constructor(private readonly platform: Platform) {}
async checkInstalled(
version: versions.Version
): Promise<InstallResult | undefined> {
const root = this.rootDir(version);
try {
await fs.promises.stat(root);
} catch (e) {
if (isENOENT(e)) {
return undefined;
}
throw e;
}
return { root, bin: "msedge.exe" };
}
async download(version: versions.Version): Promise<DownloadResult> {
const url = this.url(version);
core.info(`Acquiring ${version} from ${url}`);
let installer = await tc.downloadTool(url);
await fs.promises.rename(installer, `${installer}.exe`);
installer = `${installer}.exe`;
return { archive: installer };
}
async install(
version: versions.Version,
archive: string
): Promise<InstallResult> {
// Use a native API to kill the process.
const p = cp.spawn(archive);
p.stdout.on("data", (data: Buffer) =>
process.stdout.write(data.toString())
);
p.stderr.on("data", (data: Buffer) =>
process.stderr.write(data.toString())
);
// Do not wait for the installer, as an installer for windows requires an
// OK prompt on the dialog at the end of the install.
try {
await waitInstall(path.join(this.rootDir(version), "msedge.exe"));
} finally {
p.kill();
}
return { root: this.rootDir(version), bin: "msedge.exe" };
}
private url(version: versions.Version): string {
switch (version) {
case versions.StableVersion:
return `https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&Channel=Stable&language=en`;
case versions.BetaVersion:
return `https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&Channel=Beta&language=en`;
case versions.DevVersion:
return `https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&Channel=Dev&language=en`;
case versions.CanaryVersion:
return `https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&Channel=Canary&language=en`;
}
}
private rootDir(version: versions.Version): string {
switch (version) {
case versions.StableVersion:
return "C:\\Program Files (x86)\\Microsoft\\Edge\\Application";
case versions.BetaVersion:
return "C:\\Program Files (x86)\\Microsoft\\Edge Beta\\Application";
case versions.DevVersion:
return "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application";
case versions.CanaryVersion:
return path.join(
os.homedir(),
"AppData\\Local\\Microsoft\\Edge SxS\\Application"
);
}
}
async test(version: versions.Version): Promise<void> {
const msedgeBin = await io.which("msedge", true);
await exec.exec("wmic", [
"datafile",
"where",
`name="${msedgeBin.replace(/\\/g, "\\\\")}"`,
"get",
"version",
]);
}
}