static { try { if (CrossSystem.isWindows()) { supported = com.sun.jna.platform.win32.W32FileUtils.getInstance().hasTrash(); } else if (CrossSystem.isMac()) { supported = com.sun.jna.platform.mac.MacFileUtils.getInstance().hasTrash(); } } catch (final Throwable e) { e.printStackTrace(); } }
static { try { if (CrossSystem.isWindows()) { System.load(JDUtilities.getResourceFile("libs/rtmp.dll").getAbsolutePath()); } else if (CrossSystem.isLinux()) { System.load(JDUtilities.getResourceFile("libs/librtmp.so").getAbsolutePath()); } } catch (Exception e) { System.out.println("Error: " + e); } }
@Override public boolean onDoubleClick(MouseEvent e, AbstractNode value) { if (CrossSystem.isOpenFileSupported() && value != null) { final File ret = LinkTreeUtils.getDownloadDirectory(value); if (ret != null && ret.exists() && ret.isDirectory()) { CrossSystem.openFile(ret); } return true; } return false; }
/** * @param name * @param name2 * @return */ private boolean startsWith(final String name, final String name2) { if (CrossSystem.isWindows()) { // return name.toLowerCase(Locale.ENGLISH).startsWith(name2.toLowerCase(Locale.ENGLISH)); } return name.startsWith(name2); }
/** * @param name * @param findName * @return */ private boolean equals(final String name, final String findName) { if (CrossSystem.isWindows()) { return name.equalsIgnoreCase(findName); } return name.equals(findName); }
public static void moveToTrash(File... files) throws IOException { if (isTrashSupported()) { if (CrossSystem.isWindows()) { for (File f : files) { if (!f.exists()) { throw new FileNotFoundException(f.getAbsolutePath()); } } com.sun.jna.platform.win32.W32FileUtils.getInstance().moveToTrash(files); } else if (CrossSystem.isMac()) { for (File f : files) { if (!f.exists()) { throw new FileNotFoundException(f.getAbsolutePath()); } } com.sun.jna.platform.mac.MacFileUtils.getInstance().moveToTrash(files); } } }
public static File getDownloadDirectory(String path) { if (path == null) return null; if (CrossSystem.isAbsolutePath(path)) { return new File(path); } else { return new File( org.jdownloader.settings.staticreferences.CFG_GENERAL.DEFAULT_DOWNLOAD_FOLDER.getValue(), path); } }
@Override public void actionPerformed() { ExtFileChooserDialog d = new ExtFileChooserDialog(0, _GUI._.ExportAllMenusAdvancedAction_actionPerformed(), null, null); d.setFileFilter(new FileFilter() { @Override public String getDescription() { return _GUI._.lit_directory(); } @Override public boolean accept(File f) { return f.isDirectory(); } }); d.setFileSelectionMode(FileChooserSelectionMode.DIRECTORIES_ONLY); d.setMultiSelection(false); d.setStorageID("menus"); d.setType(FileChooserType.SAVE_DIALOG); try { Dialog.getInstance().showDialog(d); File saveTo = d.getSelectedFile(); File file = null; int i = 0; while (file == null || file.exists()) { file = new File(saveTo, "JDownloader Menustructure " + i); i++; } file.mkdirs(); MenuManagerDownloadTabBottomBar.getInstance().exportTo(file); MenuManagerDownloadTableContext.getInstance().exportTo(file); MenuManagerLinkgrabberTabBottombar.getInstance().exportTo(file); MenuManagerLinkgrabberTableContext.getInstance().exportTo(file); MenuManagerMainToolbar.getInstance().exportTo(file); MenuManagerTrayIcon.getInstance().exportTo(file); MenuManagerMainmenu.getInstance().exportTo(file); CrossSystem.openFile(file); } catch (DialogClosedException e1) { e1.printStackTrace(); } catch (DialogCanceledException e1) { e1.printStackTrace(); } catch (UnsupportedEncodingException e1) { Dialog.getInstance().showExceptionDialog(_GUI._.lit_error_occured(), e1.getMessage(), e1); } catch (IOException e1) { Dialog.getInstance().showExceptionDialog(_GUI._.lit_error_occured(), e1.getMessage(), e1); } }
public static Icon getIcon(final String name, final ExtensionsFilterInterface extension) { Icon newIcon = null; final String ext = Files.getExtension(name); if (CrossSystem.isWindows() && ext != null) { try { newIcon = CrossSystem.getMime().getFileIcon(ext, 16, 16); } catch (Throwable e) { LogController.CL().log(e); } } if (newIcon == null) { String iconID = null; if (extension != null && extension.getIconID() != null) { iconID = extension.getIconID(); } if (StringUtils.isEmpty(iconID)) { iconID = "file"; } newIcon = NewTheme.I().getIcon(iconID, 16); } return newIcon; }
@Override protected List<String> getJVMApplicationStartCommands(File root) { final java.util.List<String> jvmParameter = new ArrayList<String>(); jvmParameter.add(CrossSystem.getJavaBinary()); final List<String> lst = ManagementFactory.getRuntimeMXBean().getInputArguments(); for (final String h : lst) { if (h.equals("exit")) { getLogger().info("Workaround: removing buggy exit parameter"); /* JDownloaderExp.exe appends exit to jvm parameter list -> java cannot find mainclass anymore */ continue; } else if (h.startsWith("-agentlib:")) { continue; } else { jvmParameter.add(h); } } jvmParameter.add("-jar"); jvmParameter.add(Application.getJarName(RestartController.class)); return jvmParameter; }
private LinkedList<FilePackage> load(File file) { synchronized (SAVELOADLOCK) { LinkedList<FilePackage> ret = null; if (file != null && file.exists()) { ZipIOReader zip = null; try { zip = new ZipIOReader(file); /* lets restore the FilePackages from Json */ HashMap<Integer, FilePackage> map = new HashMap<Integer, FilePackage>(); DownloadControllerStorable dcs = null; InputStream is = null; for (ZipEntry entry : zip.getZipFiles()) { try { if (entry.getName().matches("^\\d+$")) { int packageIndex = Integer.parseInt(entry.getName()); is = zip.getInputStream(entry); byte[] bytes = IO.readStream((int) entry.getSize(), is); String json = new String(bytes, "UTF-8"); bytes = null; FilePackageStorable storable = JSonStorage.stringToObject(json, new TypeRef<FilePackageStorable>() {}, null); json = null; if (storable != null) { map.put(packageIndex, storable._getFilePackage()); } else { throw new WTFException("restored a null FilePackageStorable"); } } else if ("extraInfo".equalsIgnoreCase(entry.getName())) { is = zip.getInputStream(entry); byte[] bytes = IO.readStream((int) entry.getSize(), is); String json = new String(bytes, "UTF-8"); bytes = null; dcs = JSonStorage.stringToObject( json, new TypeRef<DownloadControllerStorable>() {}, null); json = null; } } finally { try { is.close(); } catch (final Throwable e) { } } } /* sort positions */ java.util.List<Integer> positions = new ArrayList<Integer>(map.keySet()); Collections.sort(positions); /* build final ArrayList of FilePackages */ java.util.List<FilePackage> ret2 = new ArrayList<FilePackage>(positions.size()); for (Integer position : positions) { ret2.add(map.get(position)); } if (dcs != null && JsonConfig.create(GeneralSettings.class).isConvertRelativePathesJDRoot()) { try { String oldRootPath = dcs.getRootPath(); if (!StringUtils.isEmpty(oldRootPath)) { String newRoot = JDUtilities.getJDHomeDirectoryFromEnvironment().getAbsolutePath(); /* * convert pathes relative to JDownloader root,only in jared version */ for (FilePackage pkg : ret2) { if (!CrossSystem.isAbsolutePath(pkg.getDownloadDirectory())) { /* no need to convert relative pathes */ continue; } String pkgPath = getDownloadDirectory(pkg).getAbsolutePath(); if (pkgPath.startsWith(oldRootPath + "/")) { /* * folder is inside JDRoot, lets update it */ String restPath = pkgPath.substring(oldRootPath.length()); String newPath = new File(newRoot, restPath).getAbsolutePath(); pkg.setDownloadDirectory(newPath); } } } } catch (final Throwable e) { /* this method can throw exceptions, eg in SVN */ logger.log(e); } } map = null; positions = null; ret = new LinkedList<FilePackage>(ret2); } catch (final Throwable e) { logger.log(e); } finally { try { zip.close(); } catch (final Throwable e) { } } } return ret; } }
public MenuContainerRoot createDefaultStructure() { MenuContainerRoot mr = new MenuContainerRoot(); mr.add(AddLinksContextMenuAction.class); mr.add(AddContainerContextMenuAction.class); mr.add(new SeperatorData()); // mr.add() mr.add(createSettingsMenu()); mr.add(new SeperatorData()); mr.add(new DownloadsTablePluginLink()); mr.add(new SeperatorData()); mr.add(new MenuItemData(new ActionData(OpenFileAction.class))); mr.add(new MenuItemData(new ActionData(OpenDirectoryAction.class))); mr.add(new MenuItemData(new ActionData(SortAction.class))); mr.add(new MenuItemData(new ActionData(EnabledAction.class))); mr.add(new MenuItemData(new ActionData(SkipAction.class))); mr.add(new SeperatorData()); mr.add(new MenuItemData(new ActionData(ForceDownloadAction.class))); mr.add(new MenuItemData(new ActionData(StopsignAction.class))); mr.add(new SeperatorData()); mr.add(createMoreMenu()); mr.add(new SeperatorData()); mr.add(setAccelerator(new MenuItemData(setName(setIconKey(new ActionData(GenericDeleteFromDownloadlistContextAction.class).putSetup(GenericDeleteFromDownloadlistAction.DELETE_ALL, true), IconKey.ICON_DELETE), _GUI._.DeleteQuickAction_DeleteQuickAction_object_())), CrossSystem.getDeleteShortcut())); mr.add(createDeleteMenu()); mr.add(new SeperatorData()); mr.add(PropertiesAction.class); mr.add(new SeperatorData()); mr.add(new MenuItemData(new ActionData(MenuManagerAction.class))); OptionalContainer opt; mr.add(opt = new OptionalContainer(false)); opt.add(CollapseExpandContextAction.class); opt.add(CopyGenericContextAction.class); return mr; }