Java Code Examples for com.sun.jna.platform.win32.WinReg#HKEY_CLASSES_ROOT

The following examples show how to use com.sun.jna.platform.win32.WinReg#HKEY_CLASSES_ROOT . 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
private WinReg.HKEY getHKey(
                             String key ) {

    if (key.equalsIgnoreCase(HKEY_CLASSES_ROOT)) {
        return WinReg.HKEY_CLASSES_ROOT;
    } else if (key.equalsIgnoreCase(HKEY_CURRENT_USER)) {
        return WinReg.HKEY_CURRENT_USER;
    } else if (key.equalsIgnoreCase(HKEY_LOCAL_MACHINE)) {
        return WinReg.HKEY_LOCAL_MACHINE;
    } else if (key.equalsIgnoreCase(HKEY_USERS)) {
        return WinReg.HKEY_USERS;
    } else if (key.equalsIgnoreCase(HKEY_CURRENT_CONFIG)) {
        return WinReg.HKEY_CURRENT_CONFIG;
    } else {
        throw new RegistryOperationsException("Unsupported root key '" + key + "'");
    }
}
 
Example 2
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 3
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;
}