public void setDownloadFolder(String dest) { filePackage.setDownloadDirectory(dest); }
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; } }