//delete torrents from the previous import run
for (int i = 0; i < to_delete.size(); i++) {
TOTorrent torrent = (TOTorrent) to_delete.get(i);
try {
TorrentUtils.delete(torrent);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
to_delete.clear();
String[] currentFileList = folder.list(filename_filter);
if (currentFileList == null) {
Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR,
"There was a problem trying to get a listing of torrents from " + folder));
return;
}
for (int i = 0; i < currentFileList.length; i++) {
File file = new File(folder, currentFileList[i]);
// make sure we've got a valid torrent file before proceeding
try {
TOTorrent torrent = TorrentUtils.readFromFile(file, false);
if (global_manager.getDownloadManager(torrent) != null) {
if (Logger.isEnabled())
Logger.log(new LogEvent(LOGID, file.getAbsolutePath()
+ " is already being downloaded"));
// we can't touch the torrent file as it is (probably)
// being used for the download
} else {
byte[] hash = null;
try {
hash = torrent.getHash();
} catch (Exception e) { }
if (!save_torrents) {
File imported = new File(folder, file.getName() + ".imported");