Exemplo n.º 1
0
        public async Task <TorrentManager> AddAsync(Torrent torrent, string saveDirectory, TorrentSettings settings)
        {
            await MainLoop.SwitchThread();

            var metadata = new BEncodedDictionary {
                { "info", BEncodedValue.Decode(torrent.InfoMetadata) }
            };

            var metadataCachePath = Settings.GetMetadataPath(torrent.InfoHash);

            Directory.CreateDirectory(Path.GetDirectoryName(metadataCachePath));
            File.WriteAllBytes(metadataCachePath, metadata.Encode());

            return(await AddAsync(null, torrent, saveDirectory, settings));
        }
Exemplo n.º 2
0
        async ReusableTask ITorrentFileStream.WriteAsync(byte[] buffer, int offset, int count)
        {
            // This is more memory efficient than calling Stream.
            // and has no noticable impact on performance
            await MainLoop.SwitchThread();

            Write(buffer, offset, count);
        }
Exemplo n.º 3
0
        public static async Task <ClientEngine> RestoreStateAsync(string pathToStateFile)
        {
            await MainLoop.SwitchThread();

            return(await RestoreStateAsync(File.ReadAllBytes(pathToStateFile)));
        }