use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.
the class GuiContext method registerAdapter.
/**
* <p>注册GUI事件默认适配器</p>
*/
public static final void registerAdapter() {
GuiContext.register(new ShowEventAdapter());
GuiContext.register(new HideEventAdapter());
GuiContext.register(new ExitEventAdapter());
GuiContext.register(new BuildEventAdapter());
GuiContext.register(new AlertEventAdapter());
GuiContext.register(new NoticeEventAdapter());
GuiContext.register(new ResponseEventAdapter());
GuiContext.register(new MultifileEventAdapter());
GuiContext.register(new RefreshTaskListEventAdapter());
GuiContext.register(new RefreshTaskStatusEventAdapter());
}
use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.
the class SnailTest method testTorrent.
@Test
void testTorrent() throws DownloadException {
final String torrentPath = "E:\\snail\\0B156834B59B0FF64EE0C9305D4D6EDE421196E6.torrent";
final var snail = SnailBuilder.newBuilder().enableTorrent().buildSync();
assertNotNull(snail);
// 解析种子文件
final var torrent = TorrentContext.loadTorrent(torrentPath);
// 过滤下载文件
final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).filter(path -> path.endsWith(".mkv")).collect(Collectors.toList());
// 设置下载文件
GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
// 注册文件选择事件
GuiContext.register(new MultifileEventAdapter());
// 开始下载
snail.download(torrentPath);
snail.lockDownload();
}
use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.
the class TorrentDownloaderTest method testTorrentDownloaderBuild.
@Test
void testTorrentDownloaderBuild() throws DownloadException {
final String url = "E://snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent";
ProtocolContext.getInstance().register(TorrentProtocol.getInstance()).available(true);
final var torrent = TorrentContext.loadTorrent(url);
final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).collect(Collectors.toList());
GuiContext.register(new MultifileEventAdapter());
GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
final var taskSession = TorrentProtocol.getInstance().buildTaskSession(url);
final var downloader = taskSession.buildDownloader();
// downloader.run(); // 不下载
assertNotNull(downloader);
final var file = new File(taskSession.getFile());
assertTrue(file.exists());
FileUtils.delete(taskSession.getFile());
taskSession.delete();
}
use of com.acgist.snail.gui.event.adapter.MultifileEventAdapter in project snail by acgist.
the class TorrentDownloaderTest method testTorrentDownloader.
@Test
void testTorrentDownloader() throws DownloadException {
TorrentInitializer.newInstance().sync();
final String url = "E://snail/902FFAA29EE632C8DC966ED9AB573409BA9A518E.torrent";
ProtocolContext.getInstance().register(TorrentProtocol.getInstance()).available(true);
final var torrent = TorrentContext.loadTorrent(url);
final var list = torrent.getInfo().files().stream().filter(TorrentFile::notPaddingFile).map(TorrentFile::path).collect(Collectors.toList());
GuiContext.register(new MultifileEventAdapter());
GuiContext.getInstance().files(DescriptionWrapper.newEncoder(list).serialize());
final var taskSession = TorrentProtocol.getInstance().buildTaskSession(url);
final var downloader = taskSession.buildDownloader();
downloader.run();
final var file = new File(taskSession.getFile());
assertTrue(file.exists());
assertTrue(ArrayUtils.isNotEmpty(file.list()));
FileUtils.delete(taskSession.getFile());
taskSession.delete();
}
Aggregations