use of com.biglybt.core.config.impl.ConfigurationParameterNotFoundException in project BiglyBT by BiglySoftware.
the class TorrentOpenOptions method getSmartDestDir.
private String getSmartDestDir() {
String sSmartDir = sDestDir;
try {
String name = getTorrentName();
String torrentFileName = sFileName == null ? "" : new File(sFileName).getName().replaceFirst("\\.torrent$", "");
int totalSegmentsLengths = 0;
String[][] segments = { name.split("[^a-zA-Z]+"), torrentFileName.split("[^a-zA-Z]+") };
List downloadManagers = CoreFactory.getSingleton().getGlobalManager().getDownloadManagers();
for (int x = 0; x < segments.length; x++) {
String[] segmentArray = segments[x];
for (int i = 0; i < segmentArray.length; i++) {
int l = segmentArray[i].length();
if (l <= 1) {
continue;
}
segmentArray[i] = segmentArray[i].toLowerCase();
totalSegmentsLengths += l;
}
}
int maxMatches = 0;
DownloadManager match = null;
long scanStarted = SystemTime.getCurrentTime();
for (Iterator iter = downloadManagers.iterator(); iter.hasNext(); ) {
DownloadManager dm = (DownloadManager) iter.next();
if (dm.getState() == DownloadManager.STATE_ERROR) {
continue;
}
DownloadManagerState dms = dm.getDownloadState();
if (dms.getFlag(DownloadManagerState.FLAG_LOW_NOISE) || dms.getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD)) {
continue;
}
int numMatches = 0;
String dmName = dm.getDisplayName().toLowerCase();
for (int x = 0; x < segments.length; x++) {
String[] segmentArray = segments[x];
for (int i = 0; i < segmentArray.length; i++) {
int l = segmentArray[i].length();
if (l <= 1) {
continue;
}
String segment = segmentArray[i];
if (dmName.contains(segment)) {
numMatches += l;
}
}
}
if (numMatches > maxMatches) {
maxMatches = numMatches;
match = dm;
}
long scanTime = SystemTime.getCurrentTime() - scanStarted;
if (match != null && scanTime > 500) {
break;
}
if (match == null && scanTime > 1000) {
break;
}
}
if (match != null) {
// System.out.println(match + ": " + (maxMatches * 100 / totalSegmentsLengths) + "%\n");
int iMatchLevel = (maxMatches * 100 / totalSegmentsLengths);
if (iMatchLevel >= 30) {
File f = match.getSaveLocation();
if (!f.isDirectory() || match.getDiskManagerFileInfo().length > 1) {
// don't place data within another torrent's data dir
f = f.getParentFile();
}
if (f != null && f.isDirectory()) {
sSmartDir = f.getAbsolutePath();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (sSmartDir.length() == 0) {
try {
return ConfigurationDefaults.getInstance().getStringParameter(PARAM_DEFSAVEPATH);
} catch (ConfigurationParameterNotFoundException e) {
}
}
return sSmartDir;
}
Aggregations