Moved removeDescendants() and removeDir() from Base to BaseNoGui.

This commit is contained in:
Claudio Indellicati 2014-08-22 18:12:34 +02:00 committed by Cristian Maglie
parent 7c58be397b
commit 36fd0bf344
3 changed files with 42 additions and 26 deletions

View File

@ -2604,12 +2604,7 @@ public class Base {
* Remove all files in a directory and the directory itself.
*/
static public void removeDir(File dir) {
if (dir.exists()) {
removeDescendants(dir);
if (!dir.delete()) {
System.err.println(I18n.format(_("Could not delete {0}"), dir));
}
}
BaseNoGui.removeDir(dir);
}
@ -2620,24 +2615,7 @@ public class Base {
* (i.e. when cleaning temp files from lib/build)
*/
static public void removeDescendants(File dir) {
if (!dir.exists()) return;
String files[] = dir.list();
for (int i = 0; i < files.length; i++) {
if (files[i].equals(".") || files[i].equals("..")) continue;
File dead = new File(dir, files[i]);
if (!dead.isDirectory()) {
if (!Preferences.getBoolean("compiler.save_build_files")) {
if (!dead.delete()) {
// temporarily disabled
System.err.println(I18n.format(_("Could not delete {0}"), dead));
}
}
} else {
removeDir(dead);
//dead.delete();
}
}
BaseNoGui.removeDescendants(dir);
}

View File

@ -391,6 +391,45 @@ public class BaseNoGui {
PreferencesData.init(absoluteFile(preferencesFile));
}
/**
* Recursively remove all files within a directory,
* used with removeDir(), or when the contents of a dir
* should be removed, but not the directory itself.
* (i.e. when cleaning temp files from lib/build)
*/
static public void removeDescendants(File dir) {
if (!dir.exists()) return;
String files[] = dir.list();
for (int i = 0; i < files.length; i++) {
if (files[i].equals(".") || files[i].equals("..")) continue;
File dead = new File(dir, files[i]);
if (!dead.isDirectory()) {
if (!Preferences.getBoolean("compiler.save_build_files")) {
if (!dead.delete()) {
// temporarily disabled
System.err.println(I18n.format(_("Could not delete {0}"), dead));
}
}
} else {
removeDir(dead);
//dead.delete();
}
}
}
/**
* Remove all files in a directory and the directory itself.
*/
static public void removeDir(File dir) {
if (dir.exists()) {
removeDescendants(dir);
if (!dir.delete()) {
System.err.println(I18n.format(_("Could not delete {0}"), dir));
}
}
}
/**
* Spew the contents of a String object out to a file.
*/

View File

@ -39,7 +39,6 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
@ -201,7 +200,7 @@ public class Compiler implements MessageConsumer {
// the next time we start up, internal runs using Runner won't
// work because the build dir won't exist at startup, so the classloader
// will ignore the fact that that dir is in the CLASSPATH in run.sh
Base.removeDescendants(tempBuildFolder);
BaseNoGui.removeDescendants(tempBuildFolder);
} else {
// delete only stale source files, from the previously
// compiled sketch. This allows multiple windows to be