@Override protected String doInBackground(String... filesToDownload) { try { List<File> filesToReindex = new ArrayList<File>(); boolean forceWifi = downloadFileHelper.isWifiConnected(); for (int i = 0; i < filesToDownload.length; i++) { String filename = filesToDownload[i]; DownloadEntry entry = entriesToDownload.get(filename); if (entry != null) { String indexOfAllFiles = filesToDownload.length <= 1 ? "" : (" [" + (i + 1) + "/" + filesToDownload.length + "]"); boolean result = entry.downloadFile( downloadFileHelper, filename, filesToReindex, progress, indexOfAllFiles, this, forceWifi, getAssets()); if (result) { entriesToDownload.remove(filename); downloads.set(downloads.get() + 1); if (entry.existingBackupFile != null) { Algoritms.removeAllFiles(entry.existingBackupFile); } publishProgress(entry); } } } boolean vectorMapsToReindex = false; for (File f : filesToReindex) { if (f.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { vectorMapsToReindex = true; break; } } // reindex vector maps all at one time ResourceManager manager = getMyApplication().getResourceManager(); manager.indexVoiceFiles(progress); if (vectorMapsToReindex) { List<String> warnings = manager.indexingMaps(progress); if (!warnings.isEmpty()) { return warnings.get(0); } } } catch (InterruptedException e) { // do not dismiss dialog } finally { if (progressFileDlg != null) { removeDialog(DIALOG_PROGRESS_FILE); progressFileDlg = null; } } return null; }
private DownloadJob buildJob(Cursor cursor) { DownloadEntry entry = new DownloadEntry(); entry.aid = cursor.getString(cursor.getColumnIndex(COLUMN_AID)); entry.title = cursor.getString(cursor.getColumnIndex(COLUMN_TITLE)); entry.destination = cursor.getString(cursor.getColumnIndex(COLUMN_DEST)); entry.part = new VideoPart(); entry.part.vid = cursor.getString(cursor.getColumnIndex(COLUMN_VID)); entry.part.subtitle = cursor.getString(cursor.getColumnIndex(COLUMN_SUBTITLE)); entry.part.vtype = cursor.getString(cursor.getColumnIndex(COLUMN_VTYPE)); entry.part.segments = new ArrayList<VideoSegment>(); DownloadJob job = new DownloadJob(entry); job.setUserAgent(cursor.getString(cursor.getColumnIndex(COLUMN_UA))); int status = cursor.getInt(cursor.getColumnIndex(COLUMN_STATUS)); job.setStatus(status); entry.part.isDownloaded = status == STATUS_SUCCESS; return job; }
private DownloadEntry createDownloadEntry(IndexItem item) { String fileName = item.getFileName(); File parent = null; String toSavePostfix = null; String toCheckPostfix = null; boolean unzipDir = false; File externalStorageDirectory = OsmandSettings.getOsmandSettings(getApplicationContext()).getExternalStorageDirectory(); if (fileName.endsWith(IndexConstants.POI_INDEX_EXT)) { parent = new File(externalStorageDirectory, ResourceManager.POI_PATH); toSavePostfix = POI_INDEX_EXT; toCheckPostfix = POI_INDEX_EXT; } else if (fileName.endsWith(IndexConstants.POI_INDEX_EXT_ZIP)) { parent = new File(externalStorageDirectory, ResourceManager.POI_PATH); toSavePostfix = POI_INDEX_EXT_ZIP; toCheckPostfix = POI_INDEX_EXT; } else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { parent = new File(externalStorageDirectory, ResourceManager.APP_DIR); toSavePostfix = BINARY_MAP_INDEX_EXT; toCheckPostfix = BINARY_MAP_INDEX_EXT; } else if (fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) { parent = new File(externalStorageDirectory, ResourceManager.APP_DIR); toSavePostfix = BINARY_MAP_INDEX_EXT_ZIP; toCheckPostfix = BINARY_MAP_INDEX_EXT; } else if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { parent = new File(externalStorageDirectory, ResourceManager.VOICE_PATH); toSavePostfix = VOICE_INDEX_EXT_ZIP; toCheckPostfix = ""; // $NON-NLS-1$ unzipDir = true; } else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) { parent = new File(externalStorageDirectory, ResourceManager.VOICE_PATH); toSavePostfix = TTSVOICE_INDEX_EXT_ZIP; toCheckPostfix = ""; // $NON-NLS-1$ unzipDir = true; } if (parent != null) { parent.mkdirs(); } final DownloadEntry entry; if (parent == null || !parent.exists()) { Toast.makeText( DownloadIndexActivity.this, getString(R.string.sd_dir_not_accessible), Toast.LENGTH_LONG) .show(); entry = null; } else { entry = new DownloadEntry(); int ls = fileName.lastIndexOf('_'); entry.baseName = fileName.substring(0, ls); entry.fileToSave = new File(parent, entry.baseName + toSavePostfix); entry.unzip = unzipDir; SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy"); // $NON-NLS-1$ try { Date d = format.parse(item.getDate()); entry.dateModified = d.getTime(); } catch (ParseException e1) { } try { entry.sizeMB = Double.parseDouble(item.getSize()); } catch (NumberFormatException e1) { } entry.parts = 1; if (item.getParts() != null) { entry.parts = Integer.parseInt(item.getParts()); } entry.fileToUnzip = new File(parent, entry.baseName + toCheckPostfix); } return entry; }