-
Notifications
You must be signed in to change notification settings - Fork 0
/
TorrentHandler.cs
69 lines (59 loc) · 2.64 KB
/
TorrentHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
namespace Torrent
{
class TorrentHandler
{
public TorrentHandler()
{
}
string filePath = string.Concat($@"C:\Users\", Environment.UserName, @"\AppData\Local\Bitloader\active_torrents.tor"); //USE Environment.UserName for releases
public void WriteActiveTorrents(List<string> torrents)
{
string[] activeTorrents = new string[torrents.Count];
for (int i = 0; i < activeTorrents.Length; ++i)
{
activeTorrents[i] = torrents[i];
}
File.WriteAllLines(filePath, activeTorrents);
}
public void ReadActiveTorrents()
{
string[] torrentsToAdd = File.ReadAllLines(filePath);
int uploadSpeed = SettingsForm.defaultSettings.defaultMaxUploadSpeed;
int downloadSpeed = SettingsForm.defaultSettings.defaultMaxDownloadSpeed;
string savePath = SettingsForm.defaultSettings.defaultSavePath;
string torrentPath = string.Empty;
string magnetLink = string.Empty;
bool unlimitedDownloadSpeed = SettingsForm.defaultSettings.unlimitedDownloadSpeed;
bool unlimitedUpSpeed = SettingsForm.defaultSettings.unlimitedUploadSpeed;
for (int i = 0; i < torrentsToAdd.Length; ++i)
{
if (torrentsToAdd[i].StartsWith("magnet:"))
magnetLink = torrentsToAdd[i];
else
torrentPath = torrentsToAdd[i];
TorrentDownloader downloader = new TorrentDownloader(uploadSpeed, downloadSpeed, savePath, torrentPath, magnetLink, unlimitedDownloadSpeed, unlimitedUpSpeed);
cMainForm.mainForm.downloadList.Add(downloader); //Add to the main list of downloading objects for indexing
downloader.torrentIndex = cMainForm.mainForm.torrentIndex;
if (!string.IsNullOrEmpty(torrentPath))
{
cMainForm.mainForm.activeTorrents.Add(downloader.torrentFilePath);
new Thread(downloader.AddTorrentFromFile).Start();
}
else if (!string.IsNullOrEmpty(magnetLink))
{
cMainForm.mainForm.activeTorrents.Add(downloader.magnetLink);
new Thread(downloader.AddTorrentFromMagnet).Start();
}
else
return;
if (File.Exists(filePath))
File.Delete(filePath);
cMainForm.mainForm.mainTimer.Start();
}
}
}
}