Add file indexing differently
This commit is contained in:
parent
417042f673
commit
6c7fdd1b72
1 changed files with 4 additions and 20 deletions
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
@ -24,7 +23,6 @@ import net.osmand.LogUtil;
|
||||||
import net.osmand.Version;
|
import net.osmand.Version;
|
||||||
import net.osmand.data.IndexConstants;
|
import net.osmand.data.IndexConstants;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.ResourceManager;
|
|
||||||
|
|
||||||
public class DownloadFileHelper {
|
public class DownloadFileHelper {
|
||||||
|
|
||||||
|
@ -152,11 +150,8 @@ public class DownloadFileHelper {
|
||||||
out = null;
|
out = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
File toIndex = fileToDownload;
|
|
||||||
if (fileToDownload.getName().endsWith(".zip")) { //$NON-NLS-1$
|
if (fileToDownload.getName().endsWith(".zip")) { //$NON-NLS-1$
|
||||||
if (!unzipToDir) {
|
if (unzipToDir) {
|
||||||
toIndex = fileToUnZip;
|
|
||||||
} else {
|
|
||||||
fileToUnZip.mkdirs();
|
fileToUnZip.mkdirs();
|
||||||
}
|
}
|
||||||
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(fileToDownload));
|
ZipInputStream zipIn = new ZipInputStream(new FileInputStream(fileToDownload));
|
||||||
|
@ -171,7 +166,7 @@ public class DownloadFileHelper {
|
||||||
File fs;
|
File fs;
|
||||||
if (!unzipToDir) {
|
if (!unzipToDir) {
|
||||||
if (first) {
|
if (first) {
|
||||||
fs = toIndex;
|
fs = fileToUnZip;
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
String name = entry.getName();
|
String name = entry.getName();
|
||||||
|
@ -185,7 +180,6 @@ public class DownloadFileHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fs = new File(fileToUnZip.getParent(), name);
|
fs = new File(fileToUnZip.getParent(), name);
|
||||||
toIndex = fs;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fs = new File(fileToUnZip, entry.getName());
|
fs = new File(fileToUnZip, entry.getName());
|
||||||
|
@ -202,23 +196,13 @@ public class DownloadFileHelper {
|
||||||
if(dateModified != null){
|
if(dateModified != null){
|
||||||
fs.setLastModified(dateModified);
|
fs.setLastModified(dateModified);
|
||||||
}
|
}
|
||||||
|
toReIndex.add(fs);
|
||||||
}
|
}
|
||||||
zipIn.close();
|
zipIn.close();
|
||||||
fileToDownload.delete(); // zip is no needed more
|
fileToDownload.delete(); // zip is no needed more
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<String> warnings = new ArrayList<String>();
|
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
|
||||||
ResourceManager manager = ((OsmandApplication) ctx.getApplicationContext()).getResourceManager();
|
|
||||||
if(dateModified != null){
|
|
||||||
toIndex.setLastModified(dateModified);
|
|
||||||
manager.updateIndexLastDateModified(toIndex);
|
|
||||||
}
|
|
||||||
toReIndex.add(toIndex);
|
|
||||||
if (warnings.isEmpty()) {
|
|
||||||
showWarningCallback.showWarning(ctx.getString(R.string.download_index_success));
|
|
||||||
} else {
|
|
||||||
showWarningCallback.showWarning(warnings.get(0));
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Exception ocurred", e); //$NON-NLS-1$
|
log.error("Exception ocurred", e); //$NON-NLS-1$
|
||||||
|
|
Loading…
Reference in a new issue