From a9bcb275b1620a0708b1b55081e2d3c0349f33ff Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 24 Apr 2017 12:51:35 -0700 Subject: [PATCH] refactor to be more readable (#65) --- js/utils/getRegistry.js | 62 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/js/utils/getRegistry.js b/js/utils/getRegistry.js index a9e52e71..b5010466 100644 --- a/js/utils/getRegistry.js +++ b/js/utils/getRegistry.js @@ -16,42 +16,46 @@ var symphonyRegistryHKLM = new Registry({ var symphonyRegistryHKLM6432 = new Registry({ key: symphonyRegistry.replace('\\Software','\\Software\\WOW6432Node') }); - + /** - * Reads Windows Registry key. This Registry holds the Symphony registry keys - * that are intended to be used as global (or default) value for all users + * Reads Windows Registry key. This Registry holds the Symphony registry keys + * that are intended to be used as global (or default) value for all users * running this app. */ var getRegistry = function (name) { var promise = new Promise(function(resolve, reject) { - if (isMac){ - reject('Mac OS. Using default url from config.json.'); - } else{ - //Try to get registry on HKEY_CURRENT_USER - symphonyRegistryHKCU.get( name, function( err1, reg1 ) { - if ( !err1 && reg1!==null && reg1.value) { - resolve(reg1.value); - } else{ - //Try to get registry on HKEY_LOCAL_MACHINE - symphonyRegistryHKLM.get( name, function( err2, reg2 ) { - if ( !err2 && reg2!==null && reg2.value) { - resolve(reg2.value); - } else{ - //Try to get registry on HKEY_LOCAL_MACHINE in case 32bit app installed on 64bit system. - //winreg does not merge keys as normally windows does. - symphonyRegistryHKLM6432.get( name, function( err3, reg3 ) { - if ( !err3 && reg3!==null && reg3.value) { - resolve(reg3.value); - } else{ - reject('Cannot find PodUrl Registry. Using default url.'); - } - }); - } - }); - } - }); + if (isMac) { + reject('registry is not supported for mac osx.'); + return; } + + //Try to get registry on HKEY_CURRENT_USER + symphonyRegistryHKCU.get( name, function( err1, reg1 ) { + if (!err1 && reg1 !==null && reg1.value) { + resolve(reg1.value); + return; + } + + //Try to get registry on HKEY_LOCAL_MACHINE + symphonyRegistryHKLM.get( name, function( err2, reg2 ) { + if ( !err2 && reg2!==null && reg2.value) { + resolve(reg2.value); + return; + } + + // Try to get registry on HKEY_LOCAL_MACHINE in case 32bit app installed on 64bit system. + // winreg does not merge keys as normally windows does. + symphonyRegistryHKLM6432.get( name, function( err3, reg3 ) { + if ( !err3 && reg3!==null && reg3.value) { + resolve(reg3.value); + } else{ + reject('Cannot find PodUrl Registry. Using default url.'); + } + }); + }); + }); }); + return promise; }