< prev index next >

## src/java.desktop/windows/classes/sun/awt/shell/Win32ShellFolderManager2.java

Print this page

     430         if (dir != null && dir == getDrives()) {
     431             return true;
     432         } else {
     433             String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
     434                 public String run() {
     435                     return dir.getAbsolutePath();
     436                 }
     437             });
     438
     439             return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
     440         }
     441     }
     442
     443     public boolean isFileSystemRoot(File dir) {
     444         //Note: Removable drives don't "exist" but are listed in "My Computer"
     445         if (dir != null) {
     446
     447             if (dir instanceof Win32ShellFolder2) {
     448                 Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
     449

     450                 return (sf.isFileSystem() && sf.parent != null &&
     451                         sf.parent.equals(getDrives()));

     452             }
     453             String path = dir.getPath();
     454

     455             if (path.length() != 3 || path.charAt(1) != ':') {
     456                 return false;
     457             }
     458
     459             File[] roots = Win32ShellFolder2.listRoots();
     460
     461             return roots != null && Arrays.asList(roots).contains(dir);
     462         }
     463         return false;
     464     }
     465
     466     private static List<Win32ShellFolder2> topFolderList = null;
     467     static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) {
     468         boolean special1 = sf1.isSpecial();
     469         boolean special2 = sf2.isSpecial();
     470
     471         if (special1 || special2) {
     472             if (topFolderList == null) {
     473                 ArrayList<Win32ShellFolder2> tmpTopFolderList = new ArrayList<>();
     474                 tmpTopFolderList.add(Win32ShellFolderManager2.getPersonal());
     475                 tmpTopFolderList.add(Win32ShellFolderManager2.getDesktop());
     476                 tmpTopFolderList.add(Win32ShellFolderManager2.getDrives());
     477                 tmpTopFolderList.add(Win32ShellFolderManager2.getNetwork());
     478                 topFolderList = tmpTopFolderList;
     479             }
     480             int i1 = topFolderList.indexOf(sf1);
     481             int i2 = topFolderList.indexOf(sf2);
     482             if (i1 >= 0 && i2 >= 0) {
     483                 return (i1 - i2);
     430         if (dir != null && dir == getDrives()) {
     431             return true;
     432         } else {
     433             String path = AccessController.doPrivileged(new PrivilegedAction<String>() {
     434                 public String run() {
     435                     return dir.getAbsolutePath();
     436                 }
     437             });
     438
     439             return (path.startsWith("\\\\") && path.indexOf("\\", 2) < 0);      //Network path
     440         }
     441     }
     442
     443     public boolean isFileSystemRoot(File dir) {
     444         //Note: Removable drives don't "exist" but are listed in "My Computer"
     445         if (dir != null) {
     446
     447             if (dir instanceof Win32ShellFolder2) {
     448                 Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
     449
     450                 //This includes all the drives under "My PC" or "My Computer.
     451                 // On windows 10, "External Drives" are listed under "Desktop"
     452                 // also
     453                 return  (sf.isFileSystem() && sf.parent != null &&
     454                         (sf.parent.equals (getDrives()) ||
     455                         (sf.parent.equals (getDesktop()) && isDrive(dir))));
     456             }
     457             return isDrive(dir);
     458         }
     459         return false;
     460     }

     461
     462     private boolean isDrive(File dir) {
     463         String path = dir.getPath();
     464         if (path.length() != 3 || path.charAt(1) != ':') {
     465             return false;
     466         }

     467         File[] roots = Win32ShellFolder2.listRoots();

     468         return roots != null && Arrays.asList(roots).contains(dir);

     469     }
     470
     471     private static List<Win32ShellFolder2> topFolderList = null;
     472     static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) {
     473         boolean special1 = sf1.isSpecial();
     474         boolean special2 = sf2.isSpecial();
     475
     476         if (special1 || special2) {
     477             if (topFolderList == null) {
     478                 ArrayList<Win32ShellFolder2> tmpTopFolderList = new ArrayList<>();
     479                 tmpTopFolderList.add(Win32ShellFolderManager2.getPersonal());
     480                 tmpTopFolderList.add(Win32ShellFolderManager2.getDesktop());
     481                 tmpTopFolderList.add(Win32ShellFolderManager2.getDrives());
     482                 tmpTopFolderList.add(Win32ShellFolderManager2.getNetwork());
     483                 topFolderList = tmpTopFolderList;
     484             }
     485             int i1 = topFolderList.indexOf(sf1);
     486             int i2 = topFolderList.indexOf(sf2);
     487             if (i1 >= 0 && i2 >= 0) {
     488                 return (i1 - i2);

< prev index next >