return all class files and packages

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@290 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 4f9f2e09c3
commit 0ad9df04f0
  1. 37
      jode/jode/bytecode/SearchPath.java

@ -23,6 +23,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable;
import jode.Decompiler; import jode.Decompiler;
/** /**
@ -220,17 +221,19 @@ public class SearchPath {
} }
/** /**
* Searches for a file in the search path. * Searches for all files in the given directory.
* @param filename the filename. The path components should be separated * @param dirName the directory name. The path components should
* by <code>/</code>. * be separated by <code>/</code>.
* @return An InputStream for the file. * @return An enumeration with all files/directories in the given
*/ * directory. */
public Enumeration listClassFiles(final String dirName) { public Enumeration listFiles(final String dirName) {
return new Enumeration() { return new Enumeration() {
int pathNr; int pathNr;
Enumeration zipEnum; Enumeration zipEnum;
int fileNr; int fileNr;
File currentDir;
String[] files; String[] files;
Hashtable doneDirs = new Hashtable();
public String findNextFile() { public String findNextFile() {
while (true) { while (true) {
@ -240,9 +243,19 @@ public class SearchPath {
String name = ze.getName(); String name = ze.getName();
if (name.startsWith(dirName) if (name.startsWith(dirName)
&& name.endsWith(".class")) { && name.endsWith(".class")) {
name = name.substring(dirName.length()+1); name = name.substring(dirName.length());
if (name.indexOf('/') == -1) while (name.charAt(0) == '/')
name = name.substring(1);
int slashIndex = name.indexOf('/');
if (slashIndex == -1)
return name; return name;
else {
String dir = name.substring(0, slashIndex);
if (doneDirs.get(dir) == null) {
doneDirs.put(dir, dir);
return dir;
}
}
} }
} }
zipEnum = null; zipEnum = null;
@ -252,6 +265,10 @@ public class SearchPath {
String name = files[fileNr++]; String name = files[fileNr++];
if (name.endsWith(".class")) { if (name.endsWith(".class")) {
return name; return name;
} else {
File f = new File(currentDir, name);
if (f.exists() && f.isDirectory())
return name;
} }
} }
files = null; files = null;
@ -270,8 +287,10 @@ public class SearchPath {
: dirName; : dirName;
try { try {
File f = new File(dirs[pathNr], localDirName); File f = new File(dirs[pathNr], localDirName);
if (f.exists() && f.isDirectory()) if (f.exists() && f.isDirectory()) {
currentDir = f;
files = f.list(); files = f.list();
}
} catch (SecurityException ex) { } catch (SecurityException ex) {
Decompiler.err.println("Warning: SecurityException" Decompiler.err.println("Warning: SecurityException"
+" while accessing " +" while accessing "

Loading…
Cancel
Save