コード例 #1
0
  public static boolean isSubtitlesExists(File file, DLNAMediaInfo media, boolean usecache) {
    boolean found = false;
    if (file.exists()) {
      found = browseFolderForSubtitles(file.getParentFile(), file, media, usecache);
    }
    String alternate = PMS.getConfiguration().getAlternateSubtitlesFolder();

    if (isNotBlank(alternate)) { // https://code.google.com/p/ps3mediaserver/issues/detail?id=737#c5
      File subFolder = new File(alternate);

      if (!subFolder.isAbsolute()) {
        subFolder = new File(file.getParent() + "/" + alternate);
        try {
          subFolder = subFolder.getCanonicalFile();
        } catch (IOException e) {
          LOGGER.debug("Caught exception", e);
        }
      }

      if (subFolder.exists()) {
        found = found || browseFolderForSubtitles(subFolder, file, media, usecache);
      }
    }

    return found;
  }
コード例 #2
0
  // this is called from a static initialiser, where errors aren't clearly reported,
  // so do everything possible to return a valid reponse, even if the parameters
  // aren't sane
  public static FileLocation getFileLocation(
      String customPath, String defaultDirectory, String defaultBasename) {
    File customFile = null;
    File directory = null;
    File file = null;

    if (isBlank(defaultBasename)) {
      // shouldn't get here
      defaultBasename = DEFAULT_BASENAME;
    }

    if (defaultDirectory == null) {
      defaultDirectory = ""; // current directory
    }

    if (customPath != null) {
      customFile = new File(customPath).getAbsoluteFile();
    }

    if (customFile != null) {
      if (customFile.exists()) {
        if (customFile.isDirectory()) {
          directory = customFile;
          file = new File(customFile, defaultBasename).getAbsoluteFile();
        } else {
          directory = customFile.getParentFile();
          file = customFile;
        }
      } else {
        File parentDirectoryFile = customFile.getParentFile();
        if (parentDirectoryFile != null && parentDirectoryFile.exists()) {
          // parent directory exists: the file can be created
          directory = parentDirectoryFile;
          file = customFile;
        }
      }
    }

    if (directory == null || file == null) {
      directory = new File(defaultDirectory).getAbsoluteFile();
      file = new File(directory, defaultBasename).getAbsoluteFile();
    }

    return new FileLocation(directory, file);
  }
コード例 #3
0
  public static File isFileExists(File f, String ext) {
    int point = f.getName().lastIndexOf('.');

    if (point == -1) {
      point = f.getName().length();
    }

    File lowerCasedFile =
        new File(f.getParentFile(), f.getName().substring(0, point) + "." + ext.toLowerCase());
    if (lowerCasedFile.exists()) {
      return lowerCasedFile;
    }

    File upperCasedFile =
        new File(f.getParentFile(), f.getName().substring(0, point) + "." + ext.toUpperCase());
    if (upperCasedFile.exists()) {
      return upperCasedFile;
    }

    return null;
  }