lycheedev 1.0.6 → 1.1.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/bin/lycheedev.js CHANGED
@@ -2,7 +2,10 @@
2
2
  /** lycheedev command line entry. */
3
3
 
4
4
  import { readFileSync } from 'node:fs';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
5
7
  import path from 'node:path';
8
+ import { randomBytes } from 'node:crypto';
6
9
 
7
10
  import { runDoctor } from '../src/doctor.js';
8
11
  import { runInstall } from '../src/install.js';
@@ -13,6 +16,9 @@ import {
13
16
  findInstances,
14
17
  findSavedVariablesCandidates,
15
18
  formatInstance,
19
+ identityKey,
20
+ identityLabel,
21
+ matchIdentity,
16
22
  matchPinned,
17
23
  resolveInstance,
18
24
  scanClients,
@@ -29,7 +35,9 @@ commands
29
35
  doctor report what is installed and what is missing
30
36
  clients list every detected build and its addon state
31
37
  instances list running game clients (build, pid, window)
38
+ instances --identify also read each window's character and build marker
32
39
  use [index] pin one running client as the default target
40
+ use --character <n> pin the window that reports character <n>
33
41
  use --clear drop the pin
34
42
  send <text> type one slash command into the running game
35
43
  capture poll the game window and decode the completion notice
@@ -44,8 +52,10 @@ commands
44
52
 
45
53
  options
46
54
  --wow-root <path> folder that contains _retail_/_classic_/_classic_titan_
47
- --client <id> retail | classic | titan (default: the only configured one)
55
+ --client <id> retail | classic | titan | forever (default: the configured one)
48
56
  --instance <index> which running client to target when several are open
57
+ --character <name> target the window reporting that character (Name or Name-Realm)
58
+ --identify also read each window's character marker (instances, use)
49
59
  --hwnd <handle> target one window directly, skipping instance lookup
50
60
  --pid <pid> expected process id for the target window
51
61
  --python <bin> python interpreter to use
@@ -56,10 +66,20 @@ options
56
66
  -v, --version show the version
57
67
 
58
68
  Every non-retail client runs as WowClassic.exe, so a running client is matched
59
- by its install path, not its process name. With several clients open, run
60
- "lycheedev instances" then "lycheedev use <index>" to pin one as the target;
61
- the pin stores the build, so it survives a restart even though the pid and
62
- window handle change. Pass --instance <index> to override it for one command.
69
+ by its install path, not its process name. A folder is only a location: the CLI
70
+ also reads each client's own .flavor.info product code and version.txt build, so
71
+ a reused test folder (such as _classic_beta_ carrying WoW: Forever) is still
72
+ identified correctly. With several clients open, run "lycheedev instances" then
73
+ "lycheedev use <index>" to pin one as the target; the pin stores the build, so it
74
+ survives a restart even though the pid and window handle change. Pass
75
+ --instance <index> to override it for one command.
76
+
77
+ When several windows share one build, they are told apart by the character each
78
+ window reports: run "/dev auto identify" in each game window, then
79
+ "lycheedev instances --identify" to read them, and pin by name with
80
+ "lycheedev use --character <name>". Windows that report the same character, or
81
+ that show no marker, remain ambiguous and the CLI asks for one window to be
82
+ closed rather than risking a command in the wrong game.
63
83
 
64
84
  The automation subcommands are thin wrappers over the bundled python helper, so
65
85
  the same arguments it accepts are forwarded unchanged.`;
@@ -142,10 +162,16 @@ function runClients(flags) {
142
162
  console.log(root);
143
163
  for (const client of scanClients(root)) {
144
164
  const version = client.version ? `v${client.version}` : 'unknown version';
165
+ // The product is the client's own identity; the folder is only where it
166
+ // lives, and one folder can serve different products over time.
167
+ const product = client.folderProduct && client.folderProduct !== client.product
168
+ ? `[${client.folderProduct}] `
169
+ : '';
145
170
  const state = !client.toc
146
171
  ? 'not served by the addon'
147
172
  : (client.installed ? 'addon installed' : 'addon missing');
148
- console.log(` ${client.id.padEnd(12)} ${client.folder.padEnd(18)} ${version.padEnd(18)} ${state}`);
173
+ console.log(` ${client.id.padEnd(12)} ${client.folder.padEnd(18)} `
174
+ + `${(product + version).padEnd(18)} ${state}`);
149
175
  }
150
176
  return 0;
151
177
  }
@@ -153,11 +179,40 @@ function runClients(flags) {
153
179
  /** `lycheedev instances`: which game clients are running right now. */
154
180
  function runInstances(flags) {
155
181
  const config = loadConfig();
156
- const instances = findInstances({ pythonBin: flags.python || null });
182
+ let instances = findInstances({ pythonBin: flags.python || null });
157
183
  if (instances.length === 0) {
158
184
  console.log('no World of Warcraft instance is running');
159
185
  return 0;
160
186
  }
187
+
188
+ // `--identify` asks each window to report the character and build it holds.
189
+ // Capture reads the window surface directly, so no window needs the
190
+ // foreground and nothing is typed into the game.
191
+ let identifyNote = null;
192
+ if (flags.identify) {
193
+ const supported = instances.filter((item) => item.supported);
194
+ if (supported.length === 0) {
195
+ identifyNote = 'no served build is running, so there is nothing to identify';
196
+ } else {
197
+ const probed = probeIdentities(supported, flags);
198
+ if (probed.error) {
199
+ identifyNote = probed.error;
200
+ } else {
201
+ const byHwnd = new Map(probed.list.map((entry) => [String(entry.hwnd), entry]));
202
+ instances = instances.map((instance) => {
203
+ const entry = byHwnd.get(String(instance.hwnd));
204
+ if (!entry || !entry.identity) return instance;
205
+ return { ...instance, identity: entry.identity };
206
+ });
207
+ const unidentified = probed.list.filter((entry) => !entry.identity);
208
+ if (unidentified.length) {
209
+ identifyNote = `${unidentified.length} window(s) show no identity marker; `
210
+ + 'run `/dev auto identify` in each game window you care about, then retry';
211
+ }
212
+ }
213
+ }
214
+ }
215
+
161
216
  const pinned = matchPinned(instances, config.pinnedInstance);
162
217
  console.log('running instances:');
163
218
  instances.forEach((instance, index) => {
@@ -174,21 +229,69 @@ function runInstances(flags) {
174
229
  if (supported.length === 0) {
175
230
  console.log('none of these builds are served by the addon');
176
231
  } else if (!pinned && supported.length > 1) {
177
- console.log('several clients are running: `lycheedev use <index>` pins one, '
178
- + 'or pass --instance <index> per command');
232
+ const shape = describeAmbiguity(instances);
233
+ if (shape.sameBuildCollision) {
234
+ // Do not suggest `use <index>` here: pinning is refused for windows that
235
+ // cannot be told apart, so pointing at it would send the user in a circle.
236
+ console.log('several clients are running and cannot be told apart: run '
237
+ + '`/dev auto identify` in each game window, then `lycheedev use --character <name>`');
238
+ } else {
239
+ console.log('several clients are running: `lycheedev use <index>` pins one, '
240
+ + 'or pass --instance <index> per command');
241
+ }
179
242
  } else if (!pinned) {
180
243
  console.log('commands target this instance automatically');
181
244
  }
245
+ if (identifyNote) console.log(identifyNote);
182
246
  return 0;
183
247
  }
184
248
 
249
+ /**
250
+ * Ask the Python helper to read the identity marker from each window.
251
+ *
252
+ * The instance list is handed over as a file rather than arguments, because
253
+ * every field has to survive the trip and a command line is a fragile place to
254
+ * put it. The name is unpredictable and the file is created exclusively, so a
255
+ * pre-existing file at that path cannot be followed or silently overwritten.
256
+ */
257
+ function probeIdentities(supported, flags) {
258
+ const windowsFile = path.join(os.tmpdir(),
259
+ `lycheedev-windows-${process.pid}-${randomBytes(8).toString('hex')}.json`);
260
+ try {
261
+ fs.writeFileSync(windowsFile, JSON.stringify(supported), { encoding: 'utf8', flag: 'wx' });
262
+ const args = ['identify', '--windows-json', windowsFile];
263
+ if (flags.timeout) args.push('--timeout', String(flags.timeout));
264
+ const result = runAutomation(args, {
265
+ pythonBin: flags.python || null,
266
+ inherit: false,
267
+ });
268
+ if (!result.ok) {
269
+ return { error: `could not read identity markers: ${result.stderr || 'helper failed'}` };
270
+ }
271
+ return { list: JSON.parse(result.stdout || '[]') };
272
+ } catch (error) {
273
+ return { error: `could not read identity markers: ${error.message}` };
274
+ } finally {
275
+ try {
276
+ fs.unlinkSync(windowsFile);
277
+ } catch {
278
+ // A leftover temp file is harmless.
279
+ }
280
+ }
281
+ }
282
+
185
283
  /**
186
284
  * Resolve the live game window a command should type into.
187
285
  *
188
- * Precedence: an explicit `--hwnd`/`--pid`, then `--instance <index>`, then the
189
- * saved pin, then `--client`, and finally the only running instance when there
190
- * is exactly one. `WowClassic.exe` looks identical for every classic build, so
191
- * an ambiguous choice fails loudly instead of typing into the wrong game.
286
+ * Precedence: an explicit `--hwnd`/`--pid`, then `--instance <index>`, then
287
+ * `--character <name>`, then the saved pin, then `--client`, and finally the only
288
+ * running instance when there is exactly one. `WowClassic.exe` looks identical
289
+ * for every classic build, so an ambiguous choice fails loudly instead of typing
290
+ * into the wrong game.
291
+ *
292
+ * Windows of one build are distinguishable when each reports a different
293
+ * character; only windows that report the same character (or no marker at all)
294
+ * are genuinely ambiguous, and those still fail loudly.
192
295
  */
193
296
  function resolveRuntime(flags) {
194
297
  if (flags.hwnd || flags.pid) {
@@ -207,6 +310,14 @@ function resolveRuntime(flags) {
207
310
  return toTarget(chosen);
208
311
  }
209
312
 
313
+ if (flags.character) {
314
+ // A named character is only findable if the window showed its marker, so
315
+ // probe first; this is read-only capture and types nothing.
316
+ const named = resolveByCharacter(instances, flags.character, flags);
317
+ if (named.error) return { error: true };
318
+ return toTarget(named.instance);
319
+ }
320
+
210
321
  if (!flags.client) {
211
322
  const config = loadConfig();
212
323
  const pinned = matchPinned(instances, config.pinnedInstance);
@@ -222,14 +333,29 @@ function resolveRuntime(flags) {
222
333
  const resolved = resolveInstance(instances, { clientId: flags.client || null, index: null });
223
334
  if (resolved.error) {
224
335
  const shape = describeAmbiguity(instances);
225
- // Several windows of one build: no flag can pick the right one reliably, so
226
- // ask for a single window rather than inviting a wrong guess.
227
336
  if (shape.sameBuildCollision) {
228
- for (const [flavorId, list] of shape.duplicates) {
229
- const label = list[0].flavorLabel || flavorId;
230
- console.error(`error: ${list.length} ${label} clients are running and cannot be told apart`);
231
- console.error(` close all but one, or close these pids: ${list.map((i) => i.pid).join(', ')}`);
337
+ // Same build and no way to separate the windows: no flag can pick the right
338
+ // one reliably, so ask for a single window rather than inviting a wrong guess.
339
+ for (const entry of shape.collisions) {
340
+ for (const group of entry.sameCharacter) {
341
+ const label = group[0].flavorLabel || entry.flavorId;
342
+ console.error(`error: ${group.length} ${label} clients report the same character `
343
+ + `and cannot be told apart`);
344
+ console.error(` close all but one, or close these pids: `
345
+ + group.map((i) => i.pid).join(', '));
346
+ }
347
+ }
348
+ if (!shape.sameBuildNamed) {
349
+ console.error(' run `/dev auto identify` in each game window, then retry '
350
+ + 'with --identify');
232
351
  }
352
+ } else if (supported.length > 1) {
353
+ // Several windows of one build, and the caller filtered to that build. They
354
+ // may well be separable by character, so say how rather than just failing.
355
+ console.error(`error: ${resolved.error}`);
356
+ console.error(' if each window shows a different character, run '
357
+ + '`/dev auto identify` in each, then pass --character <name>; '
358
+ + 'otherwise pass --instance <index>');
233
359
  } else {
234
360
  console.error(`error: ${resolved.error}`);
235
361
  }
@@ -244,6 +370,43 @@ function resolveRuntime(flags) {
244
370
  return toTarget(resolved.instance);
245
371
  }
246
372
 
373
+ /**
374
+ * Find the window reporting a named character, probing the markers first.
375
+ *
376
+ * Names only exist inside the marker, so read it when the caller has not already
377
+ * supplied it. Returns `{ instance }` or `{ error: true }` after explaining why.
378
+ */
379
+ function resolveByCharacter(instances, query, flags) {
380
+ const supported = instances.filter((item) => item.supported);
381
+ if (supported.length === 0) {
382
+ console.error('error: no served build is running');
383
+ return { error: true };
384
+ }
385
+
386
+ let probed = supported;
387
+ if (!supported.some((item) => item.identity)) {
388
+ const result = probeIdentities(supported, flags);
389
+ if (result.error) {
390
+ console.error('error: could not read identity markers; run '
391
+ + '`lycheedev instances --identify` after `/dev auto identify` in each game window');
392
+ return { error: true };
393
+ }
394
+ const byHwnd = new Map(result.list.map((entry) => [String(entry.hwnd), entry]));
395
+ probed = supported.map((instance) => {
396
+ const entry = byHwnd.get(String(instance.hwnd));
397
+ return entry && entry.identity ? { ...instance, identity: entry.identity } : instance;
398
+ });
399
+ }
400
+
401
+ const matched = matchIdentity(probed, query);
402
+ if (matched.error) {
403
+ console.error(`error: ${matched.error}`);
404
+ (matched.candidates || probed).forEach((item, index) => console.log(formatInstance(item, index)));
405
+ return { error: true };
406
+ }
407
+ return { instance: matched.instance };
408
+ }
409
+
247
410
  function toTarget(instance) {
248
411
  return {
249
412
  hwnd: instance.hwnd ? `0x${instance.hwnd.toString(16)}` : null,
@@ -253,15 +416,18 @@ function toTarget(instance) {
253
416
  }
254
417
 
255
418
  /**
256
- * `lycheedev use [index]`: keep one running client as the default target.
419
+ * `lycheedev use [index|--character <name>]`: keep one running client as the
420
+ * default target.
257
421
  *
258
- * Stores only the build and the instance ordinal, so the pin survives a
259
- * restart even though the pid and window handle do not.
422
+ * The pin stores the build, the instance ordinal and — when the window showed
423
+ * its identity marker — the character. The character is the durable half: pids
424
+ * and window handles change every launch, and an ordinal shifts as soon as the
425
+ * windows are opened in a different order.
260
426
  */
261
427
  function runUse(flags, rest) {
262
- const instances = findInstances({ pythonBin: flags.python || null });
263
- const shape = describeAmbiguity(instances);
264
- const supported = shape.supported;
428
+ let instances = findInstances({ pythonBin: flags.python || null });
429
+ let shape = describeAmbiguity(instances);
430
+ let supported = shape.supported;
265
431
 
266
432
  if (flags.clear) {
267
433
  updateConfig({ pinnedInstance: null });
@@ -276,16 +442,55 @@ function runUse(flags, rest) {
276
442
  return 1;
277
443
  }
278
444
 
279
- // Several windows of one build cannot be told apart from outside the game, so
280
- // pinning one of them would only look precise. Ask for a single window instead.
445
+ // Probing is read-only capture that types nothing, so do it whenever it could
446
+ // resolve an ambiguity. An explicit index or character already is the decision,
447
+ // so probing then would only add seconds of waiting for no new information.
448
+ const decided = Boolean(flags.character) || rest.length > 0 || flags.instance !== undefined;
449
+ const wantsIdentity = Boolean(flags.character) || Boolean(flags.identify)
450
+ || (shape.sameBuildCollision && !decided);
451
+ if (wantsIdentity) {
452
+ const probed = probeIdentities(supported, flags);
453
+ if (probed.error) {
454
+ if (flags.character) {
455
+ console.error(`error: ${probed.error}`);
456
+ return 1;
457
+ }
458
+ // Without an explicit name request the pin can still be taken by ordinal.
459
+ } else {
460
+ const byHwnd = new Map(probed.list.map((entry) => [String(entry.hwnd), entry]));
461
+ instances = instances.map((instance) => {
462
+ const entry = byHwnd.get(String(instance.hwnd));
463
+ return entry && entry.identity ? { ...instance, identity: entry.identity } : instance;
464
+ });
465
+ supported = instances.filter((item) => item.supported);
466
+ shape = describeAmbiguity(instances);
467
+ }
468
+ }
469
+
470
+ // Pinning by name is the recommended path when several windows share a build.
471
+ if (flags.character) {
472
+ const matched = matchIdentity(supported, flags.character);
473
+ if (matched.error) {
474
+ console.error(`error: ${matched.error}`);
475
+ (matched.candidates || supported).forEach((item, index) => console.log(formatInstance(item, index)));
476
+ return 1;
477
+ }
478
+ return savePin(matched.instance);
479
+ }
480
+
481
+ // Only windows that report the same character (or no marker at all) are
482
+ // genuinely indistinguishable; those still get asked for a single window.
281
483
  if (shape.sameBuildCollision) {
282
- for (const [flavorId, list] of shape.duplicates) {
283
- const label = list[0].flavorLabel || flavorId;
284
- console.error(`error: ${list.length} ${label} clients are running and cannot be told apart`);
285
- console.error(` close all but one, or close these pids: ${list.map((i) => i.pid).join(', ')}`);
484
+ for (const entry of shape.collisions) {
485
+ for (const group of entry.sameCharacter) {
486
+ const label = group[0].flavorLabel || entry.flavorId;
487
+ console.error(`error: ${group.length} ${label} clients cannot be told apart`);
488
+ console.error(` close all but one, or close these pids: `
489
+ + group.map((i) => i.pid).join(', '));
490
+ }
286
491
  }
287
- console.error(' nothing observable from outside the game identifies which character');
288
- console.error(' is behind which window, so pinning one would risk typing into the wrong game');
492
+ console.error(' or run `/dev auto identify` in each game window and then '
493
+ + '`lycheedev use --character <name>`');
289
494
  supported.forEach((item, index) => console.log(formatInstance(item, index)));
290
495
  return 1;
291
496
  }
@@ -316,10 +521,22 @@ function runUse(flags, rest) {
316
521
  ordinal = 0;
317
522
  }
318
523
 
319
- updateConfig({ pinnedInstance: { flavor: chosen.flavorId, ordinal } });
524
+ return savePin(chosen, ordinal);
525
+ }
526
+
527
+ /** Persist a pin, preferring the character when the window reported one. */
528
+ function savePin(chosen, ordinal = 0) {
529
+ const pin = { flavor: chosen.flavorId, ordinal };
530
+ // The character is the durable half of the pin; the ordinal stays as a
531
+ // fallback for a build whose windows never showed a marker.
532
+ const character = identityKey(chosen);
533
+ if (character) pin.character = character;
534
+
535
+ updateConfig({ pinnedInstance: pin });
320
536
  const label = chosen.flavorLabel || chosen.flavorFolder;
321
- console.log(`pinned ${label} (pid ${chosen.pid})`);
322
- console.log('commands now target it; pass --instance <index> to override');
537
+ const name = identityLabel(chosen);
538
+ console.log(`pinned ${label}${name ? ` (${name})` : ''} (pid ${chosen.pid})`);
539
+ console.log('commands now target it; pass --instance <index> or --character <name> to override');
323
540
  return 0;
324
541
  }
325
542
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lycheedev",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "description": "lycheedev: install the World of Warcraft inspection addon, its in-game automation tooling, and drive it from the command line.",
5
5
  "keywords": [
6
6
  "wow",
package/src/addon.js CHANGED
@@ -31,7 +31,7 @@ export function installedVersion(addonsDir, toc = null) {
31
31
  const catalogs = toc
32
32
  ? [toc]
33
33
  : [`${addonFolderName}_Mainline.toc`, `${addonFolderName}_Mists.toc`,
34
- `${addonFolderName}_Wrath.toc`];
34
+ `${addonFolderName}_Wrath.toc`, `${addonFolderName}_Forever.toc`];
35
35
  for (const name of catalogs) {
36
36
  const file = path.join(target, name);
37
37
  if (!exists(file)) continue;
package/src/doctor.js CHANGED
@@ -93,7 +93,8 @@ export function runDoctor({ flags }) {
93
93
  }
94
94
  }
95
95
 
96
- // Which clients are running decides what `send`/`run` can target.
96
+ // Which clients are running decides what `send`/`run` can target. Reuse the
97
+ // interpreter already resolved above rather than probing for one again.
97
98
  const instances = findInstances({ pythonBin: python ? python.bin : null });
98
99
  const supportedRunning = instances.filter((item) => item.supported);
99
100
  if (instances.length === 0) {
package/src/install.js CHANGED
@@ -7,7 +7,7 @@ import { loadConfig, setClient, updateConfig } from './config.js';
7
7
  import { exists } from './paths.js';
8
8
  import { depsInstalled, findPython, installDeps } from './python.js';
9
9
  import { installSkill } from './skill.js';
10
- import { detectWowRoots, findSavedVariablesCandidates, scanClients } from './wow.js';
10
+ import { detectWowRoots, findSavedVariablesCandidates, knownFolders, scanClients } from './wow.js';
11
11
 
12
12
  function step(label, fn) {
13
13
  process.stdout.write(`\n` + `${label}\n`);
@@ -30,8 +30,11 @@ export function resolveWowRoot({ wowRoot, config }) {
30
30
  const clients = scanClients(resolved);
31
31
  if (clients.length === 0) {
32
32
  return {
33
- error: `${resolved} has no _retail_/_classic_/_classic_arena_ folder; `
34
- + 'point --wow-root at the folder that contains them',
33
+ // List what detection actually accepts, generated from the same table,
34
+ // so the message cannot drift from the behavior it describes.
35
+ error: `${resolved} has no known client folder:\n `
36
+ + knownFolders().join('\n ')
37
+ + '\npoint --wow-root at the folder that contains them',
35
38
  };
36
39
  }
37
40
  return { root: resolved, clients };
@@ -79,7 +82,12 @@ export function runInstall({ flags }) {
79
82
 
80
83
  const nextConfig = { ...config, wowRoot: resolved.root, pythonBin: flags.python || config.pythonBin };
81
84
  const addonResults = [];
82
- let defaultClient = config.defaultClient || null;
85
+ // Prefer retail as the default target so a routine command stays predictable;
86
+ // otherwise take the first supported client that was actually updated.
87
+ const preferredDefault = resolved.clients.some((client) => client.toc && client.id === 'retail')
88
+ ? 'retail'
89
+ : null;
90
+ let defaultClient = config.defaultClient || preferredDefault || null;
83
91
 
84
92
  for (const client of resolved.clients) {
85
93
  // A build without a catalog is reported, not silently dropped: the folder
@@ -1,11 +1,15 @@
1
1
  """List running World of Warcraft instances as JSON.
2
2
 
3
3
  The executable name cannot identify a build: Blizzard ships every non-retail
4
- client as ``WowClassic.exe``. The install path can, because each build lives in
5
- a ``_flavor_`` directory. Visible top-level window handles are attached so the
6
- caller can tell same-build instances apart.
7
-
8
- Read-only: this opens no process, only enumerates windows and process metadata.
4
+ client as ``WowClassic.exe``. The install path narrows it to a ``_flavor_``
5
+ folder, but a folder is a location rather than an identity - the game reuses a
6
+ test folder for whatever is on the test track, so ``_classic_beta_`` currently
7
+ carries WoW: Forever (1.60.x) on that track. The folder's own ``.flavor.info``
8
+ product code and ``version.txt`` build are reported alongside the window handle
9
+ so the caller can identify the client from the client itself.
10
+
11
+ Read-only: this opens no process, only enumerates windows and reads process
12
+ metadata plus two small per-folder files.
9
13
  """
10
14
 
11
15
  from __future__ import annotations
@@ -13,6 +17,7 @@ from __future__ import annotations
13
17
  import ctypes
14
18
  import json
15
19
  import os
20
+ import re
16
21
  import sys
17
22
  from ctypes import wintypes
18
23
 
@@ -22,6 +27,8 @@ kernel32 = ctypes.windll.kernel32
22
27
  PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
23
28
  ERROR_INSUFFICIENT_BUFFER = 122
24
29
 
30
+ _FLAVOR_PRODUCT = re.compile(rb"\b(wow[a-z0-9_]*)\b", re.IGNORECASE)
31
+
25
32
  user32.EnumWindows.restype = wintypes.BOOL
26
33
  user32.EnumWindows.argtypes = [ctypes.c_void_p, wintypes.LPARAM]
27
34
  user32.IsWindowVisible.restype = wintypes.BOOL
@@ -44,6 +51,10 @@ FLAVOR_LABELS = {
44
51
  "_retail_": ("retail", "Retail"),
45
52
  "_classic_": ("classic", "Classic"),
46
53
  "_classic_titan_": ("titan", "Classic Titan"),
54
+ # Folder default only: this folder also carries WoW: Forever on the test
55
+ # track, which the caller resolves from the folder's own product code.
56
+ "_classic_beta_": ("classicBeta", "Classic Beta"),
57
+ "_forever_": ("forever", "Forever"),
47
58
  "_classic_era_": ("classicEra", "Classic Era"),
48
59
  "_anniversary_": ("anniversary", "Anniversary"),
49
60
  "_beta_": ("beta", "Beta"),
@@ -66,6 +77,31 @@ def process_image(pid: int) -> str | None:
66
77
  kernel32.CloseHandle(handle)
67
78
 
68
79
 
80
+ def _read_small_text(path: str, limit: int = 512) -> str | None:
81
+ try:
82
+ with open(path, "rb") as handle:
83
+ return handle.read(limit).decode("utf-8", "replace").strip() or None
84
+ except OSError:
85
+ return None
86
+
87
+
88
+ def folder_product(version_dir: str) -> str | None:
89
+ """The folder's declared product code, e.g. ``wow_classic_titan``."""
90
+ for name in (".flavor.info", "flavor.info"):
91
+ text = _read_small_text(os.path.join(version_dir, name))
92
+ if not text:
93
+ continue
94
+ match = _FLAVOR_PRODUCT.search(text.encode("utf-8", "replace"))
95
+ if match:
96
+ return match.group(1).decode("ascii", "replace").lower()
97
+ return None
98
+
99
+
100
+ def folder_version(version_dir: str) -> str | None:
101
+ """The folder's build, e.g. ``1.60.1.69893`` from ``version.txt``."""
102
+ return _read_small_text(os.path.join(version_dir, "version.txt"))
103
+
104
+
69
105
  def visible_windows() -> dict[int, dict]:
70
106
  found: dict[int, dict] = {}
71
107
 
@@ -99,7 +135,14 @@ def main() -> int:
99
135
  continue
100
136
  parts = image.replace("/", os.sep).split(os.sep)
101
137
  folder = next((part for part in parts if part.startswith("_") and part.endswith("_")), None)
138
+ # Folder defaults only. The caller re-resolves the flavor from `product`
139
+ # and `version`, because a folder name is a location rather than an
140
+ # identity; keeping the product rule in one place avoids two mappings
141
+ # that can disagree about a reused test folder.
102
142
  flavor_id, label = FLAVOR_LABELS.get(folder, (None, None))
143
+ version_dir = os.path.dirname(image)
144
+ product = folder_product(version_dir)
145
+ version = folder_version(version_dir)
103
146
  instances.append({
104
147
  "pid": pid,
105
148
  "exe": os.path.basename(image),
@@ -107,6 +150,8 @@ def main() -> int:
107
150
  "flavorFolder": folder,
108
151
  "flavorId": flavor_id,
109
152
  "flavorLabel": label,
153
+ "product": product,
154
+ "version": version,
110
155
  "hwnd": windows[pid]["hwnd"],
111
156
  "title": windows[pid]["title"],
112
157
  })