Пример #1
0
        private void Update()
        {
            if (_queue.Count > 0 &&
                _useds.Count < Preference.Instance.CurrentlyTorrentCount)
            {
                var info = _queue.First();
                _queue.Remove(info);

                var id = NativeInterface.CreateTorrent();

                // for child directory
                var savePath = Path.Combine(Preference.GetAbsoluteDownloadPath(), info._childPathName);
                if (Directory.Exists(savePath) == false)
                {
                    Directory.CreateDirectory(savePath);
                }

                var result = NativeInterface.StartDownload(id, info._header.Magnet, savePath, (stateInfo) =>
                {
                    info._updateEvent(stateInfo);

                    state_t state = (state_t)stateInfo.State;

                    if (state == state_t.finished ||
                        state == state_t.seeding)
                    {
                        info._finishEvent?.Invoke(id, stateInfo);
                        _useds.Remove(id);
                        NativeInterface.DestroyTorrent(id);
                    }
                });

                if (result)
                {
                    info._startEvent?.Invoke(id);
                    _useds.Add(id);
                }
                else
                {
                    // 뭔진 모르겠지만 다운로드를 시작하지 못했다.
                    // 토렌트 id는 자동 파괴됨
                    // ERROR
                    Console.WriteLine("[Error] Torrent download is failed\nFile:{0}, Episode:{1}", info._header.Name, info._header.Episode);
                }
            }
        }