-
Notifications
You must be signed in to change notification settings - Fork 1
/
metadata.ts
60 lines (47 loc) · 1.94 KB
/
metadata.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
import cache from './cache.ts';
const txtDec = new TextDecoder();
async function setMetadata(exePath: string, metadata: Metadata, opts = {recache: false}): Promise<string[]> {
const rceditPath = await cache(new URL('https://github.com/electron/rcedit/releases/download/v2.0.0/rcedit-x64.exe'), {refresh: opts.recache});
const problems = checkMetadata(metadata);
if (problems.length) return problems;
const errors: string[] = [];
const {stdout, stderr} = new Deno.Command(rceditPath, {
args: [
exePath,
'--set-icon', metadata.Icon,
'--set-version-string', 'FileDescription', metadata.FileDescription,
'--set-version-string', 'LegalCopyright', metadata.LegalCopyright,
'--set-version-string', 'OriginalFilename', metadata.OriginalFilename,
'--set-file-version', metadata.FileVersion,
'--set-product-version', metadata.ProductVersion,
'--set-version-string', 'ProductName', metadata.ProductName,
// '--set-version-string', 'Translation', metadata.Translation,
// '--set-requested-execution-level', metadata.RequestedExecutionLevel,
],
stdout: 'piped',
stderr: 'piped',
}).outputSync();
if (stdout.length) errors.push(txtDec.decode(stdout));
if (stderr.length) errors.push(txtDec.decode(stderr));
return errors;
}
function checkMetadata(metadata: Metadata): string[] {
const problems: string[] = [];
if (!/\d/.test(metadata.ProductVersion[0]))
problems.push('The first character of the ProductVersion must be a number.');
if (!/^\d[\d\.]*$/.test(metadata.FileVersion))
problems.push('FileVersion can only contain numbers and dots, and must begin with a number.');
return problems;
}
interface Metadata {
Icon: string,
FileDescription: string
LegalCopyright: string
OriginalFilename: string
FileVersion: string
ProductVersion: string
ProductName: string
// Translation: string
// RequestedExecutionLevel: 'asInvoker' | 'highestAvailable' | 'requireAdministrator'
}
export {type Metadata, setMetadata, checkMetadata};