private void checkAutoStartRegistry() { if (Constants.isWindows) { try { /* * else, not first start sync up the setting with what is in the * windows registry */ int handle = RegUtil.RegOpenKey( RegUtil.HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegUtil.KEY_ALL_ACCESS)[RegUtil.NATIVE_HANDLE]; byte[] value = RegUtil.RegQueryValueEx(handle, "OneSwarm"); RegUtil.RegCloseKey(handle); if (value != null) { COConfigurationManager.setParameter("autostart", true); } else { COConfigurationManager.setParameter("autostart", false); } } catch (Exception e) { e.printStackTrace(); } // create config listener COConfigurationManager.addAndFireParameterListener( "autostart", new ParameterListener() { public void parameterChanged(String parameterName) { try { int handle = RegUtil.RegOpenKey( RegUtil.HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", RegUtil.KEY_ALL_ACCESS)[RegUtil.NATIVE_HANDLE]; byte[] value = RegUtil.RegQueryValueEx(handle, "OneSwarm"); boolean registryValue = value != null; if (registryValue != COConfigurationManager.getBooleanParameter("autostart")) { if (COConfigurationManager.getBooleanParameter("autostart")) { // install the registry key RegUtil.RegSetValueEx( handle, "OneSwarm", "\"" + SystemProperties.getApplicationPath() + "OneSwarm.exe\" --autostart"); } else { // remove the registry key RegUtil.RegDeleteValue(handle, "OneSwarm"); } } RegUtil.RegCloseKey(handle); } catch (Exception e) { e.printStackTrace(); } } }); } }
/** * 判断是否符是合法的文件路径 * * @param path * @return */ public static boolean legalFile(String path) { // 下面的正则表达式有问题 String regex = "[a-zA-Z]:(?:[/][^/:*?\"<>|.][^/:*?\"<>|]{0,254})+"; // String regex ="^([a-zA-z]:)|(^\\.{0,2}/)|(^\\w*)\\w([^:?*\"><|]){0,250}"; return RegUtil.isMatche(commandPath(path), regex); }