mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
impl idea
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package org.cryptomator.launcher;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Properties;
|
||||
|
||||
class AdminPropertiesSetter {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AdminPropertiesSetter.class);
|
||||
|
||||
static {
|
||||
final Path adminDir;
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
adminDir = Path.of(System.getenv().getOrDefault("ProgramData", "C:\\ProgramData"), "Cryptomator");
|
||||
} else if (SystemUtils.IS_OS_MAC) {
|
||||
adminDir = Path.of("/Library/Application Support/Cryptomator");
|
||||
} else { //LINUX
|
||||
adminDir = Path.of("/etc/cryptmator");
|
||||
}
|
||||
ADMIN_PROPERTIES_DIR = adminDir;
|
||||
}
|
||||
|
||||
private static final Path ADMIN_PROPERTIES_DIR;
|
||||
private static final Path ADMIN_PROPERTIES_FILE = ADMIN_PROPERTIES_DIR.resolve("config.properties");
|
||||
|
||||
static Properties adjustSystemProperties() {
|
||||
var systemProps = System.getProperties();
|
||||
var adminProps = loadAdminProperties(ADMIN_PROPERTIES_FILE);
|
||||
for (var key : adminProps.stringPropertyNames()) {
|
||||
var value = adminProps.getProperty(key);
|
||||
LOG.info("Overwriting {} with value {} from admin properties.", key, value);
|
||||
systemProps.setProperty(key, value);
|
||||
}
|
||||
return systemProps;
|
||||
}
|
||||
|
||||
private static Properties loadAdminProperties(Path adminPropertiesPath) {
|
||||
var adminProps = new Properties();
|
||||
try {
|
||||
adminProps.load(Files.newInputStream(adminPropertiesPath, StandardOpenOption.READ));
|
||||
} catch (NoSuchFileException _) {
|
||||
//NO-OP
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
LOG.warn("Failed to read administrative properties from {}. Returning empty properties.", adminPropertiesPath, e);
|
||||
}
|
||||
return adminProps;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Singleton
|
||||
@@ -35,7 +36,8 @@ public class Cryptomator {
|
||||
private static final long STARTUP_TIME = System.currentTimeMillis();
|
||||
|
||||
static {
|
||||
var lazyProcessedProps = new SubstitutingProperties(System.getProperties(), System.getenv());
|
||||
var adjustedSystemProps = AdminPropertiesSetter.adjustSystemProperties();
|
||||
var lazyProcessedProps = new SubstitutingProperties(adjustedSystemProps, System.getenv());
|
||||
System.setProperties(lazyProcessedProps);
|
||||
CRYPTOMATOR_COMPONENT = DaggerCryptomatorComponent.factory().create(STARTUP_TIME);
|
||||
LOG = LoggerFactory.getLogger(Cryptomator.class);
|
||||
|
||||
Reference in New Issue
Block a user