Update CachedOsmandIndexes after map download

This commit is contained in:
Vitaliy 2021-01-06 00:30:00 +02:00
parent f27c397835
commit 37bfc759b1
3 changed files with 15 additions and 11 deletions

View file

@ -1,11 +1,5 @@
package net.osmand.binary; package net.osmand.binary;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion; import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock; import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock;
@ -29,6 +23,12 @@ import net.osmand.binary.OsmandIndex.TransportPart;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
public class CachedOsmandIndexes { public class CachedOsmandIndexes {
private OsmAndStoredIndex storedIndex; private OsmAndStoredIndex storedIndex;
@ -174,10 +174,10 @@ public class CachedOsmandIndexes {
routing.addSubregions(rpart); routing.addSubregions(rpart);
} }
public BinaryMapIndexReader getReader(File f) throws IOException { public BinaryMapIndexReader getReader(File f, boolean useStoredIndex) throws IOException {
RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r"); RandomAccessFile mf = new RandomAccessFile(f.getPath(), "r");
FileIndex found = null; FileIndex found = null;
if (storedIndex != null) { if (storedIndex != null && useStoredIndex) {
for (int i = 0; i < storedIndex.getFileIndexCount(); i++) { for (int i = 0; i < storedIndex.getFileIndexCount(); i++) {
FileIndex fi = storedIndex.getFileIndex(i); FileIndex fi = storedIndex.getFileIndex(i);
if (f.length() == fi.getSize() && f.getName().equals(fi.getFileName())) { if (f.length() == fi.getSize() && f.getName().equals(fi.getFileName())) {

View file

@ -576,7 +576,7 @@ public class DownloadIndexesThread {
manager.indexVoiceFiles(this); manager.indexVoiceFiles(this);
manager.indexFontFiles(this); manager.indexFontFiles(this);
if (vectorMapsToReindex) { if (vectorMapsToReindex) {
warnings = manager.indexingMaps(this); warnings = manager.indexingMaps(this, filesToReindex);
} }
List<String> wns = manager.indexAdditionalMaps(this); List<String> wns = manager.indexAdditionalMaps(this);
if (wns != null) { if (wns != null) {

View file

@ -621,7 +621,11 @@ public class ResourceManager {
} }
} }
public List<String> indexingMaps(final IProgress progress) { public List<String> indexingMaps(IProgress progress) {
return indexingMaps(progress, Collections.<File>emptyList());
}
public List<String> indexingMaps(final IProgress progress, List<File> filesToReindex) {
long val = System.currentTimeMillis(); long val = System.currentTimeMillis();
ArrayList<File> files = new ArrayList<File>(); ArrayList<File> files = new ArrayList<File>();
File appPath = context.getAppPath(null); File appPath = context.getAppPath(null);
@ -688,7 +692,7 @@ public class ResourceManager {
try { try {
BinaryMapIndexReader mapReader = null; BinaryMapIndexReader mapReader = null;
try { try {
mapReader = cachedOsmandIndexes.getReader(f); mapReader = cachedOsmandIndexes.getReader(f, !filesToReindex.contains(f));
if (mapReader.getVersion() != IndexConstants.BINARY_MAP_VERSION) { if (mapReader.getVersion() != IndexConstants.BINARY_MAP_VERSION) {
mapReader = null; mapReader = null;
} }