@Override
 protected String doInBackground(LocalIndexInfo... params) {
   int count = 0;
   int total = 0;
   for (LocalIndexInfo info : params) {
     if (!isCancelled()) {
       String warning = null;
       try {
         File file = new File(info.getPathToData());
         String userName = settings.USER_NAME.get();
         String pwd = settings.USER_PASSWORD.get();
         String url =
             URL_TO_UPLOAD_GPX
                 + "?author="
                 + URLEncoder.encode(userName, "UTF-8")
                 + "&wd="
                 + URLEncoder.encode(pwd, "UTF-8")
                 + "&file="
                 + URLEncoder.encode(file.getName(), "UTF-8");
         warning = Algoritms.uploadFile(url, file, "filename", true);
       } catch (UnsupportedEncodingException e) {
         warning = e.getMessage();
       }
       total++;
       if (warning == null) {
         count++;
       } else {
         publishProgress(warning);
       }
     }
   }
   return getString(R.string.local_index_items_uploaded, count, total);
 }
 private File getFileToRestore(LocalIndexInfo i) {
   if (i.isBackupedData()) {
     File parent = new File(i.getPathToData()).getParentFile();
     if (i.getType() == LocalIndexType.GPX_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.GPX_PATH);
     } else if (i.getType() == LocalIndexType.MAP_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.MAPS_PATH);
     } else if (i.getType() == LocalIndexType.POI_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.POI_PATH);
     } else if (i.getType() == LocalIndexType.TILES_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.TILES_PATH);
     } else if (i.getType() == LocalIndexType.VOICE_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.VOICE_PATH);
     } else if (i.getType() == LocalIndexType.TTS_VOICE_DATA) {
       parent = settings.extendOsmandPath(ResourceManager.VOICE_PATH);
     }
     return new File(parent, i.getFileName());
   }
   return new File(i.getPathToData());
 }
    @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 "";
    }
  private void renameFile(LocalIndexInfo info) {
    final File f = new File(info.getPathToData());
    Builder b = new AlertDialog.Builder(this);
    if (f.exists()) {
      final EditText editText = new EditText(this);
      editText.setText(f.getName());
      b.setView(editText);
      b.setPositiveButton(
          R.string.default_buttons_save,
          new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
              String newName = editText.getText().toString();
              File dest = new File(f.getParentFile(), newName);
              if (dest.exists()) {
                Toast.makeText(
                        LocalIndexesActivity.this,
                        R.string.file_with_name_already_exists,
                        Toast.LENGTH_LONG)
                    .show();
              } else {
                if (f.renameTo(dest)) {
                  asyncLoader = new LoadLocalIndexTask();
                  asyncLoader.execute(LocalIndexesActivity.this);
                  reloadIndexes();
                } else {
                  Toast.makeText(
                          LocalIndexesActivity.this,
                          R.string.file_can_not_be_renamed,
                          Toast.LENGTH_LONG)
                      .show();
                }
              }
            }
          });
      b.setNegativeButton(R.string.default_buttons_cancel, null);
      b.show();
    }
  }
 private File getFileToBackup(LocalIndexInfo i) {
   if (!i.isBackupedData()) {
     return new File(settings.extendOsmandPath(ResourceManager.BACKUP_PATH), i.getFileName());
   }
   return new File(i.getPathToData());
 }