private List<String> getOptions() { final List<File> aList = FileUtils.listDirectory(OsUtils.getMcDir("resourcepacks")); final List<String> options = new ArrayList<String>(); for (final File f : aList) { if (f.isDirectory()) continue; final String[] parts = FileUtils.getFilenameParts(f); if (parts[1].equalsIgnoreCase("zip")) { options.add(parts[0]); } } Collections.sort(options); return options; }
public static void run(FileFsTreeNode fileNode, Runnable afterImport) { final String title = "Import sound file into sounds/" + fileNode.getPathRelativeToRoot(); final FileChooser fc = new FileChooser( App.getFrame(), FilePath.IMPORT_SOUND, title, FileChooser.OGG, true, false, false); fc.showDialog("Open"); if (!fc.approved()) { return; } fc.showDialog("Import"); if (fc.approved()) { return; } final File file = fc.getSelectedFile(); if (file == null || !file.exists()) { Alerts.error(App.getFrame(), "That's not a valid file."); return; } try { final File target = fileNode.getPath(); target.mkdirs(); FileUtils.copyFile(file, new File(target, file.getName())); if (afterImport != null) afterImport.run(); } catch (final IOException e) { Log.e(e); Alerts.error(App.getFrame(), "Something went wrong during import."); } }