Esempio n. 1
0
 /**
  * Resolves the user Trash folder and its "info" and "files" subfolders once and for all. The
  * trash folder is created if it doesn't already exist.
  */
 static {
   TRASH_FOLDER = getTrashFolder();
   if (TRASH_FOLDER != null) {
     TRASH_INFO_SUBFOLDER = TRASH_FOLDER.getChildSilently("info");
     TRASH_FILES_SUBFOLDER = TRASH_FOLDER.getChildSilently("files");
     TRASH_VOLUME = TRASH_FOLDER.getVolume();
   } else {
     TRASH_INFO_SUBFOLDER = null;
     TRASH_FILES_SUBFOLDER = null;
     TRASH_VOLUME = null;
   }
 }
Esempio n. 2
0
  /**
   * Tries to find an existing user Trash folder and returns it. If no existing Trash folder was
   * found, creates the standard Xfce user Trash folder and returns it.
   *
   * @return the user Trash folder, <code>null</code> if no user trash folder could be found or
   *     created
   */
  private static AbstractFile getTrashFolder() {
    AbstractFile userHome = LocalFile.getUserHome();

    AbstractFile trashDir = userHome.getChildSilently(".local/share/Trash/");
    if (isTrashFolder(trashDir)) {
      return trashDir;
    }

    // No existing user trash was found: create the folder, only if it doesn't already exist.
    if (!trashDir.exists()) {
      try {
        trashDir.mkdirs();
        trashDir.getChild("info").mkdir();
        trashDir.getChild("files").mkdir();

        return trashDir;
      } catch (IOException e) {
        // Will return null
      }
    }

    return null;
  }