Exemple #1
0
        public async Task SaveRestoreState_OneTorrentFile_NoContainingDirectory()
        {
            var pieceLength = Constants.BlockSize * 4;

            using var tmpDir = TempDir.Create();

            TestRig.CreateMultiFileTorrent(TorrentFile.Create(pieceLength, Constants.BlockSize, Constants.BlockSize * 2, Constants.BlockSize * 3), pieceLength, out BEncoding.BEncodedDictionary metadata);
            var metadataFile = Path.Combine(tmpDir.Path, "test.torrent");

            File.WriteAllBytes(metadataFile, metadata.Encode());

            var engine = new ClientEngine(EngineSettingsBuilder.CreateForTests(cacheDirectory: tmpDir.Path));
            await engine.AddStreamingAsync(metadataFile, "mySaveDirectory", new TorrentSettingsBuilder { CreateContainingDirectory = false }.ToSettings());

            var restoredEngine = await ClientEngine.RestoreStateAsync(await engine.SaveStateAsync());

            Assert.AreEqual(engine.Settings, restoredEngine.Settings);
            Assert.AreEqual(engine.Torrents[0].Torrent.Name, restoredEngine.Torrents[0].Torrent.Name);
            Assert.AreEqual(engine.Torrents[0].SavePath, restoredEngine.Torrents[0].SavePath);
            Assert.AreEqual(engine.Torrents[0].Settings, restoredEngine.Torrents[0].Settings);
            Assert.AreEqual(engine.Torrents[0].InfoHash, restoredEngine.Torrents[0].InfoHash);
            Assert.AreEqual(engine.Torrents[0].MagnetLink.ToV1String(), restoredEngine.Torrents[0].MagnetLink.ToV1String());

            Assert.AreEqual(engine.Torrents[0].Files.Count, restoredEngine.Torrents[0].Files.Count);
            for (int i = 0; i < engine.Torrents.Count; i++)
            {
                Assert.AreEqual(engine.Torrents[0].Files[i].FullPath, restoredEngine.Torrents[0].Files[i].FullPath);
                Assert.AreEqual(engine.Torrents[0].Files[i].Priority, restoredEngine.Torrents[0].Files[i].Priority);
            }
        }
Exemple #2
0
        public async Task UsePartialFiles_InitiallyOn_ToggleOff()
        {
            var pieceLength = Constants.BlockSize * 4;
            var engine      = new ClientEngine(EngineSettingsBuilder.CreateForTests(usePartialFiles: true));
            var torrent     = TestRig.CreateMultiFileTorrent(TorrentFile.Create(pieceLength, Constants.BlockSize, Constants.BlockSize * 2, Constants.BlockSize * 3), pieceLength, out BEncoding.BEncodedDictionary _);

            var manager = await engine.AddAsync(torrent, "");

            Assert.AreNotEqual(manager.Files[0].DownloadCompleteFullPath, manager.Files[0].DownloadIncompleteFullPath);

            var settings = new EngineSettingsBuilder(engine.Settings)
            {
                UsePartialFiles = false
            }.ToSettings();
            await engine.UpdateSettingsAsync(settings);

            Assert.AreEqual(manager.Files[0].DownloadCompleteFullPath, manager.Files[0].DownloadIncompleteFullPath);
        }
Exemple #3
0
        public async Task SaveRestoreState_OneInMemoryTorrent(bool addStreaming)
        {
            var pieceLength = Constants.BlockSize * 4;

            using var tmpDir = TempDir.Create();

            var torrent = TestRig.CreateMultiFileTorrent(TorrentFile.Create(pieceLength, Constants.BlockSize, Constants.BlockSize * 2, Constants.BlockSize * 3), pieceLength, out BEncoding.BEncodedDictionary metadata);

            var            engine = new ClientEngine(EngineSettingsBuilder.CreateForTests(cacheDirectory: tmpDir.Path));
            TorrentManager torrentManager;

            if (addStreaming)
            {
                torrentManager = await engine.AddStreamingAsync(torrent, "mySaveDirectory", new TorrentSettingsBuilder { CreateContainingDirectory = true }.ToSettings());
            }
            else
            {
                torrentManager = await engine.AddAsync(torrent, "mySaveDirectory", new TorrentSettingsBuilder { CreateContainingDirectory = true }.ToSettings());
            }

            await torrentManager.SetFilePriorityAsync(torrentManager.Files[0], Priority.High);

            await torrentManager.MoveFileAsync(torrentManager.Files[1], Path.GetFullPath("some_fake_path.txt"));

            var restoredEngine = await ClientEngine.RestoreStateAsync(await engine.SaveStateAsync());

            Assert.AreEqual(engine.Settings, restoredEngine.Settings);
            Assert.AreEqual(engine.Torrents[0].Torrent.Name, restoredEngine.Torrents[0].Torrent.Name);
            Assert.AreEqual(engine.Torrents[0].SavePath, restoredEngine.Torrents[0].SavePath);
            Assert.AreEqual(engine.Torrents[0].Settings, restoredEngine.Torrents[0].Settings);
            Assert.AreEqual(engine.Torrents[0].InfoHash, restoredEngine.Torrents[0].InfoHash);
            Assert.AreEqual(engine.Torrents[0].MagnetLink.ToV1String(), restoredEngine.Torrents[0].MagnetLink.ToV1String());

            Assert.AreEqual(engine.Torrents[0].Files.Count, restoredEngine.Torrents[0].Files.Count);
            for (int i = 0; i < engine.Torrents.Count; i++)
            {
                Assert.AreEqual(engine.Torrents[0].Files[i].FullPath, restoredEngine.Torrents[0].Files[i].FullPath);
                Assert.AreEqual(engine.Torrents[0].Files[i].Priority, restoredEngine.Torrents[0].Files[i].Priority);
            }
        }