Skip to content

Commit fe0a349

Browse files
Simplified settings/log file path handling. Removed support for %appdata%. Use ~/AppData/Roaming instead!
1 parent 461b117 commit fe0a349

4 files changed

Lines changed: 13 additions & 23 deletions

File tree

‎main/ant-kit/src/main/resources/build.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<fx:platform j2se="8.0">
3232
<fx:property name="cryptomator.logPath" value="~/.Cryptomator/cryptomator.log" />
3333
<fx:property name="cryptomator.upgradeLogPath" value="~/.Cryptomator/upgrade.log" />
34+
<fx:property name="cryptomator.settingsPath" value="~/.Cryptomator/settings.json" />
3435
<fx:jvmarg value="-Xmx512m"/>
3536
</fx:platform>
3637
<fx:resources>
@@ -53,6 +54,7 @@
5354
<fx:platform j2se="8.0">
5455
<fx:property name="cryptomator.logPath" value="~/.Cryptomator/cryptomator.log" />
5556
<fx:property name="cryptomator.upgradeLogPath" value="~/.Cryptomator/upgrade.log" />
57+
<fx:property name="cryptomator.settingsPath" value="~/.Cryptomator/settings.json" />
5658
<fx:jvmarg value="-Xmx512m"/>
5759
</fx:platform>
5860
<fx:resources>

‎main/ui/src/main/java/org/cryptomator/ui/logging/ConfigurableFileAppender.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ private static Path parsePath(String path) {
9797
} else if (path.startsWith("/")) {
9898
// absolute Path:
9999
return FileSystems.getDefault().getPath(path);
100-
} else if (SystemUtils.IS_OS_WINDOWS && path.startsWith("%appdata%/")) {
101-
final String appdata = System.getenv("APPDATA");
102-
final Path appdataPath = appdata != null ? FileSystems.getDefault().getPath(appdata) : FileSystems.getDefault().getPath(SystemUtils.USER_HOME);
103-
return appdataPath.resolve(path.substring(10));
104100
} else {
105101
// relative Path:
106102
try {

‎main/ui/src/main/java/org/cryptomator/ui/settings/Localization.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Localization() {
3939
Objects.requireNonNull(in);
4040
Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
4141
this.fallback = new PropertyResourceBundle(reader);
42-
LOG.info("Loaded localization from {}", LOCALIZATION_FILE);
42+
LOG.info("Loaded localization from bundle:{}", LOCALIZATION_FILE);
4343
} catch (IOException e) {
4444
throw new UncheckedIOException(e);
4545
}

‎main/ui/src/main/java/org/cryptomator/ui/settings/SettingsProvider.java‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.nio.file.Path;
1818
import java.nio.file.StandardOpenOption;
1919
import java.util.Objects;
20+
import java.util.Optional;
2021
import java.util.concurrent.Executors;
2122
import java.util.concurrent.ScheduledExecutorService;
2223
import java.util.concurrent.ScheduledFuture;
@@ -28,6 +29,7 @@
2829
import javax.inject.Provider;
2930
import javax.inject.Singleton;
3031

32+
import org.apache.commons.lang3.StringUtils;
3133
import org.apache.commons.lang3.SystemUtils;
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
@@ -38,23 +40,17 @@
3840
public class SettingsProvider implements Provider<Settings> {
3941

4042
private static final Logger LOG = LoggerFactory.getLogger(SettingsProvider.class);
41-
private static final Path SETTINGS_DIR;
42-
private static final String SETTINGS_FILE = "settings.json";
43+
private static final Path DEFAULT_SETTINGS_PATH;
4344
private static final long SAVE_DELAY_MS = 1000;
4445

4546
static {
46-
final String appdata = System.getenv("APPDATA");
4747
final FileSystem fs = FileSystems.getDefault();
48-
49-
if (SystemUtils.IS_OS_WINDOWS && appdata != null) {
50-
SETTINGS_DIR = fs.getPath(appdata, "Cryptomator");
51-
} else if (SystemUtils.IS_OS_WINDOWS && appdata == null) {
52-
SETTINGS_DIR = fs.getPath(SystemUtils.USER_HOME, ".Cryptomator");
48+
if (SystemUtils.IS_OS_WINDOWS) {
49+
DEFAULT_SETTINGS_PATH = fs.getPath(SystemUtils.USER_HOME, "AppData/Roaming/Cryptomator/settings.json");
5350
} else if (SystemUtils.IS_OS_MAC_OSX) {
54-
SETTINGS_DIR = fs.getPath(SystemUtils.USER_HOME, "Library/Application Support/Cryptomator");
51+
DEFAULT_SETTINGS_PATH = fs.getPath(SystemUtils.USER_HOME, "Library/Application Support/Cryptomator/settings.json");
5552
} else {
56-
// (os.contains("solaris") || os.contains("sunos") || os.contains("linux") || os.contains("unix"))
57-
SETTINGS_DIR = fs.getPath(SystemUtils.USER_HOME, ".Cryptomator");
53+
DEFAULT_SETTINGS_PATH = fs.getPath(SystemUtils.USER_HOME, ".Cryptomator/settings.json");
5854
}
5955
}
6056

@@ -68,12 +64,8 @@ public SettingsProvider(@Named("VaultJsonMapper") ObjectMapper objectMapper) {
6864
}
6965

7066
private Path getSettingsPath() throws IOException {
71-
String settingsPathProperty = System.getProperty("cryptomator.settingsPath");
72-
if (settingsPathProperty == null) {
73-
return SETTINGS_DIR.resolve(SETTINGS_FILE);
74-
} else {
75-
return FileSystems.getDefault().getPath(settingsPathProperty);
76-
}
67+
final String settingsPathProperty = System.getProperty("cryptomator.settingsPath");
68+
return Optional.ofNullable(settingsPathProperty).filter(StringUtils::isNotBlank).map(FileSystems.getDefault()::getPath).orElse(DEFAULT_SETTINGS_PATH);
7769
}
7870

7971
@Override
@@ -96,7 +88,7 @@ private void scheduleSave(Settings settings) {
9688
}
9789
ScheduledFuture<?> saveCmd = saveScheduler.schedule(() -> {
9890
this.save(settings);
99-
} , SAVE_DELAY_MS, TimeUnit.MILLISECONDS);
91+
}, SAVE_DELAY_MS, TimeUnit.MILLISECONDS);
10092
ScheduledFuture<?> previousSaveCmd = scheduledSaveCmd.getAndSet(saveCmd);
10193
if (previousSaveCmd != null) {
10294
previousSaveCmd.cancel(false);

0 commit comments

Comments
 (0)