Java Code Examples for com.sun.jna.platform.win32.Advapi32Util#registryGetStringValue()

The following examples show how to use com.sun.jna.platform.win32.Advapi32Util#registryGetStringValue() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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");
}