fix for bug 65.. recursive 'data' folder

This commit is contained in:
benfry
2005-11-07 18:56:06 +00:00
parent 27613769ed
commit b0cf32083d
5 changed files with 72 additions and 20 deletions

View File

@@ -880,6 +880,46 @@ public class Base {
}
/**
* Gets a list of all files within the specified folder,
* and returns a list of their relative paths.
* Ignores any files/folders prefixed with a dot.
*/
static public String[] listFiles(String path, boolean relative) {
return listFiles(new File(path), relative);
}
static public String[] listFiles(File folder, boolean relative) {
String path = folder.getAbsolutePath();
Vector vector = new Vector();
listFiles(relative ? (path + File.separator) : "", path, vector);
String outgoing[] = new String[vector.size()];
vector.copyInto(outgoing);
return outgoing;
}
static protected void listFiles(String basePath,
String path, Vector vector) {
File folder = new File(path);
String list[] = folder.list();
if (list == null) return;
for (int i = 0; i < list.length; i++) {
if (list[i].charAt(0) == '.') continue;
File file = new File(path, list[i]);
String newPath = file.getAbsolutePath();
if (newPath.startsWith(basePath)) {
newPath = newPath.substring(basePath.length());
}
vector.add(newPath);
if (file.isDirectory()) {
listFiles(basePath, newPath, vector);
}
}
}
/**
* Equivalent to the one in PApplet, but static (die() is removed)
*/

View File

@@ -1805,7 +1805,7 @@ public class Sketch {
} else { // just copy the file over.. prolly a .dll or something
Base.copyFile(exportFile,
new File(appletFolder, exportFile.getName()));
new File(appletFolder, exportFile.getName()));
}
}
}
@@ -1813,18 +1813,23 @@ public class Sketch {
String bagelJar = "lib/core.jar";
packClassPathIntoZipFile(bagelJar, zos);
// files to include from data directory
// TODO this needs to be recursive
if (dataFolder.exists()) {
String dataFiles[] = dataFolder.list();
//String dataFiles[] = dataFolder.list();
String dataFiles[] = Base.listFiles(dataFolder, false);
int offset = folder.getAbsolutePath().length() + 1;
for (int i = 0; i < dataFiles.length; i++) {
File dataFile = new File(dataFiles[i]);
if (dataFile.isDirectory()) continue;
// don't export hidden files
// skipping dot prefix removes all: . .. .DS_Store
if (dataFiles[i].charAt(0) == '.') continue;
//if (dataFiles[i].charAt(0) == '.') continue;
if (dataFile.getName().charAt(0) == '.') continue;
entry = new ZipEntry(dataFiles[i]);
entry = new ZipEntry(dataFiles[i].substring(offset));
zos.putNextEntry(entry);
zos.write(Base.grabFile(new File(dataFolder, dataFiles[i])));
//zos.write(Base.grabFile(new File(dataFolder, dataFiles[i])));
zos.write(Base.grabFile(dataFile)); //new File(folder, dataFiles[i])));
zos.closeEntry();
}
}

View File

@@ -3197,15 +3197,15 @@ public class PApplet extends Applet
// (not the data folder) so check there first.
// the slash as a prefix means that it'll load from the root of
// the jar, rather than trying to dig into the package location
stream = getClass().getResourceAsStream("/" + filename);
//stream = getClass().getResourceAsStream("/" + filename);
//stream = getClass().getResourceAsStream(filename);
if (stream != null) return stream;
// check the data subfolder (used when bundling separately,
// probably should be the default for sketches)
//stream = getClass().getResourceAsStream("data/" + filename);
//if (stream != null) return stream;
// for rev 0096, the "data" folder will be exported intact
// (including folders to be processed recursively)
stream = getClass().getResourceAsStream("data/" + filename);
if (stream != null) return stream;
try {
URL url = new URL(filename);
stream = url.openStream();

View File

@@ -1,6 +1,13 @@
0096 core
X set applet.path to user.dir if init() is reached and it's not set
X add NO_DEPTH_TEST to PGraphics3
_ need to document this somewhere
_ check into bug where applet crashing if image not available
_ probably need to add a hint() to make things not halt
_ hack the image exporting stuff into p5
_ check into loadImage() with jars bug, very frustrating
_ when using loadImage() on a jar, turn off "no cache" option?
_ "not available in P3D" should read "OPENGL" in opengl lib

View File

@@ -5,17 +5,16 @@ X not really, but a command line that still uses awt might not be bad
o gets messy because of how the classpath et al is handled
o maybe just split out the preproc?
o could avoid doing things like the packages etc
X subfolders in the 'data' directory don't work
X http://dev.processing.org/bugs/show_bug.cgi?id=65
_ hex colors < 6 chars produce bizarre error:
_ http://dev.processing.org/bugs/show_bug.cgi?id=196
_ check into bug where applet crashing if image not available
_ probably need to add a hint() to make things not halt
_ hack the image exporting stuff into p5
_ check into loadImage() with jars bug, very frustrating
_ when using loadImage() on a jar, turn off "no cache" option?
_ threading bug with sonia and rev 91
_ make .pde files double-clickable from windows
_ on drag, are these already passed to argv[]?
_ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/fileassociations/fa_intro.asp
_ file a feature request for command line support
@@ -23,6 +22,9 @@ _ would still require awt, but would take a sketch on cmd line
_ build it and then exit
_ add "reference" and "examples" categories to bugzilla
_ do something about the summary field to not make it editable
_ maybe just move it away from its current location?
_ call it "bug title" instead of "summary"?
the biggies
_ bring back P2D with proper stuff
@@ -387,8 +389,6 @@ _ if size() not found in export/compile, ask the user
_ have size(myWidth, myHeight) set a static var in PGraphics
_ for the last size that was used, use as default for fill-in field
_ http://dev.processing.org/bugs/show_bug.cgi?id=64
_ subfolders in the 'data' directory don't work
_ http://dev.processing.org/bugs/show_bug.cgi?id=65
_ make export put a timestamp in the html code (hidden or visible)
_ http://dev.processing.org/bugs/show_bug.cgi?id=66