Esempio n. 1
0
  private void deleteLocation(LocationInfo info) {
    if (NavigineApp.Navigation == null) return;

    if (info != null) {
      try {
        (new File(info.archiveFile)).delete();
        info.localVersion = -1;
        info.localModified = false;

        String locationDir = LocationLoader.getLocationDir(mContext, info.title);
        File dir = new File(locationDir);
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; ++i) files[i].delete();
        dir.delete();

        String mapFile = NavigineApp.Settings.getString("map_file", "");
        if (mapFile.equals(info.archiveFile)) {
          NavigineApp.Navigation.loadArchive(null);
          SharedPreferences.Editor editor = NavigineApp.Settings.edit();
          editor.putString("map_file", "");
          editor.commit();
        }

        mAdapter.updateList();
      } catch (Throwable e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }
  }
Esempio n. 2
0
  /*
   * Deletes the file at the location passed. If the location is a
   * directory the method will return false.
   * Returns true if and only if the file was deleted;
   * returns false otherwise
   */
  public static boolean deleteFile(File file) {
    if (file.isFile()) {
      if (file.delete()) {
        return true;
      }
    }

    return false;
  }
Esempio n. 3
0
 void removeFiles() throws IOException {
   BufferedReader reader = new BufferedReader(new FileReader(new File(sGREDir, "removed-files")));
   try {
     for (String removedFileName = reader.readLine();
         removedFileName != null;
         removedFileName = reader.readLine()) {
       File removedFile = new File(sGREDir, removedFileName);
       if (removedFile.exists()) removedFile.delete();
     }
   } finally {
     reader.close();
   }
 }
Esempio n. 4
0
  /*
   * Deletes the directory at the location passed. If deleteIfFull is true
   * then the method gets all the files in the directory and tries to delete
   * them. If deleteIfFull is false the method will attempt to delete the
   * directory. If the directory contains files, the method will return false.
   * Returns true if and only if the directory was deleted;
   * returns false otherwise
   */
  public static boolean deleteDirectory(File dir, boolean deleteIfFull) {
    // Checks if the file exists and if it is actually a directory
    if (dir.exists() && dir.isDirectory()) {
      // Checks if deleteIfFull is true
      if (deleteIfFull) {
        // Goes through each file in the directory and attempts to delete them
        File[] files = dir.listFiles();
        if (files != null) {
          for (File f : files) {
            f.delete();
          }
        }
      }
      // If the directory was deleted successfully then return true
      if (dir.delete()) {
        return true;
      }
    }

    // Return false otherwise
    return false;
  }