diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 8c71b3416..b4b07b2a7 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -31,6 +31,7 @@ import javax.swing.UIManager; import com.sun.jna.Library; import com.sun.jna.Native; +import com.sun.jna.platform.FileUtils; /** @@ -152,13 +153,19 @@ public class Platform { * @return true if the folder was successfully removed * @throws IOException */ - public boolean deleteFile(File file) throws IOException { - if (file.isDirectory()) { + final public boolean deleteFile(File file) throws IOException { + FileUtils fu = FileUtils.getInstance(); + if (fu.hasTrash()) { + fu.moveToTrash(new File[] { file }); + return true; + + } else if (file.isDirectory()) { Base.removeDir(file); + return true; + } else { return file.delete(); } - return true; } diff --git a/app/src/processing/app/macosx/Platform.java b/app/src/processing/app/macosx/Platform.java index 8cc71a38d..c09f2b55a 100644 --- a/app/src/processing/app/macosx/Platform.java +++ b/app/src/processing/app/macosx/Platform.java @@ -24,7 +24,6 @@ package processing.app.macosx; import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; import com.apple.eio.FileManager; @@ -104,13 +103,13 @@ public class Platform extends processing.app.Platform { } - /** - * Moves the specified File object (which might be a file or folder) - * to the trash. - */ - public boolean deleteFile(File file) throws IOException { - return FileManager.moveToTrash(file); - } +// /** +// * Moves the specified File object (which might be a file or folder) +// * to the trash. +// */ +// public boolean deleteFile(File file) throws IOException { +// return FileManager.moveToTrash(file); +// } /* diff --git a/app/src/processing/app/windows/Platform.java b/app/src/processing/app/windows/Platform.java index c5325fb17..a47662c38 100644 --- a/app/src/processing/app/windows/Platform.java +++ b/app/src/processing/app/windows/Platform.java @@ -28,11 +28,8 @@ import java.io.UnsupportedEncodingException; import com.sun.jna.Library; import com.sun.jna.Native; -import com.sun.jna.WString; import com.sun.jna.platform.win32.Kernel32Util; import com.sun.jna.platform.win32.Shell32; -import com.sun.jna.platform.win32.ShellAPI; -import com.sun.jna.platform.win32.ShellAPI.SHFILEOPSTRUCT; import com.sun.jna.platform.win32.ShlObj; import com.sun.jna.platform.win32.WinDef; import com.sun.jna.platform.win32.WinError; @@ -74,15 +71,17 @@ public class Platform extends processing.app.Platform { //checkQuickTime(); checkPath(); - /* File f = new File("C:\\recycle-test.txt"); System.out.println(f.getAbsolutePath()); java.io.PrintWriter writer = PApplet.createWriter(f); writer.println("blah"); writer.flush(); writer.close(); - deleteFile(f); - */ + try { + deleteFile(f); + } catch (IOException e) { + e.printStackTrace(); + } //findJDK(); /* @@ -333,53 +332,53 @@ public class Platform extends processing.app.Platform { } - @Override - public boolean deleteFile(File file) { - try { - moveToTrash(new File[] { file }); - } catch (IOException e) { - e.printStackTrace(); - Base.log("Could not move " + file.getAbsolutePath() + " to the trash.", e); - return false; - } - return true; - } +// @Override +// public boolean deleteFile(File file) { +// try { +// moveToTrash(new File[] { file }); +// } catch (IOException e) { +// e.printStackTrace(); +// Base.log("Could not move " + file.getAbsolutePath() + " to the trash.", e); +// return false; +// } +// return true; +// } - /** - * Move files/folders to the trash. If this file is on another file system - * or on a shared network directory, it will simply be deleted without any - * additional confirmation. Take that. - *

- * Based on JNA source for com.sun.jna.platform.win32.W32FileUtils - * - * @param files array of File objects to be removed - * @return true if no error codes returned - * @throws IOException if something bad happened along the way - */ - static private boolean moveToTrash(File[] files) throws IOException { - Shell32 shell = Shell32.INSTANCE; - SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT(); - fileop.wFunc = ShellAPI.FO_DELETE; - String[] paths = new String[files.length]; - for (int i = 0; i < paths.length; i++) { - paths[i] = files[i].getAbsolutePath(); - System.out.println(paths[i]); - } - fileop.pFrom = new WString(fileop.encodePaths(paths)); - fileop.fFlags = ShellAPI.FOF_ALLOWUNDO | ShellAPI.FOF_NO_UI; - int ret = shell.SHFileOperation(fileop); - if (ret != 0) { - throw new IOException("Move to trash failed: " + - fileop.pFrom + ": error code " + ret); -// throw new IOException("Move to trash failed: " + fileop.pFrom + ": " + -// Kernel32Util.formatMessageFromLastErrorCode(ret)); - } - if (fileop.fAnyOperationsAborted) { - throw new IOException("Move to trash aborted"); - } - return true; - } +// /** +// * Move files/folders to the trash. If this file is on another file system +// * or on a shared network directory, it will simply be deleted without any +// * additional confirmation. Take that. +// *

+// * Based on JNA source for com.sun.jna.platform.win32.W32FileUtils +// * +// * @param files array of File objects to be removed +// * @return true if no error codes returned +// * @throws IOException if something bad happened along the way +// */ +// static private boolean moveToTrash(File[] files) throws IOException { +// Shell32 shell = Shell32.INSTANCE; +// SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT(); +// fileop.wFunc = ShellAPI.FO_DELETE; +// String[] paths = new String[files.length]; +// for (int i = 0; i < paths.length; i++) { +// paths[i] = files[i].getAbsolutePath(); +// System.out.println(paths[i]); +// } +// fileop.pFrom = new WString(fileop.encodePaths(paths)); +// fileop.fFlags = ShellAPI.FOF_ALLOWUNDO | ShellAPI.FOF_NO_UI; +// int ret = shell.SHFileOperation(fileop); +// if (ret != 0) { +// throw new IOException("Move to trash failed: " + +// fileop.pFrom + ": error code " + ret); +//// throw new IOException("Move to trash failed: " + fileop.pFrom + ": " + +//// Kernel32Util.formatMessageFromLastErrorCode(ret)); +// } +// if (fileop.fAnyOperationsAborted) { +// throw new IOException("Move to trash aborted"); +// } +// return true; +// } // /**