public EncryptedTransferSettingsConverter(Class<? extends TransferSettings> transferSettingsClass) { this.encryptedFields = getEncryptedFields(transferSettingsClass); }
public void save(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter(transferSettings.getClass())); new Persister(strategy).write(this, file); } catch (Exception e) { throw new ConfigException("Cannot write config to file " + file, e); } }
public static ConfigTO load(File file) throws ConfigException { try { Registry registry = new Registry(); Strategy strategy = new RegistryStrategy(registry); registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter()); registry.bind(String.class, new EncryptedTransferSettingsConverter()); return new Persister(strategy).read(ConfigTO.class, file); } catch (ClassNotFoundException ex) { // Ugly hack to catch common case of non-existing plugin String message = ex.getMessage(); if (!message.startsWith("org.syncany.plugins.")) { // Apparently there are other ClassNotFoundExceptions possible. throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } message = message.replaceFirst("org.syncany.plugins.", ""); message = message.replaceAll("\\..*", ""); throw new ConfigException("Is the " + message + " plugin installed?"); } catch (Exception ex) { throw new ConfigException("Config file does not exist or is invalid: " + file, ex); } }