impl idea

This commit is contained in:
Armin Schrenk
2026-01-12 11:59:17 +01:00
parent 8e68a62ab0
commit 11c86f7287
2 changed files with 59 additions and 1 deletions

View File

@@ -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;
}
}

View File

@@ -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);