public static File getMetaInfoDir(byte[] torrentHash) throws TorrentException { String oneSwarmMetaInfoDir = SystemProperties.getMetaInfoPath(); String torrentHex = new String(Base32.encode(torrentHash)); char firstChar = torrentHex.charAt(0); String torrentMetaInfoDirString = oneSwarmMetaInfoDir + SystemProperties.SEP + firstChar + SystemProperties.SEP + torrentHex; File torrentMetaInfoDir = new File(torrentMetaInfoDirString); torrentMetaInfoDir.mkdirs(); if (torrentMetaInfoDir.isDirectory()) { return torrentMetaInfoDir; } return null; }
public static String bind_audio_scan() { long start = System.currentTimeMillis(); StringBuilder out = new StringBuilder(); out.append("bind audio scan..."); String metainfoPath = SystemProperties.getMetaInfoPath(); UpdatingFileTree metainfo = new UpdatingFileTree(new File(metainfoPath)); List<UpdatingFileTree> q = new ArrayList<UpdatingFileTree>(); q.add(metainfo); while (q.isEmpty() == false) { UpdatingFileTree curr = q.remove(0); if (curr.isDirectory()) { q.addAll(curr.getChildren()); } else if (curr.getThisFile().getName().equals(PreviewImageGenerator.AUDIO_INFO_FILE)) { String hashStr = curr.getThisFile().getParentFile().getName(); byte[] hashBytes = Base32.decode(hashStr); DownloadManager dm = AzureusCoreImpl.getSingleton() .getGlobalManager() .getDownloadManager(new HashWrapper(hashBytes)); // old metainfo and/or bogus directory name if (dm == null) { continue; } logger.finest("rebind audio considering: " + dm.getDisplayName()); out.append("considered: " + dm.getDisplayName()); if (dm.getDownloadState().getAttribute(FileCollection.ONESWARM_ARTIST_ATTRIBUTE) == null && dm.getDownloadState().getAttribute(FileCollection.ONESWARM_ALBUM_ATTRIBUTE) == null) { logger.finer("should rebind audio " + dm.getDisplayName()); out.append("rebinding for: " + dm.getDisplayName()); bind_audio_xml(dm); } } } String str = "binding audio scan took: " + (System.currentTimeMillis() - start); logger.info(str); out.append(str); return out.toString(); }