/// <summary>
        /// Starts a hashcheck. If forceFullScan is false, the library will attempt to load fastresume data
        /// before performing a full scan, otherwise fast resume data will be ignored and a full scan will be started
        /// </summary>
        /// <param name="forceFullScan">True if a full hash check should be performed ignoring fast resume data</param>
        public void HashCheck(bool autoStart)
        {
            ClientEngine.MainLoop.QueueWait((MainLoopTask) delegate {
                if (!Mode.CanHashCheck)
                {
                    throw new TorrentException(string.Format("A hashcheck can only be performed when the manager is stopped. State is: {0}", State));
                }

                CheckRegisteredAndDisposed();
                this.startTime = DateTime.Now;
                Mode           = new HashingMode(this, autoStart);
                Engine.Start();
            });
        }
        /// <summary>
        /// Starts a hashcheck. If forceFullScan is false, the library will attempt to load fastresume data
        /// before performing a full scan, otherwise fast resume data will be ignored and a full scan will be started
        /// </summary>
        /// <param name="forceFullScan">True if a full hash check should be performed ignoring fast resume data</param>
        public async Task HashCheckAsync(bool autoStart)
        {
            await ClientEngine.MainLoop;

            if (!Mode.CanHashCheck)
            {
                throw new TorrentException(string.Format("A hashcheck can only be performed when the manager is stopped. State is: {0}", State));
            }

            CheckRegisteredAndDisposed();
            this.StartTime = DateTime.Now;
            Mode           = new HashingMode(this, autoStart);
            Engine.Start();
        }
Exemple #3
0
        internal async Task HashCheckAsync(bool autoStart, bool setStoppedModeWhenDone)
        {
            if (!HasMetadata)
            {
                throw new TorrentException("A hashcheck cannot be performed if the TorrentManager was created with a Magnet link and the metadata has not been downloaded.");
            }

            await ClientEngine.MainLoop;

            if (!Mode.CanHashCheck)
            {
                throw new TorrentException(string.Format("A hashcheck can only be performed when the manager is stopped. State is: {0}", State));
            }

            CheckRegisteredAndDisposed();
            StartTime = DateTime.Now;

            // An IgnoringPicker is created to ensure pieces which *have not* been hash checked
            // are not requested from other peers. The intention is that files marked as DoNotDownload
            // will not be hashed, or downloaded.
            UnhashedPieces.SetAll(true);

            var hashingMode = new HashingMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);

            Mode = hashingMode;
            try {
                await hashingMode.WaitForHashingToComplete();

                HashChecked = true;
                if (autoStart)
                {
                    await StartAsync();
                }
                else if (setStoppedModeWhenDone)
                {
                    Mode = new StoppedMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
                }
            } catch {
                HashChecked = false;
                // If the hash check was cancelled (by virtue of a new Mode being set on the TorrentManager) then
                // we don't want to overwrite the Mode which was set.
                if (Mode == hashingMode)
                {
                    Mode = new StoppedMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
                }
            }
        }
Exemple #4
0
        internal async Task HashCheckAsync(bool autoStart, bool setStoppedModeWhenDone)
        {
            if (!HasMetadata)
            {
                throw new TorrentException("A hashcheck cannot be performed if the TorrentManager was created with a Magnet link and the metadata has not been downloaded.");
            }

            await ClientEngine.MainLoop;

            if (!Mode.CanHashCheck)
            {
                throw new TorrentException(string.Format("A hashcheck can only be performed when the manager is stopped. State is: {0}", State));
            }

            CheckRegisteredAndDisposed();
            StartTime = DateTime.Now;

            // An IgnoringPicker is created to ensure pieces which *have not* been hash checked
            // are not requested from other peers. The intention is that files marked as DoNotDownload
            // will not be hashed, or downloaded.
            UnhashedPieces.SetAll(true);

            var hashingMode = new HashingMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);

            Mode = hashingMode;

            try {
                await hashingMode.WaitForHashingToComplete();

                hashingMode.Token.ThrowIfCancellationRequested();
            } catch (OperationCanceledException) {
                return;
            } catch (Exception ex) {
                TrySetError(Reason.ReadFailure, ex);
                return;
            }

            HashChecked = true;
            if (autoStart)
            {
                await StartAsync();
            }
            else if (setStoppedModeWhenDone)
            {
                Mode = new StoppedMode(this, Engine.DiskManager, Engine.ConnectionManager, Engine.Settings);
            }
        }
        /// <summary>
        /// Starts a hashcheck. If forceFullScan is false, the library will attempt to load fastresume data
        /// before performing a full scan, otherwise fast resume data will be ignored and a full scan will be started
        /// </summary>
        /// <param name="forceFullScan">True if a full hash check should be performed ignoring fast resume data</param>
        public async Task HashCheckAsync(bool autoStart)
        {
            if (!HasMetadata)
            {
                throw new TorrentException("A hashcheck cannot be performed if the TorrentManager was created with a Magnet link and the metadata has not been downloaded.");
            }

            await ClientEngine.MainLoop;

            if (!Mode.CanHashCheck)
            {
                throw new TorrentException(string.Format("A hashcheck can only be performed when the manager is stopped. State is: {0}", State));
            }

            CheckRegisteredAndDisposed();
            StartTime = DateTime.Now;

            var hashingMode = new HashingMode(this);

            Mode = hashingMode;
            try {
                await hashingMode.WaitForHashingToComplete();

                HashChecked = true;
                if (autoStart)
                {
                    await StartAsync();
                }
                else
                {
                    Mode = new StoppedMode(this);
                }
            } catch {
                HashChecked = false;
                // If the hash check was cancelled (by virtue of a new Mode being set on the TorrentManager) then
                // we don't want to overwrite the Mode which was set.
                if (Mode == hashingMode)
                {
                    Mode = new StoppedMode(this);
                }
            }
        }