@@ -4,31 +4,12 @@ import { runElevated } from './utils';
44const REG = 'reg.exe' ;
55const ENTRY_PATTERN = / ^ \s + ( \w + ) \s + ( [ A - Z _ ] + ) \s * ( .* ) / ;
66
7- export interface RegEntry {
8- /** Full path to the registry branch, for example
9- * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DirectDrawEx */
10- root : string ;
11- /** The registry key name */
12- key : string ;
13- /** One of possible registry value types, for example REG_DWORD or REG_SZ */
14- type : string ;
15- /** The actual value. Could be empty */
16- value : string ;
17- }
18-
19- function parseRegEntries ( root : string | undefined , block : string [ ] ) : RegEntry [ ] {
20- if ( _ . isEmpty ( block ) || ! root || _ . isEmpty ( root ) ) {
21- return [ ] ;
22- }
23- return block . reduce ( ( acc : RegEntry [ ] , line : string ) => {
24- const match = ENTRY_PATTERN . exec ( line ) ;
25- if ( match ) {
26- acc . push ( { root, key : match [ 1 ] , type : match [ 2 ] , value : match [ 3 ] || '' } ) ;
27- }
28- return acc ;
29- } , [ ] ) ;
30- }
31-
7+ /**
8+ * Parses the output of the reg query command into a list of RegEntry instances
9+ *
10+ * @param output - The output of the reg query command
11+ * @returns List of matched RegEntry instances
12+ */
3213export function parseRegQueryOutput ( output : string ) : RegEntry [ ] {
3314 const result : RegEntry [ ] = [ ] ;
3415 let root : string | undefined ;
@@ -73,3 +54,27 @@ export async function queryRegistry(root: string): Promise<RegEntry[]> {
7354 return parseRegQueryOutput ( stdout ) ;
7455}
7556
57+ function parseRegEntries ( root : string | undefined , block : string [ ] ) : RegEntry [ ] {
58+ if ( _ . isEmpty ( block ) || ! root || _ . isEmpty ( root ) ) {
59+ return [ ] ;
60+ }
61+ return block . reduce ( ( acc : RegEntry [ ] , line : string ) => {
62+ const match = ENTRY_PATTERN . exec ( line ) ;
63+ if ( match ) {
64+ acc . push ( { root, key : match [ 1 ] , type : match [ 2 ] , value : match [ 3 ] || '' } ) ;
65+ }
66+ return acc ;
67+ } , [ ] ) ;
68+ }
69+
70+ export interface RegEntry {
71+ /** Full path to the registry branch, for example
72+ * HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\DirectDrawEx */
73+ root : string ;
74+ /** The registry key name */
75+ key : string ;
76+ /** One of possible registry value types, for example REG_DWORD or REG_SZ */
77+ type : string ;
78+ /** The actual value. Could be empty */
79+ value : string ;
80+ }
0 commit comments