MCPcopy Index your code
hub / github.com/OpenSourcePhysics/osp / processFile

Method processFile

src/org/opensourcephysics/tools/JarTool.java:1214–1280  ·  view source on GitHub ↗

Processes a regular file, a compressed file, or (recursively) a directory @param filename String the relative filename to process @param parent File The actual file to process @param targetDirectory File The target directory @param policy OverwriteValue What to do on duplic

(String filename, File file, File targetDirectory, OverwriteValue policy)

Source from the content-addressed store, hash-verified

1212 * @return StringBuffer A list of errors
1213 */
1214 static private StringBuffer processFile(String filename, File file, File targetDirectory, OverwriteValue policy) {
1215 // changed by D Brown June 2007 to handle zip/jar entries
1216 if (!file.exists() && (filename.indexOf("!") == -1)) { //$NON-NLS-1$
1217 return new StringBuffer(res.getString("JarTool.FileDoesntExist") + " " + file.getAbsolutePath() + ".\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1218 } // end change by D Brown
1219 if (file.isDirectory()) {
1220 // recursively process each file in the directory
1221 StringBuffer errorMessage = new StringBuffer();
1222 FileSystemView fsView = FileSystemView.getFileSystemView();
1223 File filesInDir[] = fsView.getFiles(file, false);
1224 for (int i = 0, n = filesInDir.length; i < n; i++) {
1225 errorMessage.append(
1226 processFile(filename + "/" + filesInDir[i].getName(), filesInDir[i], targetDirectory, policy)); //$NON-NLS-1$
1227 }
1228 return errorMessage;
1229 }
1230 // Check for a ZIP or JAR file
1231 String filenameLowerCase = file.getName().toLowerCase();
1232 if (filenameLowerCase.endsWith(".jar") || filenameLowerCase.endsWith(".zip") //$NON-NLS-1$ //$NON-NLS-2$
1233 || filenameLowerCase.endsWith(".trz")) { //$NON-NLS-1$
1234 if (unzipWithWarning(file, targetDirectory, policy)) {
1235 return new StringBuffer();
1236 }
1237 return new StringBuffer(res.getString("JarTool.CantUncompress") + " " + file.getAbsolutePath() + ".\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1238 }
1239 // code added by D Brown June 2007 to handle zip/jar entries
1240 int n = filename.indexOf("!"); //$NON-NLS-1$
1241 if (n > -1) {
1242 String entry = filename.substring(n + 2);
1243 // next 2 lines added/modified by W Christian/D Brown for Linux 2007-11-05
1244 String filepath = file.getAbsolutePath();
1245 File zipFile = new File(filepath.substring(0, filepath.indexOf("!"))); //$NON-NLS-1$
1246 File target = new File(targetDirectory, entry);
1247 if (extract0(zipFile, entry, target) != null) {
1248 return new StringBuffer();
1249 }
1250 return new StringBuffer(
1251 res.getString("JarTool.CantCopy") + " " + filename + " --> " + targetDirectory.getName() + ".\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
1252 } // end code added by D Brown
1253 // File is a normal file. Just copy it
1254 // If the file has leading "../" remove them from the name
1255 while (filename.startsWith("../")) { //$NON-NLS-1$
1256 filename = filename.substring(3);
1257 }
1258 File target = new File(targetDirectory, filename);
1259 if (target.exists()) {
1260 switch (policy.value) {
1261 case NO_TO_ALL:
1262 return new StringBuffer();
1263 case YES_TO_ALL:
1264 break; // will overwrite
1265 default:
1266 switch (policy.value = confirmOverwrite(filename)) {
1267 case NO_TO_ALL:
1268 case NO:
1269 return new StringBuffer();
1270// case CANCEL : return new StringBuffer();
1271 default: // Do nothing, i.e., will overwrite the file

Callers 1

compressListMethod · 0.95

Calls 10

unzipWithWarningMethod · 0.95
extract0Method · 0.95
confirmOverwriteMethod · 0.95
copyMethod · 0.95
existsMethod · 0.80
getFilesMethod · 0.80
getStringMethod · 0.65
appendMethod · 0.65
getNameMethod · 0.65
getAbsolutePathMethod · 0.45

Tested by

no test coverage detected