/**
   * Returns the parent directory of <code>dir</code>.
   *
   * @param dir the <code>File</code> being queried
   * @return the parent directory of <code>dir</code>, or <code>null</code> if <code>dir</code> is
   *     <code>null</code>
   */
  public File getParentDirectory(File dir) {
    if (dir == null || !dir.exists()) {
      return null;
    }

    ShellFolder sf;

    try {
      sf = getShellFolder(dir);
    } catch (FileNotFoundException e) {
      return null;
    }

    File psf = sf.getParentFile();

    if (psf == null) {
      return null;
    }

    if (isFileSystem(psf)) {
      File f = psf;
      if (!f.exists()) {
        // This could be a node under "Network Neighborhood".
        File ppsf = psf.getParentFile();
        if (ppsf == null || !isFileSystem(ppsf)) {
          // We're mostly after the exists() override for windows below.
          f = createFileSystemRoot(f);
        }
      }
      return f;
    } else {
      return psf;
    }
  }