MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / defineZipFilePath

Method defineZipFilePath

src/test/LoaderTest.java:379–415  ·  view source on GitHub ↗

Uses a file chooser to define the zip file path. @return empty List to fill with files to be zipped

()

Source from the content-addressed store, hash-verified

377 * @return empty List<File> to fill with files to be zipped
378 */
379 private ArrayList<File> defineZipFilePath() {
380 // show file chooser to get directory and zip name
381 AsyncFileChooser chooser = getFileChooser();
382 int result = chooser.showSaveDialog(frame);
383 if (result != JFileChooser.APPROVE_OPTION) {
384 return null;
385 }
386 File chooserFile = chooser.getSelectedFile();
387 if (chooserFile.exists()) {
388 // TODO: warn or cancel
389 }
390 if (!VideoIO.canWrite(chooserFile)) {
391 return null;
392 }
393
394 // define zipFilePath and check for reserved characters, including spaces
395 zipFilePath = chooserFile.getAbsolutePath();
396 String ext = XML.getExtension(chooserFile.getName());
397
398 // check for duplicate file if target extension not used
399 if (!"zip".equalsIgnoreCase(ext)) {
400 String newFilePath = XML.stripExtension(zipFilePath) + ".zip";
401 if (!VideoIO.canWrite(new File(newFilePath)))
402 return null;
403 zipFilePath = newFilePath;
404 }
405
406 // return empty list
407 return new ArrayList<File>() {
408 @Override
409 public boolean add(File f) {
410 if (!contains(f))
411 super.add(f);
412 return true;
413 }
414 };
415 }
416
417 private AsyncFileChooser getFileChooser() {
418 if (fileChooser == null) {

Callers 1

saveNewZipMethod · 0.95

Calls 8

getFileChooserMethod · 0.95
showSaveDialogMethod · 0.95
canWriteMethod · 0.95
getExtensionMethod · 0.95
stripExtensionMethod · 0.95
existsMethod · 0.80
getNameMethod · 0.65
getAbsolutePathMethod · 0.45

Tested by

no test coverage detected