diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java index 151aaf61f6..bb66ad06d0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java @@ -21,8 +21,6 @@ import java.io.OutputStream; public class FileSettingsItem extends StreamSettingsItem { - - public enum FileSubtype { UNKNOWN("", null), OTHER("other", ""), @@ -50,6 +48,10 @@ public class FileSettingsItem extends StreamSettingsItem { return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP; } + public boolean isDirectory() { + return this == TTS_VOICE || this == VOICE; + } + public String getSubtypeName() { return subtypeName; } @@ -123,7 +125,6 @@ public class FileSettingsItem extends StreamSettingsItem { private final File appPath; protected FileSubtype subtype; private long size; - private boolean subFolders; public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException { super(app, file.getPath().replace(app.getAppPath(null).getPath(), "")); @@ -210,14 +211,6 @@ public class FileSettingsItem extends StreamSettingsItem { this.size = size; } - public boolean isSubFolders() { - return subFolders; - } - - public void setSubFolders(boolean subFolders) { - this.subFolders = subFolders; - } - @NonNull public File getFile() { return file; @@ -253,7 +246,7 @@ public class FileSettingsItem extends StreamSettingsItem { @Override public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException { OutputStream output; - File dest = FileSettingsItem.this.file; + File dest = getDestination(); if (dest.exists() && !shouldReplace) { dest = renameFile(dest); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsExporter.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsExporter.java index 88809ea937..88b7851630 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsExporter.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsExporter.java @@ -68,7 +68,7 @@ class SettingsExporter { if (Algorithms.isEmpty(fileName)) { fileName = item.getDefaultFileName(); } - if (item instanceof FileSettingsItem && ((FileSettingsItem) item).isSubFolders()) { + if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype().isDirectory()) { File file = ((FileSettingsItem) item).getFile(); zipDirsWithFiles(file, writer, zos); } else { @@ -97,7 +97,7 @@ class SettingsExporter { FileSettingsItem item = (FileSettingsItem) writer.getItem(); String zipEntryName = Algorithms.isEmpty(item.getSubtype().getSubtypeFolder()) ? f.getName() - : f.getPath().substring(f.getPath().indexOf(item.getSubtype().getSubtypeFolder())); + : f.getPath().substring(f.getPath().indexOf(item.getSubtype().getSubtypeFolder()) - 1); ZipEntry entry = new ZipEntry(zipEntryName); zos.putNextEntry(entry); item.setInputStream(new FileInputStream(f)); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 0af0aa08b8..218d1a1f16 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -610,9 +610,6 @@ public class SettingsHelper { try { FileSettingsItem fileItem = new FileSettingsItem(app, (File) object); settingsItems.add(fileItem); - if (FileSubtype.getSubtypeByPath(app, ((File) object).getPath()) == FileSubtype.VOICE) { - fileItem.setSubFolders(true); - } } catch (IllegalArgumentException e) { LOG.warn("Trying to export unsuported file type", e); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java index a03f363542..f1a6f2d894 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java @@ -25,7 +25,7 @@ import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; class SettingsImporter { - private OsmandApplication app; + private final OsmandApplication app; SettingsImporter(@NonNull OsmandApplication app) { this.app = app; @@ -124,6 +124,7 @@ class SettingsImporter { try { SettingsItemReader reader = item.getReader(); if (reader != null) { + reader.setDestination(app.getAppPath(fileName)); reader.readFromStream(ois); } } catch (IllegalArgumentException e) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java index e54cc99409..301c4f8882 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItem.java @@ -12,6 +12,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -88,7 +89,7 @@ public abstract class SettingsItem { public boolean applyFileName(@NonNull String fileName) { String n = getFileName(); - return n != null && (n.endsWith(fileName) || fileName.startsWith(n)); + return n != null && (n.endsWith(fileName) || fileName.startsWith(n + File.separator)); } public boolean shouldReadOnCollecting() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemReader.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemReader.java index daa66f979a..5269150adc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemReader.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemReader.java @@ -2,6 +2,7 @@ package net.osmand.plus.settings.backend.backup; import androidx.annotation.NonNull; +import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -9,9 +10,19 @@ public abstract class SettingsItemReader { private T item; + File destination; + public SettingsItemReader(@NonNull T item) { this.item = item; } + public void setDestination(File destination) { + this.destination = destination; + } + + public File getDestination() { + return destination; + } + public abstract void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException; }