Merge pull request #11482 from osmandapp/FixSrtmDialogs
Remove srtm file of other type after new downloaded
This commit is contained in:
commit
c3818d6121
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.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
|
import net.osmand.plus.download.IndexItem.DownloadEntry;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
@ -199,33 +200,35 @@ public class DownloadFileHelper {
|
||||||
public boolean isWifiConnected(){
|
public boolean isWifiConnected(){
|
||||||
return ctx.getSettings().isWifiConnected();
|
return ctx.getSettings().isWifiConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean downloadFile(IndexItem.DownloadEntry de, IProgress progress,
|
public boolean downloadFile(IndexItem.DownloadEntry de, IProgress progress,
|
||||||
List<File> toReIndex, DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
List<File> toReIndex, DownloadFileShowWarning showWarningCallback, boolean forceWifi) throws InterruptedException {
|
||||||
try {
|
try {
|
||||||
final List<InputStream> downloadInputStreams = new ArrayList<InputStream>();
|
final List<InputStream> downloadInputStreams = new ArrayList<InputStream>();
|
||||||
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
URL url = new URL(de.urlToDownload); //$NON-NLS-1$
|
||||||
log.info("Url downloading " + de.urlToDownload);
|
log.info("Url downloading " + de.urlToDownload);
|
||||||
downloadInputStreams.add(getInputStreamToDownload(url, forceWifi));
|
downloadInputStreams.add(getInputStreamToDownload(url, forceWifi));
|
||||||
de.fileToDownload = de.targetFile;
|
de.fileToDownload = de.targetFile;
|
||||||
if(!de.unzipFolder) {
|
if (!de.unzipFolder) {
|
||||||
de.fileToDownload = new File(de.targetFile.getParentFile(), de.targetFile.getName() +".download");
|
de.fileToDownload = new File(de.targetFile.getParentFile(), de.targetFile.getName() + ".download");
|
||||||
}
|
}
|
||||||
unzipFile(de, progress, downloadInputStreams);
|
unzipFile(de, progress, downloadInputStreams);
|
||||||
if(!de.targetFile.getAbsolutePath().equals(de.fileToDownload.getAbsolutePath())){
|
if (!de.targetFile.getAbsolutePath().equals(de.fileToDownload.getAbsolutePath())) {
|
||||||
boolean successfull = Algorithms.removeAllFiles(de.targetFile);
|
boolean successful = Algorithms.removeAllFiles(de.targetFile);
|
||||||
if (successfull) {
|
if (successful) {
|
||||||
ctx.getResourceManager().closeFile(de.targetFile.getName());
|
ctx.getResourceManager().closeFile(de.targetFile.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean renamed = de.fileToDownload.renameTo(de.targetFile);
|
boolean renamed = de.fileToDownload.renameTo(de.targetFile);
|
||||||
if(!renamed) {
|
if (!renamed) {
|
||||||
showWarningCallback.showWarning(ctx.getString(R.string.shared_string_io_error) + ": old file can't be deleted");
|
showWarningCallback.showWarning(ctx.getString(R.string.shared_string_io_error) + ": old file can't be deleted");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (de.type == DownloadActivityType.VOICE_FILE){
|
if (de.type == DownloadActivityType.VOICE_FILE) {
|
||||||
copyVoiceConfig(de);
|
copyVoiceConfig(de);
|
||||||
|
} else if (de.type == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
|
removePreviousSrtmFile(de);
|
||||||
}
|
}
|
||||||
toReIndex.add(de.targetFile);
|
toReIndex.add(de.targetFile);
|
||||||
return true;
|
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) {
|
private void copyVoiceConfig(IndexItem.DownloadEntry de) {
|
||||||
File f = ctx.getAppPath("/voice/" + de.baseName + "/_config.p");
|
File f = ctx.getAppPath("/voice/" + de.baseName + "/_config.p");
|
||||||
if (f.exists()) try {
|
if (f.exists()) try {
|
||||||
|
@ -386,23 +409,20 @@ public class DownloadFileHelper {
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int available() throws IOException {
|
public int available() throws IOException {
|
||||||
int av = 0;
|
int av = 0;
|
||||||
for(int i = currentRead; i < delegate.length; i++) {
|
for (int i = currentRead; i < delegate.length; i++) {
|
||||||
av += delegate[i].available();
|
av += delegate[i].available();
|
||||||
}
|
}
|
||||||
return av;
|
return av;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAndClearReadCount() {
|
public int getAndClearReadCount() {
|
||||||
int last = count;
|
int last = count;
|
||||||
count = 0;
|
count = 0;
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class MultipleDownloadItem extends DownloadItem {
|
||||||
if (obj instanceof IndexItem) {
|
if (obj instanceof IndexItem) {
|
||||||
return (IndexItem) obj;
|
return (IndexItem) obj;
|
||||||
} else if (obj instanceof SrtmDownloadItem) {
|
} else if (obj instanceof SrtmDownloadItem) {
|
||||||
return ((SrtmDownloadItem) obj).getIndexItem();
|
return ((SrtmDownloadItem) obj).getDefaultIndexItem();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue