|
28 | 28 |
|
29 | 29 | import com.sun.jna.Library; |
30 | 30 | import com.sun.jna.Native; |
31 | | -import com.sun.jna.WString; |
32 | 31 | import com.sun.jna.platform.win32.Kernel32Util; |
33 | 32 | import com.sun.jna.platform.win32.Shell32; |
34 | | -import com.sun.jna.platform.win32.ShellAPI; |
35 | | -import com.sun.jna.platform.win32.ShellAPI.SHFILEOPSTRUCT; |
36 | 33 | import com.sun.jna.platform.win32.ShlObj; |
37 | 34 | import com.sun.jna.platform.win32.WinDef; |
38 | 35 | import com.sun.jna.platform.win32.WinError; |
@@ -74,15 +71,17 @@ public void init(Base base) { |
74 | 71 | //checkQuickTime(); |
75 | 72 | checkPath(); |
76 | 73 |
|
77 | | - /* |
78 | 74 | File f = new File("C:\\recycle-test.txt"); |
79 | 75 | System.out.println(f.getAbsolutePath()); |
80 | 76 | java.io.PrintWriter writer = PApplet.createWriter(f); |
81 | 77 | writer.println("blah"); |
82 | 78 | writer.flush(); |
83 | 79 | writer.close(); |
84 | | - deleteFile(f); |
85 | | - */ |
| 80 | + try { |
| 81 | + deleteFile(f); |
| 82 | + } catch (IOException e) { |
| 83 | + e.printStackTrace(); |
| 84 | + } |
86 | 85 |
|
87 | 86 | //findJDK(); |
88 | 87 | /* |
@@ -333,53 +332,53 @@ static private String getDocumentsPath() throws Exception { |
333 | 332 | } |
334 | 333 |
|
335 | 334 |
|
336 | | - @Override |
337 | | - public boolean deleteFile(File file) { |
338 | | - try { |
339 | | - moveToTrash(new File[] { file }); |
340 | | - } catch (IOException e) { |
341 | | - e.printStackTrace(); |
342 | | - Base.log("Could not move " + file.getAbsolutePath() + " to the trash.", e); |
343 | | - return false; |
344 | | - } |
345 | | - return true; |
346 | | - } |
| 335 | +// @Override |
| 336 | +// public boolean deleteFile(File file) { |
| 337 | +// try { |
| 338 | +// moveToTrash(new File[] { file }); |
| 339 | +// } catch (IOException e) { |
| 340 | +// e.printStackTrace(); |
| 341 | +// Base.log("Could not move " + file.getAbsolutePath() + " to the trash.", e); |
| 342 | +// return false; |
| 343 | +// } |
| 344 | +// return true; |
| 345 | +// } |
347 | 346 |
|
348 | 347 |
|
349 | | - /** |
350 | | - * Move files/folders to the trash. If this file is on another file system |
351 | | - * or on a shared network directory, it will simply be deleted without any |
352 | | - * additional confirmation. Take that. |
353 | | - * <p> |
354 | | - * Based on JNA source for com.sun.jna.platform.win32.W32FileUtils |
355 | | - * |
356 | | - * @param files array of File objects to be removed |
357 | | - * @return true if no error codes returned |
358 | | - * @throws IOException if something bad happened along the way |
359 | | - */ |
360 | | - static private boolean moveToTrash(File[] files) throws IOException { |
361 | | - Shell32 shell = Shell32.INSTANCE; |
362 | | - SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT(); |
363 | | - fileop.wFunc = ShellAPI.FO_DELETE; |
364 | | - String[] paths = new String[files.length]; |
365 | | - for (int i = 0; i < paths.length; i++) { |
366 | | - paths[i] = files[i].getAbsolutePath(); |
367 | | - System.out.println(paths[i]); |
368 | | - } |
369 | | - fileop.pFrom = new WString(fileop.encodePaths(paths)); |
370 | | - fileop.fFlags = ShellAPI.FOF_ALLOWUNDO | ShellAPI.FOF_NO_UI; |
371 | | - int ret = shell.SHFileOperation(fileop); |
372 | | - if (ret != 0) { |
373 | | - throw new IOException("Move to trash failed: " + |
374 | | - fileop.pFrom + ": error code " + ret); |
375 | | -// throw new IOException("Move to trash failed: " + fileop.pFrom + ": " + |
376 | | -// Kernel32Util.formatMessageFromLastErrorCode(ret)); |
377 | | - } |
378 | | - if (fileop.fAnyOperationsAborted) { |
379 | | - throw new IOException("Move to trash aborted"); |
380 | | - } |
381 | | - return true; |
382 | | - } |
| 348 | +// /** |
| 349 | +// * Move files/folders to the trash. If this file is on another file system |
| 350 | +// * or on a shared network directory, it will simply be deleted without any |
| 351 | +// * additional confirmation. Take that. |
| 352 | +// * <p> |
| 353 | +// * Based on JNA source for com.sun.jna.platform.win32.W32FileUtils |
| 354 | +// * |
| 355 | +// * @param files array of File objects to be removed |
| 356 | +// * @return true if no error codes returned |
| 357 | +// * @throws IOException if something bad happened along the way |
| 358 | +// */ |
| 359 | +// static private boolean moveToTrash(File[] files) throws IOException { |
| 360 | +// Shell32 shell = Shell32.INSTANCE; |
| 361 | +// SHFILEOPSTRUCT fileop = new SHFILEOPSTRUCT(); |
| 362 | +// fileop.wFunc = ShellAPI.FO_DELETE; |
| 363 | +// String[] paths = new String[files.length]; |
| 364 | +// for (int i = 0; i < paths.length; i++) { |
| 365 | +// paths[i] = files[i].getAbsolutePath(); |
| 366 | +// System.out.println(paths[i]); |
| 367 | +// } |
| 368 | +// fileop.pFrom = new WString(fileop.encodePaths(paths)); |
| 369 | +// fileop.fFlags = ShellAPI.FOF_ALLOWUNDO | ShellAPI.FOF_NO_UI; |
| 370 | +// int ret = shell.SHFileOperation(fileop); |
| 371 | +// if (ret != 0) { |
| 372 | +// throw new IOException("Move to trash failed: " + |
| 373 | +// fileop.pFrom + ": error code " + ret); |
| 374 | +//// throw new IOException("Move to trash failed: " + fileop.pFrom + ": " + |
| 375 | +//// Kernel32Util.formatMessageFromLastErrorCode(ret)); |
| 376 | +// } |
| 377 | +// if (fileop.fAnyOperationsAborted) { |
| 378 | +// throw new IOException("Move to trash aborted"); |
| 379 | +// } |
| 380 | +// return true; |
| 381 | +// } |
383 | 382 |
|
384 | 383 |
|
385 | 384 | // /** |
|
0 commit comments