426 * Does {@code dir} represent a "computer" such as a node on the network, or
427 * "My Computer" on the desktop.
428 */
429 public boolean isComputerNode(final File dir) {
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 Win32ShellFolder2 drives = getDrives();
447 if (dir instanceof Win32ShellFolder2) {
448 Win32ShellFolder2 sf = (Win32ShellFolder2)dir;
449 if (sf.isFileSystem()) {
450 if (sf.parent != null) {
451 return sf.parent.equals(drives);
452 }
453 // else fall through ...
454 } else {
455 return false;
456 }
457 }
458 String path = dir.getPath();
459
460 if (path.length() != 3 || path.charAt(1) != ':') {
461 return false;
462 }
463
464 File[] files = drives.listFiles();
465
466 return files != null && Arrays.asList(files).contains(dir);
467 }
468 return false;
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);
544 final Runnable comRun = new Runnable() {
545 public void run() {
546 try {
547 initializeCom();
548 task.run();
549 } finally {
550 uninitializeCom();
551 }
552 }
553 };
554 comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
555 String name = "Swing-Shell";
556 /* The thread must be a member of a thread group
557 * which will not get GCed before VM exit.
558 * Make its parent the top-level thread group.
559 */
560 Thread thread = new Thread(
561 ThreadGroupUtils.getRootThreadGroup(), comRun, name,
562 0, false);
563 thread.setDaemon(true);
564 return thread;
565 });
566 return comThread;
567 }
568
569 public <T> T invoke(Callable<T> task) throws Exception {
570 if (Thread.currentThread() == comThread) {
571 // if it's already called from the COM
572 // thread, we don't need to delegate the task
573 return task.call();
574 } else {
575 final Future<T> future;
576
577 try {
578 future = submit(task);
579 } catch (RejectedExecutionException e) {
580 throw new InterruptedException(e.getMessage());
581 }
582
583 try {
|
426 * Does {@code dir} represent a "computer" such as a node on the network, or
427 * "My Computer" on the desktop.
428 */
429 public boolean isComputerNode(final File dir) {
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(Win32ShellFolder2.listRoots()));
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);
539 final Runnable comRun = new Runnable() {
540 public void run() {
541 try {
542 initializeCom();
543 task.run();
544 } finally {
545 uninitializeCom();
546 }
547 }
548 };
549 comThread = AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {
550 String name = "Swing-Shell";
551 /* The thread must be a member of a thread group
552 * which will not get GCed before VM exit.
553 * Make its parent the top-level thread group.
554 */
555 Thread thread = new Thread(
556 ThreadGroupUtils.getRootThreadGroup(), comRun, name,
557 0, false);
558 thread.setDaemon(true);
559 /* This is important, since this thread running at lower priority
560 leads to memory consumption when listDrives() function is called
561 repeatedly.
562 */
563 thread.setPriority(Thread.MAX_PRIORITY);
564 return thread;
565 });
566 return comThread;
567 }
568
569 public <T> T invoke(Callable<T> task) throws Exception {
570 if (Thread.currentThread() == comThread) {
571 // if it's already called from the COM
572 // thread, we don't need to delegate the task
573 return task.call();
574 } else {
575 final Future<T> future;
576
577 try {
578 future = submit(task);
579 } catch (RejectedExecutionException e) {
580 throw new InterruptedException(e.getMessage());
581 }
582
583 try {
|