Skip to content

Commit

Permalink
Fix registry lookup response (#224)
Browse files Browse the repository at this point in the history
fixes #58, check if valid value is returned
  • Loading branch information
DonJayamanne authored Nov 22, 2017
1 parent a6b49d2 commit f37fe13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/client/common/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export interface IRegistry {
}

export class RegistryImplementation implements IRegistry {
public getKeys(key: string, hive: Hive, arch?: Architecture) {
return getRegistryKeys({ hive: translateHive(hive), arch: translateArchitecture(arch), key });
public async getKeys(key: string, hive: Hive, arch?: Architecture) {
return getRegistryKeys({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key });
}
public getValue(key: string, hive: Hive, arch?: Architecture, name: string = '') {
return getRegistryValue({ hive: translateHive(hive), arch: translateArchitecture(arch), key }, name);
public async getValue(key: string, hive: Hive, arch?: Architecture, name: string = '') {
return getRegistryValue({ hive: translateHive(hive)!, arch: translateArchitecture(arch), key }, name);
}
}

Expand All @@ -38,28 +38,28 @@ export function getArchitectureDislayName(arch?: Architecture) {
}
}

function getRegistryValue(options: Registry.Options, name: string = '') {
async function getRegistryValue(options: Registry.Options, name: string = '') {
return new Promise<string | undefined | null>((resolve, reject) => {
new Registry(options).get(name, (error, result) => {
if (error) {
if (error || !result || typeof result.value !== 'string') {
return resolve(undefined);
}
resolve(result.value);
});
});
}
function getRegistryKeys(options: Registry.Options): Promise<string[]> {
async function getRegistryKeys(options: Registry.Options): Promise<string[]> {
// https://github.com/python/peps/blob/master/pep-0514.txt#L85
return new Promise<string[]>((resolve, reject) => {
new Registry(options).keys((error, result) => {
if (error) {
if (error || !Array.isArray(result)) {
return resolve([]);
}
resolve(result.map(item => item.key));
resolve(result.filter(item => typeof item.key === 'string').map(item => item.key));
});
});
}
function translateArchitecture(arch?: Architecture): RegistryArchitectures | null | undefined {
function translateArchitecture(arch?: Architecture): RegistryArchitectures | undefined {
switch (arch) {
case Architecture.x86:
return RegistryArchitectures.x86;
Expand All @@ -69,7 +69,7 @@ function translateArchitecture(arch?: Architecture): RegistryArchitectures | nul
return;
}
}
function translateHive(hive: Hive): string | null | undefined {
function translateHive(hive: Hive): string | undefined {
switch (hive) {
case Hive.HKCU:
return Registry.HKCU;
Expand Down
6 changes: 3 additions & 3 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"PromiseLike"
],
"completed-docs": false,
"no-void-expression": false,
"no-non-null-assertion": false,
"no-unsafe-any": false,
"prefer-type-cast": false,
"function-name": false,
"variable-name": false,
"no-void-expression": false,
"no-backbone-get-set-outside-model": false,
"underscore-consistent-invocation": false,
"no-non-null-assertion": false
"underscore-consistent-invocation": false
}
}

0 comments on commit f37fe13

Please sign in to comment.