com.sun.jna.platform.win32.Advapi32Util Java Examples

The following examples show how to use com.sun.jna.platform.win32.Advapi32Util. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Delete a registry key
 *
 * @param keyPath
 * @param keyName
 */
@Override
public void deleteKey(
                       String rootKey,
                       String keyPath,
                       String keyName ) {

    log.info("Delete key: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registryDeleteValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't delete registry key. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #2
Source File: Sc2RegMonitor.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the current APM originating from the Windows Registry.
 * 
 * Note: since 2.0 SC2 outputs real-time APM instead of game-time APM,
 * so no conversion is performed to convert it anymore.
 * 
 * <p><b>How to interpret the values in the registry?</b><br>
 * The digits of the result: 5 has to be subtracted from the first digit (in decimal representation), 4 has to be subtracted from the second digit,
 * 3 from the third etc.
 * If the result of a subtraction is negative, 10 has to be added.
 * Examples: 64 => 10 APM; 40 => 96 APM; 8768 => 3336 APM; 38 => 84 APM</p>
 * 
 * @return the current APM or <code>null</code> if some error occurs 
 */
public static Integer getApm() {
	try {
		final String apmString = Advapi32Util.registryGetStringValue( WinReg.HKEY_CURRENT_USER, "Software\\Razer\\Starcraft2", "APMValue" );
		int apm = 0;
		
		for ( int idx = 0, delta = 5, digit; idx < apmString.length(); idx++, delta-- ) {
			digit = apmString.charAt( idx ) - '0' - delta;
			if ( digit < 0 )
				digit += 10;
			apm = apm * 10 + digit;
		}
		
		return apm;
	} catch ( final Exception e ) {
		// Silently ignore, do not print stack trace
		return null;
	}
}
 
Example #3
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findMobileLibrary() {
	if (Platform.isWindows()) {
		String path;
	    try {
	    	path = getMDPath(true);
	    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    } catch (Exception ignored) {
	    	try {
		    	path = getMDPath(false);
		    	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "iTunesMobileDeviceDLL");
	    	} catch (Exception ignored1) {
	    		log.info(ignored.getMessage());
	    		return "";
	    	}
		}
    	File f = new File(path);
    	if (f.exists())
    		return path;
	} else {
		if (Platform.isMac()) {
			return "/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice";
		}
	}
	return "";
}
 
Example #4
Source File: WindowsRegistryParameterProvider.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Map<String, String> readProperties() {
	if (!IS_WINDOWS) {
		return null;
	}
	try {
		// Check if key exists
		if (!Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, CONFIG_KEY)) {
			return null;
		}
		// Read values from registry
		TreeMap<String, Object> map = Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, CONFIG_KEY);
		Map<String, String> values = new HashMap<>();
		map.forEach((String k, Object oV) -> {
					String v = Objects.toString(oV, null);
					values.put(k.trim(), v != null ? v.trim() : null);
				}
		);
		LogService.getRoot().fine(() -> String.format("Successfully enforced %d settings from the Windows registry.", values.size()));
		return values;
	} catch (Throwable e) {
		LogService.getRoot().log(Level.WARNING, "Failed to access the Windows registry.", e);
		return null;
	}
}
 
Example #5
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private static String findCoreLibrary() {
    String path="";
    if (Platform.isWindows()) {
    	try {
	    	path = getCPath(true);
	       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    	} catch (Exception ignored) {
    		try {
		    	path = getCPath(false);
		       	path = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, path, "InstallDir");
    		} catch (Exception ignored1) {
    			return "";
    		}
    	}
       	path = path + "CoreFoundation.dll";
       	File f = new File(path);
       	if (f.exists())
       		return path;
    } else if (Platform.isMac()) {
         return "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation";
    }
    return "";
}
 
Example #6
Source File: Options.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the osu! installation directory.
 * @return the directory, or null if not found
 */
private static File getOsuInstallationDirectory() {
	if (!System.getProperty("os.name").startsWith("Win"))
		return null;  // only works on Windows

	// registry location
	final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT;
	final String regKey = "osu\\DefaultIcon";
	final String regValue = null; // default value
	final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\"";

	String value;
	try {
		value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue);
	} catch (Win32Exception e) {
		return null;  // key/value not found
	}
	Pattern pattern = Pattern.compile(regPathPattern);
	Matcher m = pattern.matcher(value);
	if (!m.find())
		return null;
	File dir = new File(m.group(1));
	return (dir.isDirectory()) ? dir : null;
}
 
Example #7
Source File: ContextMenuTools.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isAddedToContextMenu() {
    if (!Platform.isWindows()) {
        return false;
    }
    final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE;
    final String REG_CLASSES_PATH = "Software\\Classes\\";
    try {
        if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf")) {
            return false;
        }
        String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY, REG_CLASSES_PATH + ".swf", "");
        if (clsName == null) {
            return false;
        }
        return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY, REG_CLASSES_PATH + clsName + "\\shell\\ffdec");
    } catch (Win32Exception ex) {
        return false;
    }
}
 
Example #8
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
private void checkKeyExists(
                             String rootKey,
                             String keyPath,
                             String keyName ) {

    try {
        WinReg.HKEY rootHKey = getHKey(rootKey);
        if (!Advapi32Util.registryValueExists(rootHKey, keyPath, keyName)) {
            throw new RegistryOperationsException("Registry key does not exist. "
                                                  + getDescription(rootKey, keyPath, keyName));
        }
    } catch (Win32Exception e) {
        throw new RegistryOperationsException("Registry key path does not exist. "
                                              + getDescription(rootKey, keyPath, keyName), e);
    }
}
 
Example #9
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Applies a Binary(REG_BINARY) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setBinaryValue(
                            String rootKey,
                            String keyPath,
                            String keyName,
                            byte[] keyValue ) {

    log.info("Set Binary value '" + Arrays.toString(keyValue) + "' on: "
             + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetBinaryValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry binary value to: "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #10
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Applies a Long(REG_QWORD) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setLongValue(
                          String rootKey,
                          String keyPath,
                          String keyName,
                          long keyValue ) {

    log.info("Set Long value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetLongValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry Long value '" + keyValue + "' to: "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #11
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Applies a Integer(REG_DWORD) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setIntValue(
                         String rootKey,
                         String keyPath,
                         String keyName,
                         int keyValue ) {

    log.info("Set Intger value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetIntValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry Integer value '" + keyValue
                                              + "' to: "
                                              + getDescription(rootKey, keyPath, keyName),
                                              re);
    }
}
 
Example #12
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Applies a String(REG_SZ) value on the specified key.
 *
 * The key will be created if does not exist.
 * The key type will be changed if needed.
 *
 * @param keyPath
 * @param keyName
 * @param keyValue
 */
@Override
public void setStringValue(
                            String rootKey,
                            String keyPath,
                            String keyName,
                            String keyValue ) {

    log.info("Set String value '" + keyValue + "' on: " + getDescription(rootKey, keyPath, keyName));

    try {
        Advapi32Util.registrySetStringValue(getHKey(rootKey), keyPath, keyName, keyValue);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't set registry String value '" + keyValue
                                              + "' to: "
                                              + getDescription(rootKey, keyPath, keyName),
                                              re);
    }
}
 
Example #13
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Creates path in the registry.
 *
 * Will fail if the path exists already.
 *
 * If want to create a nested path(for example "Software\\MyCompany\\MyApplication\\Configuration"),
 * it is needed to call this method for each path token(first for "Software\\MyCompany", then for "Software\\MyCompany\\MyApplication" etc)
 *
 * @param keyPath
 */
@Override
public void createPath(
                        String rootKey,
                        String keyPath ) {

    log.info("Create regestry key path: " + getDescription(rootKey, keyPath, null));

    int index = keyPath.lastIndexOf("\\");
    if (index < 1) {
        throw new RegistryOperationsException("Invalid path '" + keyPath + "'");
    }

    String keyParentPath = keyPath.substring(0, index);
    String keyName = keyPath.substring(index + 1);

    checkPathDoesNotExist(rootKey, keyPath);

    try {
        Advapi32Util.registryCreateKey(getHKey(rootKey), keyParentPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Couldn't create registry key. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #14
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get Binary registry value(REG_BINARY)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public byte[] getBinaryValue(
                              String rootKey,
                              String keyPath,
                              String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetBinaryValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Binary. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #15
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get Long registry value(REG_QWORD)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public long getLongValue(
                          String rootKey,
                          String keyPath,
                          String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetLongValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Long. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #16
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Get Integer registry value(REG_DWORD)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public int getIntValue(
                        String rootKey,
                        String keyPath,
                        String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);

    try {
        return Advapi32Util.registryGetIntValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type Integer. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #17
Source File: JdkGenericDumpTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
private static Set<String> findJavaHomesOnWindows(final String keyJavaHome, final String[] keys) {
    final Set<String> javaHomes = new HashSet<>(keys.length);
    for (final String key : keys) {
        if (Advapi32Util.registryKeyExists(HKEY_LOCAL_MACHINE, keyJavaHome + "\\" + key)) {
            final String javaHome = Advapi32Util.registryGetStringValue(HKEY_LOCAL_MACHINE,
                keyJavaHome + "\\" + key, "JavaHome");
            if (StringUtils.isNoneBlank(javaHome)) {
                if (new File(javaHome).exists()) {
                    javaHomes.add(javaHome);
                }
            }
        }
    }
    return javaHomes;
}
 
Example #18
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Get String registry value(REG_SZ)
 *
 * @param keyPath
 * @param keyName
 * @return
 */
@Override
public String getStringValue(
                              String rootKey,
                              String keyPath,
                              String keyName ) {

    checkKeyExists(rootKey, keyPath, keyName);
    try {
        return Advapi32Util.registryGetStringValue(getHKey(rootKey), keyPath, keyName);
    } catch (RuntimeException re) {
        throw new RegistryOperationsException("Registry key is not of type String. "
                                              + getDescription(rootKey, keyPath, keyName), re);
    }
}
 
Example #19
Source File: JnaWinRegistry.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Nullable
public static String readString(WinReg.HKEY hkey, String key, String valueName) {
    if (! isAvailable()) {
        return null;
    }
    try {
        return Advapi32Util.registryGetStringValue(hkey, key, valueName);
    } catch (Win32Exception e) {
        return null;
    }
}
 
Example #20
Source File: Sc2RegMonitor.java    From sc2gears with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the current game status from the Windows Registry.
 * @return the current game status or <code>null</code> if some error occurs 
 */
public static Integer getGameStatus() {
	try {
		return Advapi32Util.registryGetIntValue( WinReg.HKEY_CURRENT_USER, "Software\\Razer\\Starcraft2", "StartModule" );
	} catch ( final Exception e ) {
		// Silently ignore, do not print stack trace
		return null;
	}
}
 
Example #21
Source File: Configuration.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
private File loadOsuInstallationDirectory() {
	if (!System.getProperty("os.name").startsWith("Win")) {
		return null;
	}

	final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT;
	final String regKey = "osu\\DefaultIcon";
	final String regValue = null; // default value
	final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\"";

	String value;
	try {
		value = Advapi32Util.registryGetStringValue(rootKey, regKey, regValue);
	} catch (Win32Exception ignored) {
		return null;
	}
	Pattern pattern = Pattern.compile(regPathPattern);
	Matcher m = pattern.matcher(value);
	if (!m.find()) {
		return null;
	}
	File dir = new File(m.group(1));
	if (dir.isDirectory()) {
		return dir;
	}
	return null;
}
 
Example #22
Source File: OSUtils.java    From SWET with MIT License 5 votes vote down vote up
public static int getAdvancedOptionsZoom() {
	int value = -1;
	try {
		value = Advapi32Util.registryGetIntValue(WinReg.HKEY_LOCAL_MACHINE,
				"SOFTWARE\\Microsoft\\Internet Explorer\\AdvancedOptions\\ACCESSIBILITY\\ZOOMLEVEL",
				"CheckedValue");
	} catch (Exception e) {
		e.printStackTrace();
	}
	return value;
}
 
Example #23
Source File: OSUtils.java    From SWET with MIT License 5 votes vote down vote up
private static List<String> findBrowsersInRegistry() {
	// String regPath = "SOFTWARE\\Clients\\StartMenuInternet\\";
	String regPath = is64bit
			? "SOFTWARE\\Wow6432Node\\Clients\\StartMenuInternet\\"
			: "SOFTWARE\\Clients\\StartMenuInternet\\";

	List<String> browsers = new ArrayList<>();
	String path = null;
	try {
		for (String browserName : Advapi32Util
				.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE, regPath)) {
			path = Advapi32Util
					.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,
							regPath + "\\" + browserName + "\\shell\\open\\command", "")
					.replace("\"", "");
			if (path != null && new File(path).exists()) {
				String browser = path.replaceAll("\\\\", "/")
						.replaceAll("^(?:.+)/([^/]+)(.exe)$", "$1$2");
				if (debug)
					err.println("Found browser: " + browser);
				browsers.add(path.toString());
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return browsers;
}
 
Example #24
Source File: LocalRegistryOperations.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
private void checkPathDoesNotExist(
                                    String rootKey,
                                    String keyPath ) {

    if (Advapi32Util.registryKeyExists(getHKey(rootKey), keyPath)) {
        throw new RegistryOperationsException("Registry path already exists. "
                                              + getDescription(rootKey, keyPath, null));
    }
}
 
Example #25
Source File: LibraryFinder.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private static boolean loadPath() {
	String mdPath;
	String cfpath;
	if (Platform.isWindows()) {
		try {

			mdPath = getMDPath(true);
			mdPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, mdPath, "iTunesMobileDeviceDLL");
			
			cfpath = getCPath(true);
			cfpath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, cfpath, "InstallDir");

			ANBActivator
			.getDefault()
			.getLog()
			.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
					"loadPath() mdpath = "+mdPath+ " cfpath = "+cfpath, null));

		} catch (Throwable ignored) {
			try {
				mdPath = getMDPath(false);
				mdPath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, mdPath, "iTunesMobileDeviceDLL");
				
				cfpath = getCPath(false);
				cfpath = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, cfpath, "InstallDir");

			} catch (Throwable ignored1) {
				ignored.printStackTrace();
				ANBActivator
				.getDefault()
				.getLog()
				.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
						"windows registry path not exist", null));
				return false;
			}
		}
		File fMd = new File(mdPath);
		if (!(fMd.exists())) {
			ANBActivator
			.getDefault()
			.getLog()
			.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
					"File path not exist", null));
			return false;
		}			
		String pathEnvVar = System.getenv("Path");
		pathEnvVar = pathEnvVar +   cfpath  + ";" + fMd.getParent() ;
		
		Environment.setEnv("Path", pathEnvVar);
		ANBActivator
		.getDefault()
		.getLog()
		.log(new Status(IStatus.ERROR, ANBActivator.PLUGIN_ID, 0, 
				"Environment.setEnv pathEnvVar = " + pathEnvVar, null));
		
         String sqlite3 = cfpath + "/SQLite3.dll";
         File fsql = new File(sqlite3);
         if (fsql.exists())
           System.load(cfpath + "/SQLite3.dll");
         
         String cfnetwork = cfpath + "/CFNetwork.dll";
         File fcfn = new File(cfnetwork);
         if (fcfn.exists())
           System.load(cfpath + "/CFNetwork.dll");
    }
    return true;
}
 
Example #26
Source File: ContextMenuTools.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
private static void registryDeleteKey(WinReg.HKEY hKey, String keyName) {
    boolean exists = Advapi32Util.registryKeyExists(hKey, keyName);
    if (exists) {
        Advapi32Util.registryDeleteKey(hKey, keyName);
    }
}
 
Example #27
Source File: ContextMenuTools.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
private static void registryDeleteValue(WinReg.HKEY root, String keyPath, String valueName) {
    boolean exists = Advapi32Util.registryValueExists(root, keyPath, valueName);
    if (exists) {
        Advapi32Util.registryDeleteValue(root, keyPath, valueName);
    }
}
 
Example #28
Source File: Main.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static void initLang() {
    if (!Configuration.locale.hasValue()) {
        if (Platform.isWindows()) {
            //Load from Installer
            String uninstKey = "{E618D276-6596-41F4-8A98-447D442A77DB}_is1";
            uninstKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + uninstKey;
            try {
                if (Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey)) {
                    if (Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language")) {
                        String installedLoc = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, uninstKey, "NSIS: Language");
                        int lcid = Integer.parseInt(installedLoc);
                        char[] buf = new char[9];
                        int cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO639LANGNAME, buf, 9);
                        String langCode = new String(buf, 0, cnt).trim().toLowerCase();

                        cnt = Kernel32.INSTANCE.GetLocaleInfo(lcid, Kernel32.LOCALE_SISO3166CTRYNAME, buf, 9);
                        String countryCode = new String(buf, 0, cnt).trim().toLowerCase();

                        List<String> langs = Arrays.asList(SelectLanguageDialog.getAvailableLanguages());
                        for (int i = 0; i < langs.size(); i++) {
                            langs.set(i, langs.get(i).toLowerCase());
                        }

                        String selectedLang = null;

                        if (langs.contains(langCode + "-" + countryCode)) {
                            selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode + "-" + countryCode)];
                        } else if (langs.contains(langCode)) {
                            selectedLang = SelectLanguageDialog.getAvailableLanguages()[langs.indexOf(langCode)];
                        }
                        if (selectedLang != null) {
                            Configuration.locale.set(selectedLang);
                        }
                    }
                }
            } catch (Exception ex) {
                //ignore
            }
        }
    }
    Locale.setDefault(Locale.forLanguageTag(Configuration.locale.get()));
    AppStrings.updateLanguage();

    Helper.decompilationErrorAdd = AppStrings.translate(Configuration.autoDeobfuscate.get() ? "deobfuscation.comment.failed" : "deobfuscation.comment.tryenable");
}
 
Example #29
Source File: JdkGenericDumpTestCase.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
private static void addAllJavaHomesOnWindows(final String keyJre, final Set<String> javaHomes) {
    if (Advapi32Util.registryKeyExists(HKEY_LOCAL_MACHINE, keyJre)) {
        javaHomes.addAll(findJavaHomesOnWindows(keyJre, Advapi32Util.registryGetKeys(HKEY_LOCAL_MACHINE, keyJre)));
    }
}