Fix import gpx files to custom folders
(cherry picked from commit caac552822
)
This commit is contained in:
parent
0e965dd796
commit
e7bb115e29
2 changed files with 17 additions and 4 deletions
|
@ -2,8 +2,6 @@ package net.osmand.util;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.router.GeneralRouter;
|
|
||||||
import net.osmand.router.RoutingConfiguration;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -31,7 +29,6 @@ import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,6 +367,14 @@ public class Algorithms {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createParentDirsForFile(File file) {
|
||||||
|
if (file != null && !file.exists()) {
|
||||||
|
File parent = file.getParentFile();
|
||||||
|
if (parent != null && !parent.exists()) {
|
||||||
|
parent.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
@SuppressWarnings("TryFinallyCanBeTryWithResources")
|
||||||
public static void fileCopy(File src, File dst) throws IOException {
|
public static void fileCopy(File src, File dst) throws IOException {
|
||||||
|
|
|
@ -74,7 +74,6 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
import net.osmand.plus.helpers.ColorDialogs;
|
import net.osmand.plus.helpers.ColorDialogs;
|
||||||
import net.osmand.plus.helpers.ExternalApiHelper;
|
import net.osmand.plus.helpers.ExternalApiHelper;
|
||||||
import net.osmand.plus.helpers.LockHelper;
|
|
||||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.IContextMenuButtonListener;
|
import net.osmand.plus.mapcontextmenu.other.IContextMenuButtonListener;
|
||||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
|
@ -1315,6 +1314,9 @@ public class OsmandAidlApi {
|
||||||
File destination = app.getAppPath(IndexConstants.GPX_INDEX_DIR + destinationPath);
|
File destination = app.getAppPath(IndexConstants.GPX_INDEX_DIR + destinationPath);
|
||||||
if (destination.getParentFile().canWrite()) {
|
if (destination.getParentFile().canWrite()) {
|
||||||
boolean destinationExists = destination.exists();
|
boolean destinationExists = destination.exists();
|
||||||
|
if (!destinationExists) {
|
||||||
|
Algorithms.createParentDirsForFile(destination);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Algorithms.fileCopy(source, destination);
|
Algorithms.fileCopy(source, destination);
|
||||||
finishGpxImport(destinationExists, destination, color, show);
|
finishGpxImport(destinationExists, destination, color, show);
|
||||||
|
@ -1336,6 +1338,9 @@ public class OsmandAidlApi {
|
||||||
gpxParcelDescriptor = app.getContentResolver().openFileDescriptor(gpxUri, "r");
|
gpxParcelDescriptor = app.getContentResolver().openFileDescriptor(gpxUri, "r");
|
||||||
if (gpxParcelDescriptor != null) {
|
if (gpxParcelDescriptor != null) {
|
||||||
boolean destinationExists = destination.exists();
|
boolean destinationExists = destination.exists();
|
||||||
|
if (!destinationExists) {
|
||||||
|
Algorithms.createParentDirsForFile(destination);
|
||||||
|
}
|
||||||
FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
|
FileDescriptor fileDescriptor = gpxParcelDescriptor.getFileDescriptor();
|
||||||
InputStream is = new FileInputStream(fileDescriptor);
|
InputStream is = new FileInputStream(fileDescriptor);
|
||||||
FileOutputStream fout = new FileOutputStream(destination);
|
FileOutputStream fout = new FileOutputStream(destination);
|
||||||
|
@ -1370,6 +1375,9 @@ public class OsmandAidlApi {
|
||||||
InputStream is = new ByteArrayInputStream(sourceRawData.getBytes());
|
InputStream is = new ByteArrayInputStream(sourceRawData.getBytes());
|
||||||
FileOutputStream fout = new FileOutputStream(destination);
|
FileOutputStream fout = new FileOutputStream(destination);
|
||||||
boolean destinationExists = destination.exists();
|
boolean destinationExists = destination.exists();
|
||||||
|
if (!destinationExists) {
|
||||||
|
Algorithms.createParentDirsForFile(destination);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Algorithms.streamCopy(is, fout);
|
Algorithms.streamCopy(is, fout);
|
||||||
finishGpxImport(destinationExists, destination, color, show);
|
finishGpxImport(destinationExists, destination, color, show);
|
||||||
|
|
Loading…
Reference in a new issue