/src/com/gmail/ianspigeon/applauncher/launchers/FileManagerLauncher.java

https://bitbucket.org/ianspigeon/applauncher · Java · 81 lines · 43 code · 38 blank · 0 comment · 7 complexity · e58539bc71ac57f45a8be869b65b0bda MD5 · raw file

  1. package com.gmail.ianspigeon.applauncher.launchers;
  2. import java.io.File;
  3. public class FileManagerLauncher extends Launcher {
  4. public String launch(String path) {
  5. System.out.println("FileManagerLauncher call detected." );
  6. try {
  7. validateParameter("path", path, "^[\\w.\\-_/]+$");
  8. } catch (Exception e) {
  9. return e.getMessage();
  10. }
  11. if (isWindows()) {
  12. try {
  13. if (directoryExists(path)) {
  14. path = path.replace("/", "\\"); // Convert to windows path separators
  15. return executeWindowsCommand(new String[] {"C:\\Windows\\explorer.exe", path});
  16. } else {
  17. return "Directory not found: " + path;
  18. }
  19. } catch ( SecurityException e ) {
  20. return "ERROR_NOT_PRIVILEGED";
  21. }
  22. } else if (isLinux()) {
  23. return executeLinuxCommand(new String[] {"/usr/bin/nautilus", "smb:" + path});
  24. } else {
  25. return "Unsupported platform, requires Windows or Linux.";
  26. }
  27. }
  28. private Boolean directoryExists(String path){
  29. final String fpath = path;
  30. Boolean result = java.security.AccessController.doPrivileged(
  31. new java.security.PrivilegedAction<Boolean>(){
  32. public Boolean run() {
  33. File directory = new File( fpath );
  34. if ( directory.exists() ) {
  35. return true;
  36. }
  37. return false;
  38. }
  39. }
  40. );
  41. return result;
  42. }
  43. }