Import voice
This commit is contained in:
parent
b5f06cf3c1
commit
e9a1bad5ab
6 changed files with 22 additions and 19 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<? extends SettingsItem> reader = item.getReader();
|
||||
if (reader != null) {
|
||||
reader.setDestination(app.getAppPath(fileName));
|
||||
reader.readFromStream(ois);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<T extends SettingsItem> {
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue