Skip to content

Commit c452b72

Browse files
committed
remove more custom code
1 parent 6127860 commit c452b72

3 files changed

Lines changed: 67 additions & 62 deletions

File tree

app/src/processing/app/Platform.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.sun.jna.Library;
3333
import com.sun.jna.Native;
34+
import com.sun.jna.platform.FileUtils;
3435

3536

3637
/**
@@ -152,13 +153,19 @@ public void openFolder(File file) throws Exception {
152153
* @return true if the folder was successfully removed
153154
* @throws IOException
154155
*/
155-
public boolean deleteFile(File file) throws IOException {
156-
if (file.isDirectory()) {
156+
final public boolean deleteFile(File file) throws IOException {
157+
FileUtils fu = FileUtils.getInstance();
158+
if (fu.hasTrash()) {
159+
fu.moveToTrash(new File[] { file });
160+
return true;
161+
162+
} else if (file.isDirectory()) {
157163
Base.removeDir(file);
164+
return true;
165+
158166
} else {
159167
return file.delete();
160168
}
161-
return true;
162169
}
163170

164171

app/src/processing/app/macosx/Platform.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.io.File;
2626
import java.io.FileNotFoundException;
27-
import java.io.IOException;
2827

2928
import com.apple.eio.FileManager;
3029

@@ -104,13 +103,13 @@ public File getDefaultSketchbookFolder() throws Exception {
104103
}
105104

106105

107-
/**
108-
* Moves the specified File object (which might be a file or folder)
109-
* to the trash.
110-
*/
111-
public boolean deleteFile(File file) throws IOException {
112-
return FileManager.moveToTrash(file);
113-
}
106+
// /**
107+
// * Moves the specified File object (which might be a file or folder)
108+
// * to the trash.
109+
// */
110+
// public boolean deleteFile(File file) throws IOException {
111+
// return FileManager.moveToTrash(file);
112+
// }
114113

115114

116115
/*

app/src/processing/app/windows/Platform.java

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@
2828

2929
import com.sun.jna.Library;
3030
import com.sun.jna.Native;
31-
import com.sun.jna.WString;
3231
import com.sun.jna.platform.win32.Kernel32Util;
3332
import com.sun.jna.platform.win32.Shell32;
34-
import com.sun.jna.platform.win32.ShellAPI;
35-
import com.sun.jna.platform.win32.ShellAPI.SHFILEOPSTRUCT;
3633
import com.sun.jna.platform.win32.ShlObj;
3734
import com.sun.jna.platform.win32.WinDef;
3835
import com.sun.jna.platform.win32.WinError;
@@ -74,15 +71,17 @@ public void init(Base base) {
7471
//checkQuickTime();
7572
checkPath();
7673

77-
/*
7874
File f = new File("C:\\recycle-test.txt");
7975
System.out.println(f.getAbsolutePath());
8076
java.io.PrintWriter writer = PApplet.createWriter(f);
8177
writer.println("blah");
8278
writer.flush();
8379
writer.close();
84-
deleteFile(f);
85-
*/
80+
try {
81+
deleteFile(f);
82+
} catch (IOException e) {
83+
e.printStackTrace();
84+
}
8685

8786
//findJDK();
8887
/*
@@ -333,53 +332,53 @@ static private String getDocumentsPath() throws Exception {
333332
}
334333

335334

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+
// }
347346

348347

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+
// }
383382

384383

385384
// /**

0 commit comments

Comments
 (0)