@@ -19,11 +19,11 @@ export interface IRegistry {
19
19
}
20
20
21
21
export class RegistryImplementation implements IRegistry {
22
- public getKeys ( key : string , hive : Hive , arch ?: Architecture ) {
23
- return getRegistryKeys ( { hive : translateHive ( hive ) , arch : translateArchitecture ( arch ) , key } ) ;
22
+ public async getKeys ( key : string , hive : Hive , arch ?: Architecture ) {
23
+ return getRegistryKeys ( { hive : translateHive ( hive ) ! , arch : translateArchitecture ( arch ) , key } ) ;
24
24
}
25
- public getValue ( key : string , hive : Hive , arch ?: Architecture , name : string = '' ) {
26
- return getRegistryValue ( { hive : translateHive ( hive ) , arch : translateArchitecture ( arch ) , key } , name ) ;
25
+ public async getValue ( key : string , hive : Hive , arch ?: Architecture , name : string = '' ) {
26
+ return getRegistryValue ( { hive : translateHive ( hive ) ! , arch : translateArchitecture ( arch ) , key } , name ) ;
27
27
}
28
28
}
29
29
@@ -38,28 +38,28 @@ export function getArchitectureDislayName(arch?: Architecture) {
38
38
}
39
39
}
40
40
41
- function getRegistryValue ( options : Registry . Options , name : string = '' ) {
41
+ async function getRegistryValue ( options : Registry . Options , name : string = '' ) {
42
42
return new Promise < string | undefined | null > ( ( resolve , reject ) => {
43
43
new Registry ( options ) . get ( name , ( error , result ) => {
44
- if ( error ) {
44
+ if ( error || ! result || typeof result . value !== 'string' ) {
45
45
return resolve ( undefined ) ;
46
46
}
47
47
resolve ( result . value ) ;
48
48
} ) ;
49
49
} ) ;
50
50
}
51
- function getRegistryKeys ( options : Registry . Options ) : Promise < string [ ] > {
51
+ async function getRegistryKeys ( options : Registry . Options ) : Promise < string [ ] > {
52
52
// https://github.com/python/peps/blob/master/pep-0514.txt#L85
53
53
return new Promise < string [ ] > ( ( resolve , reject ) => {
54
54
new Registry ( options ) . keys ( ( error , result ) => {
55
- if ( error ) {
55
+ if ( error || ! Array . isArray ( result ) ) {
56
56
return resolve ( [ ] ) ;
57
57
}
58
- resolve ( result . map ( item => item . key ) ) ;
58
+ resolve ( result . filter ( item => typeof item . key === 'string' ) . map ( item => item . key ) ) ;
59
59
} ) ;
60
60
} ) ;
61
61
}
62
- function translateArchitecture ( arch ?: Architecture ) : RegistryArchitectures | null | undefined {
62
+ function translateArchitecture ( arch ?: Architecture ) : RegistryArchitectures | undefined {
63
63
switch ( arch ) {
64
64
case Architecture . x86 :
65
65
return RegistryArchitectures . x86 ;
@@ -69,7 +69,7 @@ function translateArchitecture(arch?: Architecture): RegistryArchitectures | nul
69
69
return ;
70
70
}
71
71
}
72
- function translateHive ( hive : Hive ) : string | null | undefined {
72
+ function translateHive ( hive : Hive ) : string | undefined {
73
73
switch ( hive ) {
74
74
case Hive . HKCU :
75
75
return Registry . HKCU ;
0 commit comments