private void ListSubDirectorySizes(File file) { File[] files; files = file.listFiles( new FileFilter() { @Override public boolean accept(File file) { // if (!file.isDirectory()){ // return false; //To change body of implemented methods use // File | Settings | File Templates. // }else{ // return true; // } return true; } }); Map<String, Long> dirListing = new HashMap<String, Long>(); for (File dir : files) { DiskUsage diskUsage = new DiskUsage(); diskUsage.accept(dir); // long size = diskUsage.getSize() / (1024 * 1024); long size = diskUsage.getSize(); dirListing.put(dir.getName(), size); } ValueComparator bvc = new ValueComparator(dirListing); TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(bvc); sorted_map.putAll(dirListing); PrettyPrint(file, sorted_map); }
private void listFilesForFolder(final File folder) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { listFilesForFolder(fileEntry); } else { Image img = new Image(fileEntry.toURI().toString()); imgMan.images.add( new ImageInformation( img, fileEntry.toURI().toString(), new ImageInformation.Type[] { ImageInformation.Type.SAND, ImageInformation.Type.FISH, ImageInformation.Type.ALGA, ImageInformation.Type.CORAL, ImageInformation.Type.SAND }, new Point[] { new Point((int) (img.getWidth() * 0.25), (int) (img.getHeight() * 0.25)), new Point((int) (img.getWidth() * 0.75), (int) (img.getHeight() * 0.25)), new Point((int) (img.getWidth() * 0.5), (int) (img.getHeight() * 0.5)), new Point((int) (img.getWidth() * 0.25), (int) (img.getHeight() * 0.75)), new Point((int) (img.getWidth() * 0.75), (int) (img.getHeight() * 0.75)) }, new double[] {0.86, 0.76, 0.99, 0.65, 0.54})); } } }
// formateaza un disk public void format() { File root = new File(currentDiskPath); File[] listOfFiles = root.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { delete(listOfFiles[i]); } System.out.println("Format succesfull!"); takePath(); }
public GalaxyViewer(Settings settings, boolean animatorFrame) throws Exception { super("Stars GalaxyViewer"); this.settings = settings; this.animatorFrame = animatorFrame; if (settings.gameName.equals("")) throw new Exception("GameName not defined in settings."); setDefaultCloseOperation(EXIT_ON_CLOSE); File dir = new File(settings.directory); File map = new File(dir, settings.getGameName() + ".MAP"); if (map.exists() == false) { File f = new File(dir.getParentFile(), settings.getGameName() + ".MAP"); if (f.exists()) map = f; else { String error = "Could not find " + map.getAbsolutePath() + "\n"; error += "Export this file from Stars! (Only needs to be done one time pr game)"; throw new Exception(error); } } Vector<File> mFiles = new Vector<File>(); Vector<File> hFiles = new Vector<File>(); for (File f : dir.listFiles()) { if (f.getName().toUpperCase().endsWith("MAP")) continue; if (f.getName().toUpperCase().endsWith("HST")) continue; if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".M")) mFiles.addElement(f); else if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".H")) hFiles.addElement(f); } if (mFiles.size() == 0) throw new Exception("No M-files found matching game name."); if (hFiles.size() == 0) throw new Exception("No H-files found matching game name."); parseMapFile(map); Vector<File> files = new Vector<File>(); files.addAll(mFiles); files.addAll(hFiles); p = new Parser(files); calculateColors(); // UI: JPanel cp = (JPanel) getContentPane(); cp.setLayout(new BorderLayout()); cp.add(universe, BorderLayout.CENTER); JPanel south = createPanel(0, hw, new JLabel("Search: "), search, names, zoom, colorize); search.setPreferredSize(new Dimension(100, -1)); cp.add(south, BorderLayout.SOUTH); hw.addActionListener(this); names.addActionListener(this); zoom.addChangeListener(this); search.addKeyListener(this); colorize.addActionListener(this); setSize(800, 600); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2); setVisible(animatorFrame == false); if (animatorFrame) names.setSelected(false); }
public void ls() { // OVERLOADING :(((( File folder = new File(currentPath); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { System.out.println("File: " + listOfFiles[i].getName()); } else if (listOfFiles[i].isDirectory()) { System.out.println("Directory: " + listOfFiles[i].getName()); } } takePath(); }
private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) { String s_List = ""; ArrayList aSubFolders = new ArrayList(); File file = new File(s_Dir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { for (int i = 0; i < filelist.length; i++) { if (filelist[i].isDirectory()) { aSubFolders.add(filelist[i].getName()); } } int n_Count = aSubFolders.size(); String s_LastFlag = ""; String s_Folder = ""; for (int i = 1; i <= n_Count; i++) { if (i < n_Count) { s_LastFlag = "0"; } else { s_LastFlag = "1"; } s_Folder = aSubFolders.get(i - 1).toString(); s_List = s_List + "arr" + s_Flag + "[" + String.valueOf(n_TreeIndex) + "]=new Array(\"" + s_Folder + "\"," + String.valueOf(n_Indent) + ", " + s_LastFlag + ");\n"; n_TreeIndex = n_TreeIndex + 1; ArrayList a_Temp = GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex); s_List = s_List + a_Temp.get(0).toString(); n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue(); } } ArrayList a_Return = new ArrayList(); a_Return.add(s_List); a_Return.add(String.valueOf(n_TreeIndex)); return a_Return; }
/** * Enumerates the resouces in a give package name. This works even if the resources are loaded * from a jar file! * * <p>Adapted from code by mikewse on the java.sun.com message boards. * http://forum.java.sun.com/thread.jsp?forum=22&thread=30984 * * @param packageName The package to enumerate * @return A Set of Strings for each resouce in the package. */ public static Set getResoucesInPackage(String packageName) throws IOException { String localPackageName; if (packageName.endsWith("/")) { localPackageName = packageName; } else { localPackageName = packageName + '/'; } Enumeration dirEnum = ClassLoader.getSystemResources(localPackageName); Set names = new HashSet(); // Loop CLASSPATH directories while (dirEnum.hasMoreElements()) { URL resUrl = (URL) dirEnum.nextElement(); // Pointing to filesystem directory if (resUrl.getProtocol().equals("file")) { File dir = new File(resUrl.getFile()); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) continue; names.add(localPackageName + file.getName()); } } // Pointing to Jar file } else if (resUrl.getProtocol().equals("jar")) { JarURLConnection jconn = (JarURLConnection) resUrl.openConnection(); JarFile jfile = jconn.getJarFile(); Enumeration entryEnum = jfile.entries(); while (entryEnum.hasMoreElements()) { JarEntry entry = (JarEntry) entryEnum.nextElement(); String entryName = entry.getName(); // Exclude our own directory if (entryName.equals(localPackageName)) continue; String parentDirName = entryName.substring(0, entryName.lastIndexOf('/') + 1); if (!parentDirName.equals(localPackageName)) continue; names.add(entryName); } } else { // Invalid classpath entry } } return names; }
public static boolean deleteRecursive(File dir) { boolean result = true; File files[] = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { result = result && deleteRecursive(files[i]); } else { result = result && files[i].delete(); } } } result = result && dir.delete(); return result; }
public static void delete(File file) { if (file.isFile()) file.delete(); File[] files = file.listFiles(); if (files != null) { // some JVMs return null for empty dirs for (File f : files) { if (f.isDirectory()) { delete(f); } else { f.delete(); } } } file.delete(); }
public static boolean deleteAll(File file) { boolean b = true; if ((file != null) && file.exists()) { if (file.isDirectory()) { try { File[] files = file.listFiles(); for (File f : files) b &= deleteAll(f); } catch (Exception e) { return false; } } b &= file.delete(); } return b; }
void addChildren(DefaultMutableTreeNode parent, File parentDirFile) { for (File file : parentDirFile.listFiles()) { String[] namesplitStrings = file.toString().split("\\\\"); String filename = namesplitStrings[namesplitStrings.length - 1]; if (file.isDirectory()) { DefaultMutableTreeNode child = new DefaultMutableTreeNode(filename); addChildren(child, file); parent.add(child); } else if (file.isFile()) { parent.add(new DefaultMutableTreeNode(filename)); } } }
public static void zipDirectory(File directory, File base, ZipOutputStream zos) throws IOException { File[] files = directory.listFiles(); byte[] buffer = new byte[8192]; int read = 0; for (int i = 0, n = files.length; i < n; i++) { if (files[i].isDirectory()) { zipDirectory(files[i], base, zos); } else { FileInputStream in = new FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getPath().substring(base.getPath().length() + 1)); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } } }
private void populateList() { try { String path = "."; fileList.setText(" "); String files; File folder = new File(path); File[] listOfFiles = folder.listFiles(); for (int i = 0; i < listOfFiles.length; i++) { if (listOfFiles[i].isFile()) { files = listOfFiles[i].getName(); // if(files.endsWith(".dat")) fileList.append(files + "\n"); } } } catch (java.security.AccessControlException k) { } }
/** * Returns all jpg & png images from a directory in an array. * * @param directory the directory to start with * @param descendIntoSubDirectories should we include sub directories? * @return an ArrayList<File> containing all the files or nul if none are found.. * @throws IOException */ public static ArrayList<File> getAllImageFiles(File directory, boolean descendIntoSubDirectories) throws IOException { ArrayList<File> resultList = new ArrayList<File>(256); File[] f = directory.listFiles(); for (File file : f) { if (file != null && (file.getName().toLowerCase().endsWith(".jpg") || file.getName().toLowerCase().endsWith(".png")) && !file.getName().startsWith("tn_")) { resultList.add(file); } if (descendIntoSubDirectories && file.isDirectory()) { ArrayList<File> tmp = getAllImageFiles(file, true); if (tmp != null) { resultList.addAll(tmp); } } } if (resultList.size() > 0) return resultList; else return null; }
@Nullable private static File findOldConfigDir( @NotNull File configDir, @Nullable String customPathSelector) { final File selectorDir = CONFIG_RELATED_PATH.isEmpty() ? configDir : configDir.getParentFile(); final File parent = selectorDir.getParentFile(); if (parent == null || !parent.exists()) { return null; } File maxFile = null; long lastModified = 0; final String selector = PathManager.getPathsSelector() != null ? PathManager.getPathsSelector() : selectorDir.getName(); final String prefix = getPrefixFromSelector(selector); final String customPrefix = customPathSelector != null ? getPrefixFromSelector(customPathSelector) : null; for (File file : parent.listFiles( new FilenameFilter() { @Override public boolean accept(@NotNull File file, @NotNull String name) { return StringUtil.startsWithIgnoreCase(name, prefix) || customPrefix != null && StringUtil.startsWithIgnoreCase(name, customPrefix); } })) { File options = new File(file, CONFIG_RELATED_PATH + OPTIONS_XML); if (!options.exists()) { continue; } long modified = options.lastModified(); if (modified > lastModified) { lastModified = modified; maxFile = file; } } return maxFile != null ? new File(maxFile, CONFIG_RELATED_PATH) : null; }
boolean tryDir(String d) { ClassLoader L = getClass().getClassLoader(); File p = new File(d, PACKAGE); System.out.println("Try " + p); if (!p.exists() || !p.isDirectory()) return false; for (File f : p.listFiles()) { String s = f.getName(); if (!s.endsWith(".class")) continue; String name = s.substring(0, s.length() - 6); try { Class<?> c = L.loadClass(PACKAGE + "." + name); if (!Animator.class.isAssignableFrom(c)) continue; Animator a = (Animator) c.newInstance(); a.container().setPreferredSize(DIM); map.put(name, a); System.out.println(" " + name); // ClassNotFoundException InstantiationException IllegalAccessException } catch (Exception e) { continue; } } return map.size() > 0; }
public static boolean rmrf(File fi) { if (fi.isDirectory()) { boolean done = true; for (File subfi : fi.listFiles()) { if (!rmrf(subfi)) { done = false; } } if (!done) return false; return fi.delete(); } else { boolean done = true; for (int i = 0; i < 10; i++) { done = fi.delete(); if (done) break; try { Thread.sleep(100); } catch (InterruptedException e) { // do nothing } } return done; } }
public void run() { // String a = // "http://neuromorpho.org/neuroMorpho/dableFiles/borst/CNG%20version/dCH-cobalt.CNG.swc"; // // For developer use if (myArgs.length == 0) { String usage = "\nError, missing SWC file containing morphology!\n\nUsage: \n java -cp build cvapp.main swc_file [-test]" + "\n or:\n ./run.sh swc_file [" + TEST_FLAG + "|" + TEST_NOGUI_FLAG + "|" + NEUROML1_EXPORT_FLAG + "|" + NEUROML2_EXPORT_FLAG + "]\n\n" + "where swc_file is the file name or URL of the SWC morphology file\n"; System.out.println(usage); System.exit(0); } String a = myArgs[0]; File baseDir = new File("."); if ((new File(a)).exists()) { baseDir = (new File(a)).getParentFile(); } try { File root = new File(main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()) .getParentFile(); if (!a.startsWith("http://") && !a.startsWith("file://")) { a = "file://" + (new File(a)).getCanonicalPath(); } boolean supressGui = false; if (myArgs.length == 2 && (myArgs[1].equals(TEST_NOGUI_FLAG) || myArgs[1].equals(NEUROML1_EXPORT_FLAG) || myArgs[1].equals(NEUROML2_EXPORT_FLAG))) { supressGui = true; } neuronEditorFrame nef = null; nef = new neuronEditorFrame(700, 600, supressGui); // nef.validate(); nef.pack(); centerWindow(nef); nef.setVisible(!supressGui); nef.setReadWrite(true, true); int indexof = a.lastIndexOf('/') + 1; String directory = a.substring(0, indexof); String fileName = a.substring(indexof, a.length()); URL u = new URL(a); String sdata[] = readStringArrayFromURL(u); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + fileName); nef.loadFile(sdata, directory, fileName); System.out.println("Loaded: " + fileName); if (myArgs.length == 2 && myArgs[1].equals(TEST_ONE_FLAG)) { // Thread.sleep(1000); doTests(nef, fileName); } else if (myArgs.length == 2 && myArgs[1].equals(NEUROML1_EXPORT_FLAG)) { File rootFile = (new File(baseDir, fileName)).getAbsoluteFile(); String nml1FileName = rootFile.getName().endsWith(".swc") ? rootFile.getName().substring(0, rootFile.getName().length() - 4) + ".xml" : rootFile.getName() + ".xml"; File nml1File = new File(rootFile.getParentFile(), nml1FileName); neuronEditorPanel nep = nef.getNeuronEditorPanel(); nep.writeStringToFile(nep.getCell().writeNeuroML_v1_8_1(), nml1File.getAbsolutePath()); System.out.println( "Saved NeuroML representation of the file to: " + nml1File.getAbsolutePath() + ": " + nml1File.exists()); File v1schemaFile = new File(root, "Schemas/v1.8.1/Level3/NeuroML_Level3_v1.8.1.xsd"); validateXML(nml1File, v1schemaFile); System.exit(0); } else if (myArgs.length == 2 && myArgs[1].equals(NEUROML2_EXPORT_FLAG)) { File rootFile = (new File(baseDir, fileName)).getAbsoluteFile(); String nml2FileName = rootFile.getName().endsWith(".swc") ? rootFile.getName().substring(0, rootFile.getName().length() - 4) + ".cell.nml" : rootFile.getName() + ".cell.nml"; if (Character.isDigit(nml2FileName.charAt(0))) { nml2FileName = "Cell_" + nml2FileName; } File nml2File = new File(rootFile.getParentFile(), nml2FileName); neuronEditorPanel nep = nef.getNeuronEditorPanel(); nep.writeStringToFile(nep.getCell().writeNeuroML_v2beta(), nml2File.getAbsolutePath()); System.out.println( "Saved the NeuroML representation of the file to: " + nml2File.getAbsolutePath() + ": " + nml2File.exists()); validateXML(nml2File, new File(root, "Schemas/v2/NeuroML_v2beta4.xsd")); System.exit(0); } else if (myArgs.length == 2 && (myArgs[1].equals(TEST_FLAG) || (myArgs[1].equals(TEST_NOGUI_FLAG)))) { // Thread.sleep(1000); doTests(nef, fileName); File exampleDir = new File("twoCylSwc"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } exampleDir = new File("spherSomaSwc"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } exampleDir = new File("caseExamples"); for (File f : exampleDir.listFiles()) { if (f.getName().endsWith(".swc")) { sdata = fileString.readStringArrayFromFile(f.getAbsolutePath()); nef.setTitle("3DViewer (Modified from CVAPP with permission)-Neuron: " + f.getName()); nef.loadFile(sdata, f.getParent(), f.getName()); doTests(nef, f.getAbsolutePath()); } } if (supressGui) System.exit(0); } } catch (Exception exception) { System.err.println("Error while handling SWC file (" + a + ")"); exception.printStackTrace(); } }
private void InitUpload() throws ServletException, IOException { String sConfig = myUtil.ReadFile(myUtil.getConfigFileRealPath(m_request.getServletPath())); ArrayList aStyle = myUtil.getConfigArray("Style", sConfig); String sAllowExt, sUploadDir, sBaseUrl, sContentPath; String sCurrDir, sDir; int nAllowBrowse; String sPathShareImage, sPathShareFlash, sPathShareMedia, sPathShareOther; // param String sType = myUtil.dealNull(m_request.getParameter("type")).toUpperCase(); String sStyleName = myUtil.dealNull(m_request.getParameter("style")); String sCusDir = myUtil.dealNull(m_request.getParameter("cusdir")); String sAction = myUtil.dealNull(m_request.getParameter("action")).toUpperCase(); String s_SKey = myUtil.dealNull(m_request.getParameter("skey")); // InitUpload String[] aStyleConfig = new String[1]; boolean bValidStyle = false; for (int i = 0; i < aStyle.size(); i++) { aStyleConfig = myUtil.split(aStyle.get(i).toString(), "|||"); if (sStyleName.toLowerCase().equals(aStyleConfig[0].toLowerCase())) { bValidStyle = true; break; } } if (!bValidStyle) { out.print(getOutScript("alert('Invalid Style!')")); out.close(); return; } if (!aStyleConfig[61].equals("1")) { sCusDir = ""; } String ss_FileSize = "", ss_FileBrowse = "", ss_SpaceSize = "", ss_SpacePath = "", ss_PathMode = "", ss_PathUpload = "", ss_PathCusDir = "", ss_PathCode = "", ss_PathView = ""; if ((aStyleConfig[61].equals("2")) && (!s_SKey.equals(""))) { ss_FileSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileSize")); ss_FileBrowse = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_FileBrowse")); ss_SpaceSize = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpaceSize")); ss_SpacePath = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_SpacePath")); ss_PathMode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathMode")); ss_PathUpload = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathUpload")); ss_PathCusDir = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCusDir")); ss_PathCode = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathCode")); ss_PathView = (String) myUtil.dealNull(m_session.getAttribute("eWebEditor_" + s_SKey + "_PathView")); if (myUtil.IsInt(ss_FileSize)) { aStyleConfig[11] = ss_FileSize; aStyleConfig[12] = ss_FileSize; aStyleConfig[13] = ss_FileSize; aStyleConfig[14] = ss_FileSize; aStyleConfig[15] = ss_FileSize; aStyleConfig[45] = ss_FileSize; } else { ss_FileSize = ""; } if (ss_FileBrowse.equals("0") || ss_FileBrowse.equals("1")) { aStyleConfig[43] = ss_FileBrowse; } else { ss_FileBrowse = ""; } if (myUtil.IsInt(ss_SpaceSize)) { aStyleConfig[78] = ss_SpaceSize; } else { ss_SpaceSize = ""; } if (!ss_PathMode.equals("")) { aStyleConfig[19] = ss_PathMode; } if (!ss_PathUpload.equals("")) { aStyleConfig[3] = ss_PathUpload; } if (!ss_PathCode.equals("")) { aStyleConfig[23] = ss_PathCode; } if (!ss_PathView.equals("")) { aStyleConfig[22] = ss_PathView; } sCusDir = ss_PathCusDir; } sBaseUrl = aStyleConfig[19]; nAllowBrowse = Integer.valueOf(aStyleConfig[43]).intValue(); if (nAllowBrowse != 1) { out.print(getOutScript("alert('Do not allow browse!')")); out.close(); return; } if (!sCusDir.equals("")) { sCusDir = myUtil.replace(sCusDir, "\\", "/"); if ((sCusDir.startsWith("/")) || (sCusDir.startsWith(".")) || (sCusDir.endsWith(".")) || (sCusDir.indexOf("./") >= 0) || (sCusDir.indexOf("/.") >= 0) || (sCusDir.indexOf("//") >= 0) || (sCusDir.indexOf("..") >= 0)) { sCusDir = ""; } else { if (!sCusDir.endsWith("/")) { sCusDir = sCusDir + "/"; } } } sUploadDir = aStyleConfig[3]; if (!sBaseUrl.equals("3")) { sUploadDir = myUtil.getRealPathFromRelative(m_request.getServletPath(), sUploadDir); } sUploadDir = GetSlashPath(sUploadDir); sUploadDir = sUploadDir + myUtil.replace(myUtil.replace(sCusDir, "/", sFileSeparator), "\\", sFileSeparator); if (sType.equals("FILE")) { sAllowExt = aStyleConfig[6]; } else if (sType.equals("MEDIA")) { sAllowExt = aStyleConfig[9]; } else if (sType.equals("FLASH")) { sAllowExt = aStyleConfig[7]; } else { sAllowExt = aStyleConfig[8]; } sPathShareImage = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/image/")); sPathShareFlash = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/flash/")); sPathShareMedia = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/media/")); sPathShareOther = GetSlashPath( myUtil.getRealPathFromRelative(m_request.getServletPath(), "sharefile/other/")); String s_Out = ""; if (sAction.equals("FILE")) { String s_ReturnFlag = myUtil.dealNull(m_request.getParameter("returnflag")); String s_FolderType = myUtil.dealNull(m_request.getParameter("foldertype")); String s_Dir = myUtil.dealNull(m_request.getParameter("dir")); s_Dir = java.net.URLDecoder.decode(s_Dir, "UTF-" + "8"); String s_CurrDir = ""; if (s_FolderType.equals("upload")) { s_CurrDir = sUploadDir; } else if (s_FolderType.equals("shareimage")) { sAllowExt = ""; s_CurrDir = sPathShareImage; } else if (s_FolderType.equals("shareflash")) { sAllowExt = ""; s_CurrDir = sPathShareFlash; } else if (s_FolderType.equals("sharemedia")) { sAllowExt = ""; s_CurrDir = sPathShareMedia; } else { s_FolderType = "shareother"; sAllowExt = ""; s_CurrDir = sPathShareOther; } s_Dir = myUtil.replace(s_Dir, "\\", "/"); if ((s_Dir.startsWith("/")) || (s_Dir.startsWith(".")) || (s_Dir.endsWith(".")) || (s_Dir.indexOf("./") >= 0) || (s_Dir.indexOf("/.") >= 0) || (s_Dir.indexOf("//") >= 0) || (s_Dir.indexOf("..") >= 0)) { s_Dir = ""; } String s_Dir2 = myUtil.replace(s_Dir, "/", sFileSeparator); s_Dir2 = myUtil.replace(s_Dir2, "\\", sFileSeparator); if (!s_Dir.equals("")) { if (CheckValidDir(s_CurrDir + s_Dir2)) { s_CurrDir += s_Dir2; } else { s_Dir = ""; } } if (CheckValidDir(s_CurrDir)) { File file = new File(s_CurrDir); File[] filelist = file.listFiles(); if (filelist != null && filelist.length > 0) { int n = -1; for (int i = 0; i < filelist.length; i++) { if (filelist[i].isFile()) { String s_FileName = filelist[i].getName(); String s_FileExt = s_FileName.substring(s_FileName.lastIndexOf(".") + 1); s_FileExt = s_FileExt.toLowerCase(); if (CheckValidExt(sAllowExt, s_FileExt)) { n++; s_Out = s_Out + "arr[" + String.valueOf(n) + "]=new Array(\"" + s_FileName + "\", \"" + String.valueOf(convertFileSize(filelist[i].length())) + "\",\"" + formatDate(new Date(filelist[i].lastModified())) + "\");\n"; } } } } } s_Out = "var arr = new Array();\n" + s_Out + "parent.setFileList('" + s_ReturnFlag + "', '" + s_FolderType + "', '" + s_Dir + "', arr);"; out.print(getOutScript(s_Out)); } else { s_Out = "var arrUpload = new Array();\n"; s_Out += "var arrShareImage = new Array();\n"; s_Out += "var arrShareFlash = new Array();\n"; s_Out += "var arrShareMedia = new Array();\n"; s_Out += "var arrShareOther = new Array();\n"; s_Out += GetFolderTree(sUploadDir, "Upload", 1, 0).get(0).toString(); sAllowExt = ""; if (sType.equals("FILE")) { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); s_Out += GetFolderTree(sPathShareOther, "ShareOther", 1, 0).get(0).toString(); } else if (sType.equals("MEDIA")) { s_Out += GetFolderTree(sPathShareMedia, "ShareMedia", 1, 0).get(0).toString(); } else if (sType.equals("FLASH")) { s_Out += GetFolderTree(sPathShareFlash, "ShareFlash", 1, 0).get(0).toString(); } else { s_Out += GetFolderTree(sPathShareImage, "ShareImage", 1, 0).get(0).toString(); } s_Out += "parent.setFolderList(arrUpload, arrShareImage, arrShareFlash, arrShareMedia, arrShareOther);"; out.print(getOutScript(s_Out)); } }
private void cleanup(File directory) { // Clean up from old installations, removing or renaming files. // Note that directory is the parent of the CTP directory // unless the original installation was done by Bill Weadock's // all-in-one installer for Windows. // Get a file pointing to the CTP directory. // This might be the current directory, or // it might be the CTP child. File dir; if (directory.getName().equals("RSNA")) dir = directory; else dir = new File(directory, "CTP"); // If CTP.jar exists in this directory, it is a really // old CTP main file - not used anymore File ctp = new File(dir, "CTP.jar"); if (ctp.exists()) ctp.delete(); // These are old names for the Launcher.jar file File launcher = new File(dir, "CTP-launcher.jar"); if (launcher.exists()) launcher.delete(); launcher = new File(dir, "TFS-launcher.jar"); if (launcher.exists()) launcher.delete(); // Delete the obsolete CTP-runner.jar file File runner = new File(dir, "CTP-runner.jar"); if (runner.exists()) runner.delete(); // Delete the obsolete MIRC-copier.jar file File copier = new File(dir, "MIRC-copier.jar"); if (copier.exists()) copier.delete(); // Rename the old versions of the properties files File oldprops = new File(dir, "CTP-startup.properties"); File newprops = new File(dir, "CTP-launcher.properties"); File correctprops = new File(dir, "Launcher.properties"); if (oldprops.exists()) { if (newprops.exists() || correctprops.exists()) oldprops.delete(); else oldprops.renameTo(correctprops); } if (newprops.exists()) { if (correctprops.exists()) newprops.delete(); else newprops.renameTo(correctprops); } // Get rid of obsolete startup and shutdown programs File startup = new File(dir, "CTP-startup.jar"); if (startup.exists()) startup.delete(); File shutdown = new File(dir, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); // Get rid of the obsolete linux directory File linux = new File(dir, "linux"); if (linux.exists()) { startup = new File(linux, "CTP-startup.jar"); if (startup.exists()) startup.delete(); shutdown = new File(linux, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); linux.delete(); } // clean up the libraries directory File libraries = new File(dir, "libraries"); if (libraries.exists()) { // remove obsolete versions of the slf4j libraries // and the dcm4che-imageio libraries File[] files = libraries.listFiles(); for (File file : files) { if (file.isFile()) { String name = file.getName(); if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) { file.delete(); } } } // remove the email subdirectory File email = new File(libraries, "email"); deleteAll(email); // remove the xml subdirectory File xml = new File(libraries, "xml"); deleteAll(xml); // remove the sftp subdirectory File sftp = new File(libraries, "sftp"); deleteAll(xml); // move edtftpj.jar to the ftp directory File edtftpj = new File(libraries, "edtftpj.jar"); if (edtftpj.exists()) { File ftp = new File(libraries, "ftp"); ftp.mkdirs(); File ftpedtftpj = new File(ftp, "edtftpj.jar"); edtftpj.renameTo(ftpedtftpj); } } // remove the obsolete xml library under dir File xml = new File(dir, "xml"); deleteAll(xml); // remove the dicom profiles so any // obsolete files will disappear File profiles = new File(dir, "profiles"); File dicom = new File(profiles, "dicom"); deleteAll(dicom); dicom.mkdirs(); // Remove the index.html file so it will be rebuilt from // example-index.html when the system next starts. File root = new File(dir, "ROOT"); if (root.exists()) { File index = new File(root, "index.html"); index.delete(); } }
private File getFile(File dir, String nameStart, String nameEnd) { File[] files = dir.listFiles(new NameFilter(nameStart, nameEnd)); if (files.length == 0) return null; return files[0]; }
private static void copy( @NotNull File src, @NotNull File dest, ConfigImportSettings settings, File oldInstallationHome) throws IOException { src = src.getCanonicalFile(); dest = dest.getCanonicalFile(); if (!src.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", src.getAbsolutePath())); } if (!dest.isDirectory()) { throw new IOException( ApplicationBundle.message( "config.import.invalid.directory.error", dest.getAbsolutePath())); } if (FileUtil.filesEqual(src, dest)) { return; } FileUtil.ensureExists(dest); File[] childFiles = src.listFiles( new FilenameFilter() { @Override public boolean accept(@NotNull File dir, @NotNull String name) { // Don't copy plugins just imported. They're most probably incompatible with newer // idea version. return !StringUtil.startsWithChar(name, '.') && !name.equals(PLUGINS_PATH); } }); if (childFiles == null || childFiles.length == 0) { return; } for (File from : childFiles) { File to = new File(dest, from.getName()); if (from.isDirectory()) { FileUtil.copyDir(from, to, false); } else { FileUtil.copy(from, to); } } File plugins = new File(src, PLUGINS_PATH); if (!loadOldPlugins(plugins, dest) && SystemInfo.isMac) { File oldPluginsDir = getOldPath( oldInstallationHome, settings, PathManager.PROPERTY_PLUGINS_PATH, new Function<String, String>() { @Override public String fun(String pathSelector) { return PathManager.getDefaultPluginPathFor(pathSelector); } }); if (oldPluginsDir == null) { // e.g. installation home referred to config home. Try with default selector, same as config // name oldPluginsDir = new File(PathManager.getDefaultPluginPathFor(src.getName())); } loadOldPlugins(oldPluginsDir, dest); } }
/** * Process a directory potentially full of fonts * * @param dir The directory of fonts to process * @param fonts The fonts list to add to */ private static void processFontDirectory(File dir, ArrayList fonts) { if (!dir.exists()) { return; } if (processed.contains(dir)) { return; } processed.add(dir); File[] sources = dir.listFiles(); if (sources == null) { return; } for (int j = 0; j < sources.length; j++) { File source = sources[j]; if (source.getName().equals(".")) { continue; } if (source.getName().equals("..")) { continue; } if (source.isDirectory()) { processFontDirectory(source, fonts); continue; } if (source.getName().toLowerCase().endsWith(".ttf")) { try { if (statusListener != null) { statusListener.updateStatus("Processing " + source.getName()); } FontData data = new FontData(new FileInputStream(source), 1); fonts.add(data); String famName = data.getFamilyName(); if (!families.contains(famName)) { families.add(famName); } boolean bo = data.getJavaFont().isBold(); boolean it = data.getJavaFont().isItalic(); if ((bo) && (it)) { bolditalic.put(famName, data); } else if (bo) { bold.put(famName, data); } else if (it) { italic.put(famName, data); } else { plain.put(famName, data); } } catch (Exception e) { if (DEBUG) { System.err.println( "Unable to process: " + source.getAbsolutePath() + " (" + e.getClass() + ": " + e.getMessage() + ")"); } if (statusListener != null) { statusListener.updateStatus("Unable to process: " + source.getName()); } } } } }
public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) { this.parentFrame = parentFrame; Container cp = this; qsadminMain.setGUI(this); cp.setLayout(new BorderLayout(5, 5)); headerPanel = new HeaderPanel(qsadminMain, parentFrame); mainCommandPanel = new MainCommandPanel(qsadminMain); cmdConsole = new CmdConsole(qsadminMain); propertiePanel = new PropertiePanel(qsadminMain); if (headerPanel == null || mainCommandPanel == null || cmdConsole == null || propertiePanel == null) { throw new RuntimeException("Loading of one of gui component failed."); } headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); cp.add(headerPanel, BorderLayout.NORTH); JScrollPane propertieScrollPane = new JScrollPane(propertiePanel); // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole); splitPane.setOneTouchExpandable(false); splitPane.setDividerLocation(250); // splitPane.setDividerLocation(0.70); tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.addTab("Main", ball, splitPane, "Main Commands"); tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel"); QSAdminPluginConfig qsAdminPluginConfig = null; PluginPanel pluginPanel = null; // -- start of loadPlugins try { File xmlFile = null; ClassLoader classLoader = null; Class mainClass = null; File file = new File(pluginDir); File dirs[] = null; if (file.canRead()) dirs = file.listFiles(new DirFileList()); for (int i = 0; dirs != null && i < dirs.length; i++) { xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml"); if (xmlFile.canRead()) { qsAdminPluginConfig = PluginConfigReader.read(xmlFile); if (qsAdminPluginConfig.getActive().equals("yes") && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) { classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath()); mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass()); logger.fine("Got PluginMainClass " + mainClass); pluginPanel = (PluginPanel) mainClass.newInstance(); if (JPanel.class.isInstance(pluginPanel) == true) { logger.info("Loading plugin : " + qsAdminPluginConfig.getName()); pluginPanelMap.put("" + (2 + i), pluginPanel); plugins.add(pluginPanel); tabbedPane.addTab( qsAdminPluginConfig.getName(), ball, (JPanel) pluginPanel, qsAdminPluginConfig.getDesc()); pluginPanel.setQSAdminMain(qsadminMain); pluginPanel.init(); } } else { logger.info( "Plugin " + dirs[i] + " is disabled so skipping " + qsAdminPluginConfig.getActive() + ":" + qsAdminPluginConfig.getType()); } } else { logger.info("No plugin configuration found in " + xmlFile + " so skipping"); } } } catch (Exception e) { logger.warning("Error loading plugin : " + e); logger.fine("StackTrace:\n" + MyString.getStackTrace(e)); } // -- end of loadPlugins tabbedPane.addChangeListener( new ChangeListener() { int selected = -1; int oldSelected = -1; public void stateChanged(ChangeEvent e) { // if plugin selected = tabbedPane.getSelectedIndex(); if (selected >= 2) { ((PluginPanel) pluginPanelMap.get("" + selected)).activated(); } if (oldSelected >= 2) { ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated(); } oldSelected = selected; } }); // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); cp.add(tabbedPane, BorderLayout.CENTER); buildMenu(); }
public void secureImport() { JFileChooser imp = new JFileChooser(); imp.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); imp.setMultiSelectionEnabled(true); int ret = imp.showOpenDialog(frm); if (ret != JFileChooser.APPROVE_OPTION) { return; } File[] fis = imp.getSelectedFiles(); ArrayList<String> impJobs = new ArrayList<String>(); boolean dirs = false; for (File fi : fis) { if (fi.isDirectory()) { dirs = true; File lib = new File(fi, LIBRARY_NAME); if (lib.exists()) { try { Scanner sca = new Scanner(lib); while (sca.hasNextLine()) { String nm = sca.nextLine(); String date = sca.nextLine(); String tags = sca.nextLine(); File addr = new File(fi, nm); if (addr.exists() && !addr.isDirectory()) impJobs.add(impJob(addr, date, tags)); } sca.close(); } catch (IOException exc) { // add nothing? } } else { for (File cont : fi.listFiles()) if (!cont.isDirectory()) impJobs.add(impJob(cont, null, null)); } } else { impJobs.add(impJob(fi, null, null)); } } if (impJobs.size() > 1 || dirs) { // dont bother user if selected single file String shw = "Importing:"; if (impJobs.size() > 30) shw = null; int pcount = 0; for (String jb : impJobs) { String[] prts = jb.split(",", 4); // import jobs have 4 parts, import, name, date, tags if (shw != null) shw = shw + "\n - " + new File(prts[1]).getName(); if (!prts[3].equalsIgnoreCase(Storage.NEW_TAG)) { pcount++; if (shw != null) shw = shw + " []"; } } if (shw == null) shw = "importing "; else shw = shw + "\n"; shw = shw + impJobs.size() + "(" + pcount + ") files"; if (JOptionPane.showConfirmDialog(frm, shw, "Confirm Import", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) return; } synchronized (jobs) { for (String j : impJobs) { if (priorityExport) jobs.addLast(j); else jobs.addFirst(j); } } updateStatus(); }
public boolean accept(File file) { if (file.isFile()) size += file.length(); else file.listFiles(this); return false; }