Remove srtm file of other type after new downloaded
This commit is contained in:
parent
fed2e356c3
commit
40c060af26
2 changed files with 38 additions and 18 deletions
|
@ -7,6 +7,7 @@ import net.osmand.osm.io.NetworkUtils;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.download.IndexItem.DownloadEntry;
|
||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -213,8 +214,8 @@ public class DownloadFileHelper {
|
|||
}
|
||||
unzipFile(de, progress, downloadInputStreams);
|
||||
if (!de.targetFile.getAbsolutePath().equals(de.fileToDownload.getAbsolutePath())) {
|
||||
boolean successfull = Algorithms.removeAllFiles(de.targetFile);
|
||||
if (successfull) {
|
||||
boolean successful = Algorithms.removeAllFiles(de.targetFile);
|
||||
if (successful) {
|
||||
ctx.getResourceManager().closeFile(de.targetFile.getName());
|
||||
}
|
||||
|
||||
|
@ -226,6 +227,8 @@ public class DownloadFileHelper {
|
|||
}
|
||||
if (de.type == DownloadActivityType.VOICE_FILE) {
|
||||
copyVoiceConfig(de);
|
||||
} else if (de.type == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||
removePreviousSrtmFile(de);
|
||||
}
|
||||
toReIndex.add(de.targetFile);
|
||||
return true;
|
||||
|
@ -238,6 +241,26 @@ public class DownloadFileHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void removePreviousSrtmFile(DownloadEntry entry) {
|
||||
String meterExt = IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
|
||||
String feetExt = IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT;
|
||||
|
||||
String fileName = entry.targetFile.getAbsolutePath();
|
||||
if (fileName.endsWith(meterExt)) {
|
||||
fileName = fileName.replace(meterExt, feetExt);
|
||||
} else if (fileName.endsWith(feetExt)) {
|
||||
fileName = fileName.replace(feetExt, meterExt);
|
||||
}
|
||||
|
||||
File previous = new File(fileName);
|
||||
if (previous != null && previous.exists()) {
|
||||
boolean successful = Algorithms.removeAllFiles(previous);
|
||||
if (successful) {
|
||||
ctx.getResourceManager().closeFile(previous.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyVoiceConfig(IndexItem.DownloadEntry de) {
|
||||
File f = ctx.getAppPath("/voice/" + de.baseName + "/_config.p");
|
||||
if (f.exists()) try {
|
||||
|
@ -401,8 +424,5 @@ public class DownloadFileHelper {
|
|||
count = 0;
|
||||
return last;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ public class MultipleDownloadItem extends DownloadItem {
|
|||
if (obj instanceof IndexItem) {
|
||||
return (IndexItem) obj;
|
||||
} else if (obj instanceof SrtmDownloadItem) {
|
||||
return ((SrtmDownloadItem) obj).getIndexItem();
|
||||
return ((SrtmDownloadItem) obj).getDefaultIndexItem();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue