protected void processDir(TOTorrentFileHasher hasher, File dir, Vector encoded, String root) throws TOTorrentException { File[] dir_file_list = dir.listFiles(); if (dir_file_list == null) { throw (new TOTorrentException( "TOTorrentCreate: directory '" + dir.getAbsolutePath() + "' returned error when listing files in it", TOTorrentException.RT_FILE_NOT_FOUND)); } // sort contents so that multiple encodes of a dir always // generate same torrent List file_list = new ArrayList(Arrays.asList(dir_file_list)); Collections.sort(file_list); long offset = 0; for (int i = 0; i < file_list.size(); i++) { File file = (File) file_list.get(i); String file_name = file.getName(); if (!(file_name.equals(".") || file_name.equals(".."))) { if (file.isDirectory()) { if (root.length() > 0) { file_name = root + File.separator + file_name; } processDir(hasher, file, encoded, file_name); } else { if (!ignoreFile(file_name)) { if (root.length() > 0) { file_name = root + File.separator + file_name; } long length = hasher.add(file); TOTorrentFileImpl tf = new TOTorrentFileImpl(this, offset, length, file_name); offset += length; if (add_other_hashes) { byte[] ed2k_digest = hasher.getPerFileED2KDigest(); byte[] sha1_digest = hasher.getPerFileSHA1Digest(); // System.out.println( "file:ed2k = " + ByteFormatter.nicePrint( ed2k_digest, true )); // System.out.println( "file:sha1 = " + ByteFormatter.nicePrint( sha1_digest, true )); tf.setAdditionalProperty("sha1", sha1_digest); tf.setAdditionalProperty("ed2k", ed2k_digest); } encoded.addElement(tf); } } } } }
public static licenceDetails getFullFeatureDetails() { if (featman == null) { Debug.out("featman null"); return null; } TreeMap<Long, Object[]> mapOrder = new TreeMap<Long, Object[]>(Collections.reverseOrder()); FeatureDetails[] featureDetails = featman.getFeatureDetails("dvdburn"); // if any of the feature details are still valid, we have a full for (FeatureDetails fd : featureDetails) { Licence licence = fd.getLicence(); int state = licence.getState(); if (state == Licence.LS_ACTIVATION_DENIED) { mapOrder.put(-1L, new Object[] {licence, Long.valueOf(0)}); continue; } else if (state == Licence.LS_CANCELLED) { mapOrder.put(-2L, new Object[] {licence, Long.valueOf(0)}); continue; } else if (state == Licence.LS_INVALID_KEY) { mapOrder.put(-3L, new Object[] {licence, Long.valueOf(0)}); continue; } else if (state == Licence.LS_REVOKED) { mapOrder.put(-4L, new Object[] {licence, Long.valueOf(0)}); continue; } else if (state == Licence.LS_PENDING_AUTHENTICATION) { mapOrder.put(-6L, new Object[] {licence, Long.valueOf(0)}); continue; } long now = SystemTime.getCurrentTime(); Long lValidUntil = (Long) fd.getProperty(FeatureDetails.PR_VALID_UNTIL); Long lValidOfflineUntil = (Long) fd.getProperty(FeatureDetails.PR_OFFLINE_VALID_UNTIL); if (lValidUntil == null && lValidOfflineUntil == null) { continue; } long minValidUntil = -1; long maxValidUntil = -1; if (lValidUntil != null) { minValidUntil = maxValidUntil = lValidUntil.longValue(); if (minValidUntil < now) { mapOrder.put(minValidUntil, new Object[] {licence, Long.valueOf(minValidUntil)}); continue; } } if (lValidOfflineUntil != null) { long validOfflineUntil = lValidOfflineUntil.longValue(); if (validOfflineUntil < now) { mapOrder.put(validOfflineUntil, new Object[] {licence, Long.valueOf(maxValidUntil)}); continue; } if (maxValidUntil == -1 || validOfflineUntil > maxValidUntil) { maxValidUntil = validOfflineUntil; } } mapOrder.put(maxValidUntil, new Object[] {licence, minValidUntil}); } if (mapOrder.size() == 0) { return null; } Long firstKey = mapOrder.firstKey(); Object[] objects = mapOrder.get(firstKey); Licence licence = (Licence) objects[0]; return new licenceDetails(firstKey.longValue(), ((Long) objects[1]).longValue(), licence); }