electron-forge-maker-innosetup 0.3.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/parser.js CHANGED
@@ -35,70 +35,199 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.InnoScriptParser = void 0;
37
37
  const fs = __importStar(require("fs"));
38
+ const errors_1 = require("./errors");
39
+ const logger_1 = require("./logger");
38
40
  /**
39
41
  * Inno Setup 脚本解析器
40
42
  * 将 .iss 文件解析为 InnoSetupConfig 对象
41
43
  */
42
44
  class InnoScriptParser {
43
45
  /**
44
- * 从文件路径解析 ISS 脚本
46
+ * 解析 ISS 文件
47
+ * @param filePath .iss 文件路径
48
+ * @returns 解析后的配置
49
+ * @throws ParseError 如果文件无法读取
45
50
  */
46
- static parseFile(issFilePath) {
47
- const content = fs.readFileSync(issFilePath, "utf-8");
51
+ static parseFile(filePath) {
52
+ (0, logger_1.logParser)("解析文件: %s", filePath);
53
+ if (!fs.existsSync(filePath)) {
54
+ throw new errors_1.ParseError(`文件不存在: ${filePath}`);
55
+ }
56
+ const content = fs.readFileSync(filePath, "utf-8");
48
57
  return this.parse(content);
49
58
  }
50
59
  /**
51
60
  * 解析 ISS 脚本内容
52
61
  * @param content ISS 脚本内容
53
- * @param preserveDefineReferences 是否保留 {#...} 引用(不替换为实际值)
62
+ * @param options 解析选项
63
+ * @returns 解析后的配置
54
64
  */
55
- static parse(content, preserveDefineReferences = true) {
56
- const config = {};
57
- const defines = {};
65
+ static parse(content, options = {}) {
66
+ const { preserveDefineReferences = true } = options;
67
+ (0, logger_1.logParser)("解析内容, preserveDefineReferences: %s", preserveDefineReferences);
58
68
  const lines = content.split(/\r?\n/);
59
- let currentSection = null;
60
- let codeSection = "";
61
- let inCodeSection = false;
62
- // 第一次扫描:提取所有 #define 定义
63
- for (let i = 0; i < lines.length; i++) {
64
- let line = lines[i].trim();
69
+ const defines = new Map();
70
+ const result = {
71
+ config: {},
72
+ errors: [],
73
+ };
74
+ // 第一遍扫描:提取所有 #define 指令
75
+ this.extractDefines(lines, defines);
76
+ if (defines.size > 0) {
77
+ result.config.Defines = Object.fromEntries(defines);
78
+ }
79
+ // 第二遍扫描:解析段落
80
+ this.parseSections(lines, result, defines, preserveDefineReferences);
81
+ // 验证必需的字段
82
+ if (!result.config.Setup?.AppName || !result.config.Setup?.AppVersion) {
83
+ result.errors.push(new errors_1.ParseError("缺少必需的 Setup 部分属性: AppName 和 AppVersion 是必需的"));
84
+ }
85
+ if (result.errors.length > 0) {
86
+ throw result.errors[0];
87
+ }
88
+ // 构建最终配置(包含必需字段)
89
+ const setup = {
90
+ AppName: result.config.Setup?.AppName ?? "",
91
+ AppVersion: result.config.Setup?.AppVersion ?? "",
92
+ DefaultDirName: result.config.Setup?.DefaultDirName ?? "{autopf}\\App",
93
+ OutputDir: result.config.Setup?.OutputDir ?? "output",
94
+ ...result.config.Setup,
95
+ };
96
+ return {
97
+ ...result.config,
98
+ Setup: setup,
99
+ };
100
+ }
101
+ /**
102
+ * 从行中提取 #define 指令
103
+ */
104
+ static extractDefines(lines, defines) {
105
+ for (const line of lines) {
106
+ const trimmed = line.trim();
65
107
  // 跳过空行和注释
66
- if (!line || line.startsWith(";") || line.startsWith("//")) {
108
+ if (!trimmed || trimmed.startsWith(";") || trimmed.startsWith("//")) {
67
109
  continue;
68
110
  }
69
111
  // 解析 #define 指令
70
- const defineMatch = line.match(/^#define\s+(\w+)\s+(.+)$/);
112
+ const defineMatch = trimmed.match(/^#define\s+(\w+)\s+(.+)$/);
71
113
  if (defineMatch) {
72
114
  const [, varName, varValue] = defineMatch;
73
- // 如果保留引用,则保存原始表达式;否则计算值
74
- defines[varName] = preserveDefineReferences
75
- ? this.preserveDefineExpression(varValue)
76
- : this.parseDefineValue(varValue, defines);
115
+ if (varName && varValue) {
116
+ defines.set(varName, this.parseDefineValue(varValue.trim(), defines));
117
+ }
77
118
  }
78
119
  }
79
- // 如果有 defines,添加到配置中
80
- if (Object.keys(defines).length > 0) {
81
- config.Defines = defines;
120
+ }
121
+ /**
122
+ * 解析 #define 的值
123
+ */
124
+ static parseDefineValue(value, defines) {
125
+ // 移除外层引号
126
+ if (value.startsWith('"') && value.endsWith('"')) {
127
+ return value.slice(1, -1);
128
+ }
129
+ // 处理字符串拼接
130
+ if (value.includes("+")) {
131
+ return this.parseConcatenation(value, defines);
132
+ }
133
+ // 处理 StringChange 函数
134
+ if (value.includes("StringChange(")) {
135
+ return this.parseStringChange(value, defines);
136
+ }
137
+ // 检查是否是对其他定义的引用
138
+ const existingDefine = defines.get(value);
139
+ if (existingDefine !== undefined) {
140
+ return existingDefine;
141
+ }
142
+ // 检查是否为数字
143
+ const numValue = Number(value);
144
+ if (!isNaN(numValue)) {
145
+ return numValue;
146
+ }
147
+ return value;
148
+ }
149
+ /**
150
+ * 解析字符串拼接表达式
151
+ */
152
+ static parseConcatenation(value, defines) {
153
+ const parts = value.split("+").map((p) => p.trim());
154
+ let result = "";
155
+ for (const part of parts) {
156
+ if (part.startsWith('"') && part.endsWith('"')) {
157
+ result += part.slice(1, -1);
158
+ }
159
+ else {
160
+ const defineValue = defines.get(part);
161
+ result += defineValue !== undefined ? String(defineValue) : part;
162
+ }
163
+ }
164
+ return result;
165
+ }
166
+ /**
167
+ * 解析 StringChange 函数调用
168
+ */
169
+ static parseStringChange(value, defines) {
170
+ const match = value.match(/StringChange\(([^,]+),\s*"([^"]*)",\s*"([^"]*)"\)/);
171
+ if (!match) {
172
+ return value;
173
+ }
174
+ const [, varRef, searchStr, replaceStr] = match;
175
+ if (!varRef) {
176
+ return value;
177
+ }
178
+ const varName = varRef.trim();
179
+ const sourceValue = defines.get(varName);
180
+ let result = typeof sourceValue === "string" ? sourceValue : varName;
181
+ result = result.replace(new RegExp(searchStr ?? "", "g"), replaceStr ?? "");
182
+ // 处理后缀拼接
183
+ const suffixMatch = value.match(/StringChange\([^)]+\)(.*)$/);
184
+ if (suffixMatch?.[1]) {
185
+ const suffix = suffixMatch[1].trim();
186
+ if (suffix.startsWith("+")) {
187
+ const suffixPart = suffix.substring(1).trim();
188
+ if (suffixPart.startsWith('"') && suffixPart.endsWith('"')) {
189
+ result += suffixPart.slice(1, -1);
190
+ }
191
+ }
82
192
  }
83
- // 第二次扫描:解析配置段落
193
+ return result;
194
+ }
195
+ /**
196
+ * 替换 {#ConstantName} 引用为实际值
197
+ */
198
+ static replaceDefines(text, defines) {
199
+ return text.replace(/\{#(\w+)\}/g, (match, varName) => {
200
+ const value = defines.get(varName);
201
+ return value !== undefined ? String(value) : match;
202
+ });
203
+ }
204
+ /**
205
+ * 解析所有段落
206
+ */
207
+ static parseSections(lines, result, defines, preserveDefineReferences) {
208
+ let currentSection = null;
209
+ let codeSection = "";
210
+ let inCodeSection = false;
84
211
  for (let i = 0; i < lines.length; i++) {
85
- let line = lines[i].trim();
212
+ const rawLine = lines[i];
213
+ if (rawLine === undefined)
214
+ continue;
215
+ let line = rawLine.trim();
86
216
  // 跳过空行、注释和 #define 指令
87
- if (!line ||
88
- line.startsWith(";") ||
89
- line.startsWith("//") ||
90
- line.startsWith("#define")) {
217
+ if (!line || line.startsWith(";") || line.startsWith("//") || line.startsWith("#define")) {
91
218
  continue;
92
219
  }
93
- // 如果不保留引用,则替换常量引用 {#ConstantName}
220
+ // 如果不保留引用,则替换常量
94
221
  if (!preserveDefineReferences) {
95
222
  line = this.replaceDefines(line, defines);
96
223
  }
97
- // 检测段落
224
+ // 检查段落头
98
225
  const sectionMatch = line.match(/^\[(\w+)\]$/);
99
226
  if (sectionMatch) {
100
- currentSection = sectionMatch[1];
101
- // 处理 Code 段落
227
+ const sectionName = sectionMatch[1];
228
+ if (sectionName) {
229
+ currentSection = sectionName;
230
+ }
102
231
  if (currentSection === "Code") {
103
232
  inCodeSection = true;
104
233
  codeSection = "";
@@ -108,162 +237,106 @@ class InnoScriptParser {
108
237
  }
109
238
  continue;
110
239
  }
111
- // 如果在 Code 段落中,收集所有代码
240
+ // 单独处理 Code 段落(收集原始行)
112
241
  if (inCodeSection) {
113
- // 对于 Code 段落,使用原始行(带缩进)
114
242
  const processedLine = preserveDefineReferences
115
- ? lines[i]
116
- : this.replaceDefines(lines[i], defines);
243
+ ? rawLine
244
+ : this.replaceDefines(rawLine, defines);
117
245
  codeSection += processedLine + "\n";
118
246
  continue;
119
247
  }
120
- // 解析不同段落
121
- if (currentSection === "Setup") {
122
- this.parseSetupLine(line, config);
123
- }
124
- else if (currentSection === "Languages") {
125
- this.parseLanguagesLine(line, config);
126
- }
127
- else if (currentSection === "Tasks") {
128
- this.parseTasksLine(line, config);
129
- }
130
- else if (currentSection === "Types") {
131
- this.parseTypesLine(line, config);
132
- }
133
- else if (currentSection === "Components") {
134
- this.parseComponentsLine(line, config);
135
- }
136
- else if (currentSection === "Files") {
137
- this.parseFilesLine(line, config);
138
- }
139
- else if (currentSection === "Dirs") {
140
- this.parseDirsLine(line, config);
141
- }
142
- else if (currentSection === "Icons") {
143
- this.parseIconsLine(line, config);
144
- }
145
- else if (currentSection === "INI") {
146
- this.parseINILine(line, config);
147
- }
148
- else if (currentSection === "InstallDelete") {
149
- this.parseInstallDeleteLine(line, config);
150
- }
151
- else if (currentSection === "UninstallDelete") {
152
- this.parseUninstallDeleteLine(line, config);
153
- }
154
- else if (currentSection === "Registry") {
155
- this.parseRegistryLine(line, config);
156
- }
157
- else if (currentSection === "Run") {
158
- this.parseRunLine(line, config);
159
- }
160
- else if (currentSection === "UninstallRun") {
161
- this.parseUninstallRunLine(line, config);
162
- }
163
- else if (currentSection === "Messages") {
164
- this.parseMessagesLine(line, config);
165
- }
166
- else if (currentSection === "CustomMessages") {
167
- this.parseCustomMessagesLine(line, config);
168
- }
248
+ // 根据当前段落解析行
249
+ this.parseSectionLine(currentSection, line, result, i + 1);
169
250
  }
170
- // 添加 Code 段落
251
+ // 添加收集的代码段落
171
252
  if (codeSection.trim()) {
172
- config.Code = codeSection.trim();
253
+ result.config.Code = codeSection.trim();
173
254
  }
174
- return config;
175
255
  }
176
256
  /**
177
- * 保留 #define 的原始表达式
257
+ * 解析段落中的单行
178
258
  */
179
- static preserveDefineExpression(value) {
180
- value = value.trim();
181
- // 移除外层引号(如果有)
182
- if (value.startsWith('"') && value.endsWith('"')) {
183
- return value.slice(1, -1);
259
+ static parseSectionLine(section, line, result, lineNumber) {
260
+ if (!section) {
261
+ return;
184
262
  }
185
- return value;
186
- }
187
- /**
188
- * 解析 #define 的值,支持字符串拼接和函数调用
189
- */
190
- static parseDefineValue(value, defines) {
191
- value = value.trim();
192
- // 处理字符串拼接 (e.g., MyAppName + " File")
193
- if (value.includes("+")) {
194
- const parts = value.split("+").map((p) => p.trim());
195
- let result = "";
196
- for (const part of parts) {
197
- if (part.startsWith('"') && part.endsWith('"')) {
198
- // 直接的字符串字面量
199
- result += part.slice(1, -1);
200
- }
201
- else if (defines[part]) {
202
- // 引用已定义的常量
203
- result += defines[part];
204
- }
205
- else {
206
- // 未知引用,保持原样
207
- result += part;
208
- }
209
- }
210
- return result;
211
- }
212
- // 处理 StringChange 函数 (e.g., StringChange(MyAppAssocName, " ", ""))
213
- const stringChangeMatch = value.match(/StringChange\(([^,]+),\s*"([^"]*)",\s*"([^"]*)"\)/);
214
- if (stringChangeMatch) {
215
- const [, varRef, searchStr, replaceStr] = stringChangeMatch;
216
- const varName = varRef.trim();
217
- const sourceValue = defines[varName] ? String(defines[varName]) : varName;
218
- let result = sourceValue.replace(new RegExp(searchStr, "g"), replaceStr);
219
- // 处理后续的拼接,例如 StringChange(...) + ".myp"
220
- const fullMatch = value.match(/StringChange\([^)]+\)(.*)$/);
221
- if (fullMatch && fullMatch[1]) {
222
- const suffix = fullMatch[1].trim();
223
- if (suffix.startsWith("+")) {
224
- const suffixPart = suffix.substring(1).trim();
225
- if (suffixPart.startsWith('"') && suffixPart.endsWith('"')) {
226
- result += suffixPart.slice(1, -1);
227
- }
228
- else {
229
- result += suffixPart;
230
- }
231
- }
263
+ try {
264
+ switch (section) {
265
+ case "Setup":
266
+ this.parseSetupLine(line, result);
267
+ break;
268
+ case "Languages":
269
+ this.parseLanguagesLine(line, result);
270
+ break;
271
+ case "Tasks":
272
+ this.parseTasksLine(line, result);
273
+ break;
274
+ case "Types":
275
+ this.parseTypesLine(line, result);
276
+ break;
277
+ case "Components":
278
+ this.parseComponentsLine(line, result);
279
+ break;
280
+ case "Files":
281
+ this.parseFilesLine(line, result);
282
+ break;
283
+ case "Dirs":
284
+ this.parseDirsLine(line, result);
285
+ break;
286
+ case "Icons":
287
+ this.parseIconsLine(line, result);
288
+ break;
289
+ case "INI":
290
+ this.parseINILine(line, result);
291
+ break;
292
+ case "InstallDelete":
293
+ this.parseInstallDeleteLine(line, result);
294
+ break;
295
+ case "UninstallDelete":
296
+ this.parseUninstallDeleteLine(line, result);
297
+ break;
298
+ case "Registry":
299
+ this.parseRegistryLine(line, result);
300
+ break;
301
+ case "Run":
302
+ this.parseRunLine(line, result);
303
+ break;
304
+ case "UninstallRun":
305
+ this.parseUninstallRunLine(line, result);
306
+ break;
307
+ case "Messages":
308
+ this.parseMessagesLine(line, result);
309
+ break;
310
+ case "CustomMessages":
311
+ this.parseCustomMessagesLine(line, result);
312
+ break;
232
313
  }
233
- return result;
234
314
  }
235
- // 处理常量引用 (e.g., MyAppName)
236
- if (defines[value]) {
237
- return String(defines[value]);
315
+ catch (error) {
316
+ const message = error instanceof Error ? error.message : String(error);
317
+ result.errors.push(new errors_1.ParseError(`解析失败: ${message}`, lineNumber));
238
318
  }
239
- // 移除外层引号
240
- if (value.startsWith('"') && value.endsWith('"')) {
241
- return value.slice(1, -1);
242
- }
243
- return value;
244
319
  }
245
320
  /**
246
- * 替换字符串中的常量引用 {#ConstantName}
321
+ * 解析 Setup 段落行
247
322
  */
248
- static replaceDefines(text, defines) {
249
- return text.replace(/\{#(\w+)\}/g, (match, varName) => {
250
- return defines[varName] !== undefined ? String(defines[varName]) : match;
251
- });
252
- }
253
- /**
254
- * 解析 Setup 段落的一行
255
- */
256
- static parseSetupLine(line, config) {
323
+ static parseSetupLine(line, result) {
257
324
  const match = line.match(/^(\w+)\s*=\s*(.+)$/);
258
- if (!match)
325
+ if (!match) {
259
326
  return;
327
+ }
260
328
  const [, key, value] = match;
261
- if (!config.Setup) {
262
- config.Setup = {};
329
+ if (!key || !value) {
330
+ return;
331
+ }
332
+ if (!result.config.Setup) {
333
+ result.config.Setup = {};
263
334
  }
264
- // 移除引号
265
335
  let parsedValue = value.trim();
266
- if (parsedValue.startsWith('"') && parsedValue.endsWith('"')) {
336
+ // 移除引号
337
+ if (typeof parsedValue === "string" &&
338
+ parsedValue.startsWith('"') &&
339
+ parsedValue.endsWith('"')) {
267
340
  parsedValue = parsedValue.slice(1, -1);
268
341
  }
269
342
  // 转换布尔值
@@ -274,13 +347,14 @@ class InnoScriptParser {
274
347
  parsedValue = false;
275
348
  }
276
349
  // 转换数字
277
- if (/^\d+$/.test(parsedValue)) {
350
+ if (typeof parsedValue === "string" && /^\d+$/.test(parsedValue)) {
278
351
  parsedValue = parseInt(parsedValue, 10);
279
352
  }
280
- config.Setup[key] = parsedValue;
353
+ // 使用 Object.assign 设置属性以正确处理类型
354
+ Object.assign(result.config.Setup, { [key]: parsedValue });
281
355
  }
282
356
  /**
283
- * 解析参数行(用于 Languages, Files, Icons 等段落)
357
+ * 从行中解析参数(Name: "value"; Param: "value")
284
358
  */
285
359
  static parseParams(line) {
286
360
  const params = {};
@@ -289,321 +363,437 @@ class InnoScriptParser {
289
363
  const match = part.match(/^(\w+):\s*(.+)$/);
290
364
  if (match) {
291
365
  const [, key, value] = match;
292
- // 移除引号
293
- let parsedValue = value.trim();
294
- if (parsedValue.startsWith('"') && parsedValue.endsWith('"')) {
295
- parsedValue = parsedValue.slice(1, -1);
366
+ if (key && value) {
367
+ let parsedValue = value.trim();
368
+ // 移除引号
369
+ if (parsedValue.startsWith('"') && parsedValue.endsWith('"')) {
370
+ parsedValue = parsedValue.slice(1, -1);
371
+ }
372
+ params[key] = parsedValue;
296
373
  }
297
- params[key] = parsedValue;
298
374
  }
299
375
  }
300
376
  return params;
301
377
  }
302
378
  /**
303
- * 解析 Languages 段落
379
+ * 解析 Languages 段落行
304
380
  */
305
- static parseLanguagesLine(line, config) {
306
- if (!config.Languages) {
307
- config.Languages = [];
308
- }
381
+ static parseLanguagesLine(line, result) {
309
382
  const params = this.parseParams(line);
310
- if (params.Name && params.MessagesFile) {
311
- config.Languages.push({
312
- Name: params.Name,
313
- MessagesFile: params.MessagesFile,
314
- LicenseFile: params.LicenseFile,
315
- InfoBeforeFile: params.InfoBeforeFile,
316
- InfoAfterFile: params.InfoAfterFile,
317
- });
383
+ if (!params.Name || !params.MessagesFile) {
384
+ return;
318
385
  }
386
+ const lang = {
387
+ Name: params.Name,
388
+ MessagesFile: params.MessagesFile,
389
+ };
390
+ if (params.LicenseFile)
391
+ lang.LicenseFile = params.LicenseFile;
392
+ if (params.InfoBeforeFile)
393
+ lang.InfoBeforeFile = params.InfoBeforeFile;
394
+ if (params.InfoAfterFile)
395
+ lang.InfoAfterFile = params.InfoAfterFile;
396
+ if (!result.config.Languages) {
397
+ result.config.Languages = [];
398
+ }
399
+ result.config.Languages = [...result.config.Languages, lang];
319
400
  }
320
401
  /**
321
- * 解析 Tasks 段落
402
+ * 解析 Tasks 段落行
322
403
  */
323
- static parseTasksLine(line, config) {
324
- if (!config.Tasks) {
325
- config.Tasks = [];
326
- }
404
+ static parseTasksLine(line, result) {
327
405
  const params = this.parseParams(line);
328
- if (params.Name && params.Description) {
329
- config.Tasks.push({
330
- Name: params.Name,
331
- Description: params.Description,
332
- GroupDescription: params.GroupDescription,
333
- Flags: params.Flags,
334
- Components: params.Components,
335
- Check: params.Check,
336
- });
406
+ if (!params.Name || !params.Description) {
407
+ return;
337
408
  }
409
+ const task = {
410
+ Name: params.Name,
411
+ Description: params.Description,
412
+ };
413
+ if (params.GroupDescription)
414
+ task.GroupDescription = params.GroupDescription;
415
+ if (params.Flags)
416
+ task.Flags = params.Flags;
417
+ if (params.Components)
418
+ task.Components = params.Components;
419
+ if (params.Check)
420
+ task.Check = params.Check;
421
+ if (!result.config.Tasks) {
422
+ result.config.Tasks = [];
423
+ }
424
+ result.config.Tasks = [...result.config.Tasks, task];
338
425
  }
339
426
  /**
340
- * 解析 Types 段落
427
+ * 解析 Types 段落行
341
428
  */
342
- static parseTypesLine(line, config) {
343
- if (!config.Types) {
344
- config.Types = [];
345
- }
429
+ static parseTypesLine(line, result) {
346
430
  const params = this.parseParams(line);
347
- if (params.Name && params.Description) {
348
- config.Types.push({
349
- Name: params.Name,
350
- Description: params.Description,
351
- Flags: params.Flags,
352
- });
431
+ if (!params.Name || !params.Description) {
432
+ return;
353
433
  }
434
+ const type = {
435
+ Name: params.Name,
436
+ Description: params.Description,
437
+ };
438
+ if (params.Flags)
439
+ type.Flags = params.Flags;
440
+ if (!result.config.Types) {
441
+ result.config.Types = [];
442
+ }
443
+ result.config.Types = [...result.config.Types, type];
354
444
  }
355
445
  /**
356
- * 解析 Components 段落
446
+ * 解析 Components 段落行
357
447
  */
358
- static parseComponentsLine(line, config) {
359
- if (!config.Components) {
360
- config.Components = [];
361
- }
448
+ static parseComponentsLine(line, result) {
362
449
  const params = this.parseParams(line);
363
- if (params.Name && params.Description) {
364
- config.Components.push({
365
- Name: params.Name,
366
- Description: params.Description,
367
- Types: params.Types,
368
- Flags: params.Flags,
369
- ExtraDiskSpaceRequired: params.ExtraDiskSpaceRequired
370
- ? parseInt(params.ExtraDiskSpaceRequired)
371
- : undefined,
372
- });
450
+ if (!params.Name || !params.Description) {
451
+ return;
373
452
  }
453
+ const component = {
454
+ Name: params.Name,
455
+ Description: params.Description,
456
+ };
457
+ if (params.Types)
458
+ component.Types = params.Types;
459
+ if (params.Flags)
460
+ component.Flags = params.Flags;
461
+ if (params.ExtraDiskSpaceRequired) {
462
+ component.ExtraDiskSpaceRequired = parseInt(params.ExtraDiskSpaceRequired, 10);
463
+ }
464
+ if (!result.config.Components) {
465
+ result.config.Components = [];
466
+ }
467
+ result.config.Components = [...result.config.Components, component];
374
468
  }
375
469
  /**
376
- * 解析 Files 段落
470
+ * 解析 Files 段落行
377
471
  */
378
- static parseFilesLine(line, config) {
379
- if (!config.Files) {
380
- config.Files = [];
381
- }
472
+ static parseFilesLine(line, result) {
382
473
  const params = this.parseParams(line);
383
- if (params.Source && params.DestDir) {
384
- config.Files.push({
385
- Source: params.Source,
386
- DestDir: params.DestDir,
387
- DestName: params.DestName,
388
- Flags: params.Flags,
389
- Permissions: params.Permissions,
390
- StrongAssemblyName: params.StrongAssemblyName,
391
- Components: params.Components,
392
- Tasks: params.Tasks,
393
- Languages: params.Languages,
394
- Check: params.Check,
395
- BeforeInstall: params.BeforeInstall,
396
- AfterInstall: params.AfterInstall,
397
- Attribs: params.Attribs,
398
- FontInstall: params.FontInstall,
399
- });
474
+ if (!params.Source || !params.DestDir) {
475
+ return;
400
476
  }
477
+ const file = {
478
+ Source: params.Source,
479
+ DestDir: params.DestDir,
480
+ };
481
+ if (params.DestName)
482
+ file.DestName = params.DestName;
483
+ if (params.Flags)
484
+ file.Flags = params.Flags;
485
+ if (params.Permissions)
486
+ file.Permissions = params.Permissions;
487
+ if (params.StrongAssemblyName)
488
+ file.StrongAssemblyName = params.StrongAssemblyName;
489
+ if (params.Components)
490
+ file.Components = params.Components;
491
+ if (params.Tasks)
492
+ file.Tasks = params.Tasks;
493
+ if (params.Languages)
494
+ file.Languages = params.Languages;
495
+ if (params.Check)
496
+ file.Check = params.Check;
497
+ if (params.BeforeInstall)
498
+ file.BeforeInstall = params.BeforeInstall;
499
+ if (params.AfterInstall)
500
+ file.AfterInstall = params.AfterInstall;
501
+ if (params.Attribs)
502
+ file.Attribs = params.Attribs;
503
+ if (params.FontInstall)
504
+ file.FontInstall = params.FontInstall;
505
+ if (!result.config.Files) {
506
+ result.config.Files = [];
507
+ }
508
+ result.config.Files = [...result.config.Files, file];
401
509
  }
402
510
  /**
403
- * 解析 Dirs 段落
511
+ * 解析 Dirs 段落行
404
512
  */
405
- static parseDirsLine(line, config) {
406
- if (!config.Dirs) {
407
- config.Dirs = [];
408
- }
513
+ static parseDirsLine(line, result) {
409
514
  const params = this.parseParams(line);
410
- if (params.Name) {
411
- config.Dirs.push({
412
- Name: params.Name,
413
- Permissions: params.Permissions,
414
- Attribs: params.Attribs,
415
- Flags: params.Flags,
416
- Components: params.Components,
417
- Tasks: params.Tasks,
418
- Check: params.Check,
419
- });
515
+ if (!params.Name) {
516
+ return;
420
517
  }
518
+ const dir = {
519
+ Name: params.Name,
520
+ };
521
+ if (params.Permissions)
522
+ dir.Permissions = params.Permissions;
523
+ if (params.Attribs)
524
+ dir.Attribs = params.Attribs;
525
+ if (params.Flags)
526
+ dir.Flags = params.Flags;
527
+ if (params.Components)
528
+ dir.Components = params.Components;
529
+ if (params.Tasks)
530
+ dir.Tasks = params.Tasks;
531
+ if (params.Check)
532
+ dir.Check = params.Check;
533
+ if (!result.config.Dirs) {
534
+ result.config.Dirs = [];
535
+ }
536
+ result.config.Dirs = [...result.config.Dirs, dir];
421
537
  }
422
538
  /**
423
- * 解析 Icons 段落
539
+ * 解析 Icons 段落行
424
540
  */
425
- static parseIconsLine(line, config) {
426
- if (!config.Icons) {
427
- config.Icons = [];
428
- }
541
+ static parseIconsLine(line, result) {
429
542
  const params = this.parseParams(line);
430
- if (params.Name && params.Filename) {
431
- config.Icons.push({
432
- Name: params.Name,
433
- Filename: params.Filename,
434
- Parameters: params.Parameters,
435
- WorkingDir: params.WorkingDir,
436
- HotKey: params.HotKey,
437
- Comment: params.Comment,
438
- IconFilename: params.IconFilename,
439
- IconIndex: params.IconIndex ? parseInt(params.IconIndex) : undefined,
440
- AppUserModelID: params.AppUserModelID,
441
- Flags: params.Flags,
442
- Components: params.Components,
443
- Tasks: params.Tasks,
444
- Languages: params.Languages,
445
- Check: params.Check,
446
- });
543
+ if (!params.Name || !params.Filename) {
544
+ return;
447
545
  }
546
+ const icon = {
547
+ Name: params.Name,
548
+ Filename: params.Filename,
549
+ };
550
+ if (params.Parameters)
551
+ icon.Parameters = params.Parameters;
552
+ if (params.WorkingDir)
553
+ icon.WorkingDir = params.WorkingDir;
554
+ if (params.HotKey)
555
+ icon.HotKey = params.HotKey;
556
+ if (params.Comment)
557
+ icon.Comment = params.Comment;
558
+ if (params.IconFilename)
559
+ icon.IconFilename = params.IconFilename;
560
+ if (params.IconIndex)
561
+ icon.IconIndex = parseInt(params.IconIndex, 10);
562
+ if (params.AppUserModelID)
563
+ icon.AppUserModelID = params.AppUserModelID;
564
+ if (params.Flags)
565
+ icon.Flags = params.Flags;
566
+ if (params.Components)
567
+ icon.Components = params.Components;
568
+ if (params.Tasks)
569
+ icon.Tasks = params.Tasks;
570
+ if (params.Languages)
571
+ icon.Languages = params.Languages;
572
+ if (params.Check)
573
+ icon.Check = params.Check;
574
+ if (!result.config.Icons) {
575
+ result.config.Icons = [];
576
+ }
577
+ result.config.Icons = [...result.config.Icons, icon];
448
578
  }
449
579
  /**
450
- * 解析 INI 段落
580
+ * 解析 INI 段落行
451
581
  */
452
- static parseINILine(line, config) {
453
- if (!config.INI) {
454
- config.INI = [];
455
- }
582
+ static parseINILine(line, result) {
456
583
  const params = this.parseParams(line);
457
- if (params.Filename && params.Section) {
458
- config.INI.push({
459
- Filename: params.Filename,
460
- Section: params.Section,
461
- Key: params.Key,
462
- String: params.String,
463
- Flags: params.Flags,
464
- Components: params.Components,
465
- Tasks: params.Tasks,
466
- Check: params.Check,
467
- });
584
+ if (!params.Filename || !params.Section) {
585
+ return;
468
586
  }
587
+ const ini = {
588
+ Filename: params.Filename,
589
+ Section: params.Section,
590
+ };
591
+ if (params.Key)
592
+ ini.Key = params.Key;
593
+ if (params.String)
594
+ ini.String = params.String;
595
+ if (params.Flags)
596
+ ini.Flags = params.Flags;
597
+ if (params.Components)
598
+ ini.Components = params.Components;
599
+ if (params.Tasks)
600
+ ini.Tasks = params.Tasks;
601
+ if (params.Check)
602
+ ini.Check = params.Check;
603
+ if (!result.config.INI) {
604
+ result.config.INI = [];
605
+ }
606
+ result.config.INI = [...result.config.INI, ini];
469
607
  }
470
608
  /**
471
- * 解析 InstallDelete 段落
609
+ * 解析 InstallDelete 段落行
472
610
  */
473
- static parseInstallDeleteLine(line, config) {
474
- if (!config.InstallDelete) {
475
- config.InstallDelete = [];
476
- }
611
+ static parseInstallDeleteLine(line, result) {
477
612
  const params = this.parseParams(line);
478
- if (params.Type && params.Name) {
479
- config.InstallDelete.push({
480
- Type: params.Type,
481
- Name: params.Name,
482
- Components: params.Components,
483
- Tasks: params.Tasks,
484
- Check: params.Check,
485
- });
613
+ if (!params.Type || !params.Name) {
614
+ return;
486
615
  }
616
+ const item = {
617
+ Type: params.Type,
618
+ Name: params.Name,
619
+ };
620
+ if (params.Components)
621
+ item.Components = params.Components;
622
+ if (params.Tasks)
623
+ item.Tasks = params.Tasks;
624
+ if (params.Check)
625
+ item.Check = params.Check;
626
+ if (!result.config.InstallDelete) {
627
+ result.config.InstallDelete = [];
628
+ }
629
+ result.config.InstallDelete = [...result.config.InstallDelete, item];
487
630
  }
488
631
  /**
489
- * 解析 UninstallDelete 段落
632
+ * 解析 UninstallDelete 段落行
490
633
  */
491
- static parseUninstallDeleteLine(line, config) {
492
- if (!config.UninstallDelete) {
493
- config.UninstallDelete = [];
494
- }
634
+ static parseUninstallDeleteLine(line, result) {
495
635
  const params = this.parseParams(line);
496
- if (params.Type && params.Name) {
497
- config.UninstallDelete.push({
498
- Type: params.Type,
499
- Name: params.Name,
500
- Components: params.Components,
501
- Tasks: params.Tasks,
502
- Check: params.Check,
503
- });
636
+ if (!params.Type || !params.Name) {
637
+ return;
504
638
  }
639
+ const item = {
640
+ Type: params.Type,
641
+ Name: params.Name,
642
+ };
643
+ if (params.Components)
644
+ item.Components = params.Components;
645
+ if (params.Tasks)
646
+ item.Tasks = params.Tasks;
647
+ if (params.Check)
648
+ item.Check = params.Check;
649
+ if (!result.config.UninstallDelete) {
650
+ result.config.UninstallDelete = [];
651
+ }
652
+ result.config.UninstallDelete = [...result.config.UninstallDelete, item];
505
653
  }
506
654
  /**
507
- * 解析 Registry 段落
655
+ * 解析 Registry 段落行
508
656
  */
509
- static parseRegistryLine(line, config) {
510
- if (!config.Registry) {
511
- config.Registry = [];
512
- }
657
+ static parseRegistryLine(line, result) {
513
658
  const params = this.parseParams(line);
514
- if (params.Root && params.Subkey) {
515
- let valueData = params.ValueData;
516
- // 尝试转换为数字
517
- if (valueData && /^\d+$/.test(valueData)) {
518
- valueData = parseInt(valueData, 10);
519
- }
520
- config.Registry.push({
521
- Root: params.Root,
522
- Subkey: params.Subkey,
523
- ValueType: params.ValueType,
524
- ValueName: params.ValueName,
525
- ValueData: valueData,
526
- Permissions: params.Permissions,
527
- Flags: params.Flags,
528
- Components: params.Components,
529
- Tasks: params.Tasks,
530
- Check: params.Check,
531
- });
659
+ if (!params.Root || !params.Subkey) {
660
+ return;
532
661
  }
662
+ let valueData = params.ValueData;
663
+ if (valueData && /^\d+$/.test(valueData)) {
664
+ valueData = parseInt(valueData, 10);
665
+ }
666
+ const reg = {
667
+ Root: params.Root,
668
+ Subkey: params.Subkey,
669
+ };
670
+ if (params.ValueType)
671
+ reg.ValueType = params.ValueType;
672
+ if (params.ValueName)
673
+ reg.ValueName = params.ValueName;
674
+ if (valueData !== undefined)
675
+ reg.ValueData = valueData;
676
+ if (params.Permissions)
677
+ reg.Permissions = params.Permissions;
678
+ if (params.Flags)
679
+ reg.Flags = params.Flags;
680
+ if (params.Components)
681
+ reg.Components = params.Components;
682
+ if (params.Tasks)
683
+ reg.Tasks = params.Tasks;
684
+ if (params.Check)
685
+ reg.Check = params.Check;
686
+ if (!result.config.Registry) {
687
+ result.config.Registry = [];
688
+ }
689
+ result.config.Registry = [...result.config.Registry, reg];
533
690
  }
534
691
  /**
535
- * 解析 Run 段落
692
+ * 解析 Run 段落行
536
693
  */
537
- static parseRunLine(line, config) {
538
- if (!config.Run) {
539
- config.Run = [];
540
- }
694
+ static parseRunLine(line, result) {
541
695
  const params = this.parseParams(line);
542
- if (params.Filename) {
543
- config.Run.push({
544
- Filename: params.Filename,
545
- Parameters: params.Parameters,
546
- WorkingDir: params.WorkingDir,
547
- StatusMsg: params.StatusMsg,
548
- Description: params.Description,
549
- Flags: params.Flags,
550
- RunOnceId: params.RunOnceId,
551
- Verb: params.Verb,
552
- Components: params.Components,
553
- Tasks: params.Tasks,
554
- Languages: params.Languages,
555
- Check: params.Check,
556
- });
696
+ if (!params.Filename) {
697
+ return;
557
698
  }
699
+ const run = {
700
+ Filename: params.Filename,
701
+ };
702
+ if (params.Parameters)
703
+ run.Parameters = params.Parameters;
704
+ if (params.WorkingDir)
705
+ run.WorkingDir = params.WorkingDir;
706
+ if (params.StatusMsg)
707
+ run.StatusMsg = params.StatusMsg;
708
+ if (params.Description)
709
+ run.Description = params.Description;
710
+ if (params.Flags)
711
+ run.Flags = params.Flags;
712
+ if (params.RunOnceId)
713
+ run.RunOnceId = params.RunOnceId;
714
+ if (params.Verb)
715
+ run.Verb = params.Verb;
716
+ if (params.Components)
717
+ run.Components = params.Components;
718
+ if (params.Tasks)
719
+ run.Tasks = params.Tasks;
720
+ if (params.Languages)
721
+ run.Languages = params.Languages;
722
+ if (params.Check)
723
+ run.Check = params.Check;
724
+ if (!result.config.Run) {
725
+ result.config.Run = [];
726
+ }
727
+ result.config.Run = [...result.config.Run, run];
558
728
  }
559
729
  /**
560
- * 解析 UninstallRun 段落
730
+ * 解析 UninstallRun 段落行
561
731
  */
562
- static parseUninstallRunLine(line, config) {
563
- if (!config.UninstallRun) {
564
- config.UninstallRun = [];
565
- }
732
+ static parseUninstallRunLine(line, result) {
566
733
  const params = this.parseParams(line);
567
- if (params.Filename) {
568
- config.UninstallRun.push({
569
- Filename: params.Filename,
570
- Parameters: params.Parameters,
571
- WorkingDir: params.WorkingDir,
572
- StatusMsg: params.StatusMsg,
573
- Description: params.Description,
574
- Flags: params.Flags,
575
- RunOnceId: params.RunOnceId,
576
- Components: params.Components,
577
- Tasks: params.Tasks,
578
- Check: params.Check,
579
- });
734
+ if (!params.Filename) {
735
+ return;
580
736
  }
737
+ const run = {
738
+ Filename: params.Filename,
739
+ };
740
+ if (params.Parameters)
741
+ run.Parameters = params.Parameters;
742
+ if (params.WorkingDir)
743
+ run.WorkingDir = params.WorkingDir;
744
+ if (params.StatusMsg)
745
+ run.StatusMsg = params.StatusMsg;
746
+ if (params.Description)
747
+ run.Description = params.Description;
748
+ if (params.Flags)
749
+ run.Flags = params.Flags;
750
+ if (params.RunOnceId)
751
+ run.RunOnceId = params.RunOnceId;
752
+ if (params.Components)
753
+ run.Components = params.Components;
754
+ if (params.Tasks)
755
+ run.Tasks = params.Tasks;
756
+ if (params.Check)
757
+ run.Check = params.Check;
758
+ if (!result.config.UninstallRun) {
759
+ result.config.UninstallRun = [];
760
+ }
761
+ result.config.UninstallRun = [...result.config.UninstallRun, run];
581
762
  }
582
763
  /**
583
- * 解析 Messages 段落
764
+ * 解析 Messages 段落行
584
765
  */
585
- static parseMessagesLine(line, config) {
766
+ static parseMessagesLine(line, result) {
586
767
  const match = line.match(/^(\w+)\s*=\s*(.+)$/);
587
- if (!match)
768
+ if (!match) {
588
769
  return;
770
+ }
589
771
  const [, key, value] = match;
590
- if (!config.Messages) {
591
- config.Messages = {};
772
+ if (!key || !value) {
773
+ return;
592
774
  }
593
- config.Messages[key] = value;
775
+ if (!result.config.Messages) {
776
+ result.config.Messages = {};
777
+ }
778
+ result.config.Messages = { ...result.config.Messages, [key]: value };
594
779
  }
595
780
  /**
596
- * 解析 CustomMessages 段落
781
+ * 解析 CustomMessages 段落行
597
782
  */
598
- static parseCustomMessagesLine(line, config) {
783
+ static parseCustomMessagesLine(line, result) {
599
784
  const match = line.match(/^(\w+)\s*=\s*(.+)$/);
600
- if (!match)
785
+ if (!match) {
601
786
  return;
787
+ }
602
788
  const [, key, value] = match;
603
- if (!config.CustomMessages) {
604
- config.CustomMessages = {};
789
+ if (!key || !value) {
790
+ return;
791
+ }
792
+ if (!result.config.CustomMessages) {
793
+ result.config.CustomMessages = {};
605
794
  }
606
- config.CustomMessages[key] = value;
795
+ result.config.CustomMessages = { ...result.config.CustomMessages, [key]: value };
607
796
  }
608
797
  }
609
798
  exports.InnoScriptParser = InnoScriptParser;
799
+ //# sourceMappingURL=parser.js.map