Esempio n. 1
0
 public void removeDatabase(File file) {
   if (DBDialect.H2 == this) {
     File[] list = file.getParentFile().listFiles();
     for (File f : list) {
       if (f.getName().startsWith(file.getName())) {
         Algoritms.removeAllFiles(f);
       }
     }
   } else {
     Algoritms.removeAllFiles(file);
   }
 }
 @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;
 }
    @Override
    protected String doInBackground(LocalIndexInfo... params) {
      int count = 0;
      int total = 0;
      for (LocalIndexInfo info : params) {
        if (!isCancelled()) {
          boolean successfull = false;
          if (operation == DELETE_OPERATION) {
            File f = new File(info.getPathToData());
            successfull = Algoritms.removeAllFiles(f);
          } else if (operation == RESTORE_OPERATION) {
            successfull = move(new File(info.getPathToData()), getFileToRestore(info));
            if (successfull) {
              info.setBackupedData(false);
            }
          } else if (operation == BACKUP_OPERATION) {
            successfull = move(new File(info.getPathToData()), getFileToBackup(info));
            if (successfull) {
              info.setBackupedData(true);
            }
          }
          total++;
          if (successfull) {
            count++;
            publishProgress(info);
          }
        }
      }
      if (operation == DELETE_OPERATION) {
        return getString(R.string.local_index_items_deleted, count, total);
      } else if (operation == BACKUP_OPERATION) {
        return getString(R.string.local_index_items_backuped, count, total);
      } else if (operation == RESTORE_OPERATION) {
        return getString(R.string.local_index_items_restored, count, total);
      }

      return "";
    }