replace uses of Util.deleteFile() with Platform calls that use the Trash

This commit is contained in:
Ben Fry
2022-03-03 08:09:32 -05:00
parent 5446e22e1c
commit a9a589c189
6 changed files with 60 additions and 10 deletions
+6 -1
View File
@@ -946,7 +946,12 @@ public class Sketch {
// if the new folder already exists, then first remove its contents before
// copying everything over (user will have already been warned).
if (newFolder.exists()) {
Util.removeDir(newFolder);
//Util.removeDir(newFolder);
try {
Platform.deleteFile(newFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
// in fact, you can't do this on Windows because the file dialog
// will instead put you inside the folder, but it happens on OS X a lot.
+3
View File
@@ -305,11 +305,14 @@ public class Util {
/**
* Remove all files in a directory and the directory itself.
* Prints error messages with failed filenames. Does not follow symlinks.
* Use Platform.deleteFile() instead, which first attempts to use
* the Trash or Recycle Bin, out of an abundance of caution.
*/
static public boolean removeDir(File dir) {
return removeDir(dir, true);
}
/**
* Remove all files in a directory and the directory itself.
* Optionally, prints error messages with failed filenames.
@@ -217,8 +217,12 @@ public class AvailableContribution extends Contribution {
}
// delete the contrib folder inside the libraryXXXXXXtmp folder
Util.removeDir(newContribFolder, false);
//Util.removeDir(newContribFolder, false);
try {
Platform.deleteFile(newContribFolder);
} catch (IOException e) {
e.printStackTrace();
}
} else {
if (status != null) {
status.setErrorMessage(Language.text("contrib.errors.overwriting_properties"));
@@ -229,7 +233,12 @@ public class AvailableContribution extends Contribution {
// Remove any remaining boogers
if (tempFolder.exists()) {
Util.removeDir(tempFolder, false);
//Util.removeDir(tempFolder, false);
try {
Platform.deleteFile(tempFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
return installedContrib;
}
@@ -32,6 +32,7 @@ import javax.swing.SwingWorker;
import processing.app.Base;
import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.Util;
import processing.app.ui.Editor;
import processing.core.PApplet;
@@ -546,7 +547,12 @@ public class ContributionManager {
if (possible != null) {
for (File f : possible) {
if (f.getName().matches(pattern)) {
Util.removeDir(f);
//Util.removeDir(f);
try {
Platform.deleteFile(f);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@@ -562,7 +568,12 @@ public class ContributionManager {
);
if (markedForDeletion != null) {
for (File folder : markedForDeletion) {
Util.removeDir(folder);
//Util.removeDir(folder);
try {
Platform.deleteFile(folder);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@@ -629,7 +640,12 @@ public class ContributionManager {
if (name != null) { // should not happen, but...
updateContribsNames.add(name);
}
Util.removeDir(folder);
//Util.removeDir(folder);
try {
Platform.deleteFile(folder);
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -308,14 +308,24 @@ public abstract class LocalContribution extends Contribution {
// At this point it should be safe to replace this fella
if (contribFolder.exists()) {
Util.removeDir(contribFolder);
//Util.removeDir(contribFolder);
try {
Platform.deleteFile(contribFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
// This if should ideally never happen, since this function
// is to be called only when restarting on update
if (contribFolder.exists() && contribFolder.isDirectory()) {
Util.removeDir(contribFolder);
//Util.removeDir(contribFolder);
try {
Platform.deleteFile(contribFolder);
} catch (IOException e) {
e.printStackTrace();
}
}
else if (contribFolder.exists()) {
contribFolder.delete();
@@ -447,7 +457,12 @@ public abstract class LocalContribution extends Contribution {
if (doBackup) {
success = backup(true, status);
} else {
success = Util.removeDir(getFolder(), false);
try {
success = Platform.deleteFile(getFolder());
} catch (IOException e) {
e.printStackTrace();
success = false;
}
}
if (success) {
+2
View File
@@ -3,6 +3,8 @@ X Bring back getMainProgram() for Python Mode
X https://github.com/processing/processing4/issues/409
X You must first install tweak Mode to use this sketch
X https://github.com/processing/processing4/issues/415
X Change straight quotes to smart quotes in the PDE.properties file
X look for other uses of Util.deleteFile() and replace with Platform calls
_ test with Python Mode before release
sketchbook/open/deletions