From a0d96287dd5d10f4e940449131ab41a4edc41d83 Mon Sep 17 00:00:00 2001 From: Catfriend1 <16361913+Catfriend1@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:25:56 +0100 Subject: [PATCH] Default folder path: Home shortcut (~) broken (#1197) --- .../com/nutomic/syncthingandroid/service/RestApi.java | 6 ++++++ .../java/com/nutomic/syncthingandroid/util/ConfigXml.java | 5 +++++ .../java/com/nutomic/syncthingandroid/util/FileUtils.java | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java index 2c7ce2f48..2b2374103 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/RestApi.java @@ -50,6 +50,7 @@ import com.nutomic.syncthingandroid.model.SystemStatus; import com.nutomic.syncthingandroid.model.SystemVersion; import com.nutomic.syncthingandroid.service.Constants; +import com.nutomic.syncthingandroid.util.FileUtils; import java.io.File; import java.io.FileOutputStream; @@ -594,6 +595,11 @@ public List getFolders() { synchronized (mConfigLock) { folders = deepCopy(mConfig.folders, new TypeToken>(){}.getType()); } + for (Folder folder : folders) { + if (folder.path.startsWith("~/")) { + folder.path = folder.path.replaceFirst("^~", FileUtils.getInternalStorageRootAbsolutePath()); + } + } Collections.sort(folders, FOLDERS_COMPARATOR); return folders; } diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java index 3da9362d3..5d8342a32 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/ConfigXml.java @@ -467,7 +467,12 @@ public List getFolders() { Folder folder = new Folder(); folder.id = getAttributeOrDefault(r, "id", ""); folder.label = getAttributeOrDefault(r, "label", folder.label); + folder.path = getAttributeOrDefault(r, "path", ""); + if (folder.path.startsWith("~/")) { + folder.path = folder.path.replaceFirst("^~", FileUtils.getInternalStorageRootAbsolutePath()); + } + folder.type = getAttributeOrDefault(r, "type", Constants.FOLDER_TYPE_SEND_RECEIVE); folder.autoNormalize = getAttributeOrDefault(r, "autoNormalize", folder.autoNormalize); folder.fsWatcherDelayS =getAttributeOrDefault(r, "fsWatcherDelayS", folder.fsWatcherDelayS); diff --git a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java index aa2b950cd..8a5427953 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/util/FileUtils.java @@ -307,6 +307,14 @@ public static void deleteDirectoryRecursively(java.nio.file.Path pathToDelete) t .map(java.nio.file.Path::toFile) .forEach(File::delete); } + + /** + * Expands the "~" path. + * Result: e.g. /storage/emulated/0 + */ + public static String getInternalStorageRootAbsolutePath() { + return Environment.getExternalStorageDirectory().getAbsolutePath(); + } /** * Derives the mime type from file extension.