Exemple #1
0
 private void Clear()
 {
     _schedule.Dispose();
     _queue.Clear();
     foreach (var id in _useds)
     {
         NativeInterface.DestroyTorrent(id);
     }
     _useds.Clear();
 }
Exemple #2
0
        public static void DestoryDownload(long id, EpisodeInfo header)
        {
            // 먼저 큐에 있는지 체크
            var found = Instance._queue.FirstOrDefault(item => item._header == header);

            if (found._header == header)
            {
                Instance._queue.Remove(found);
            }
            else
            {
                NativeInterface.DestroyTorrent(id);
            }
        }
Exemple #3
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);
                }
            }
        }