예제 #1
0
        async Task <TorrentManager> AddAsync(MagnetLink magnetLink, Torrent torrent, string saveDirectory, TorrentSettings settings)
        {
            saveDirectory = string.IsNullOrEmpty(saveDirectory) ? Environment.CurrentDirectory : Path.GetFullPath(saveDirectory);
            TorrentManager manager;

            if (magnetLink != null)
            {
                var metadataSaveFilePath = Settings.GetMetadataPath(magnetLink.InfoHash);
                manager = new TorrentManager(magnetLink, saveDirectory, settings, metadataSaveFilePath);
                if (Settings.AutoSaveLoadMagnetLinkMetadata && Torrent.TryLoad(metadataSaveFilePath, out torrent) && torrent.InfoHash == magnetLink.InfoHash)
                {
                    manager.SetMetadata(torrent);
                }
            }
            else
            {
                manager = new TorrentManager(torrent, saveDirectory, settings);
            }

            await Register(manager, true);

            await manager.MaybeLoadFastResumeAsync();

            return(manager);
        }
        async Task<TorrentManager> AddAsync (MagnetLink? magnetLink, Torrent? torrent, string saveDirectory, TorrentSettings settings)
        {
            await MainLoop;

            saveDirectory = string.IsNullOrEmpty (saveDirectory) ? Environment.CurrentDirectory : Path.GetFullPath (saveDirectory);
            TorrentManager manager;
            if (magnetLink != null) {
                var metadataSaveFilePath = Settings.GetMetadataPath (magnetLink.InfoHashes);
                manager = new TorrentManager (this, magnetLink, saveDirectory, settings);
                if (Settings.AutoSaveLoadMagnetLinkMetadata && Torrent.TryLoad (metadataSaveFilePath, out torrent) && torrent.InfoHashes == magnetLink.InfoHashes)
                    manager.SetMetadata (torrent);
            } else if (torrent != null) {
                manager = new TorrentManager (this, torrent, saveDirectory, settings);
            } else {
                throw new InvalidOperationException ($"You must pass a non-null {nameof (magnetLink)} or {nameof (torrent)}");
            }

            await Register (manager, true);
            await manager.MaybeLoadFastResumeAsync ();

            return manager;
        }