-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTorrentDataHandler.cs
240 lines (216 loc) · 8.05 KB
/
TorrentDataHandler.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data;
using System.Xml;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;
using System.Data.SqlClient;
using System.Collections;
namespace CSL
{
public class TorrentDataHandler : BackgroundWorker
{
public static bool datasetbusy;
public static dataset data;
public static BindingSource binding;
public static DataTable table;
public static datasetTableAdapters.TorrentsTableTableAdapter musicadapter;
public datasetTableAdapters.TrackersTableTableAdapter trackeradapter = new datasetTableAdapters.TrackersTableTableAdapter();
public TorrentDataHandler() { }
public TorrentDataHandler(ref dataset d, ref datasetTableAdapters.TorrentsTableTableAdapter musikadapter)
{
data = d;
WorkerReportsProgress = true;
WorkerSupportsCancellation = true;
musicadapter = musikadapter;
d.Tables.CollectionChanging += new CollectionChangeEventHandler(Tables_CollectionChanging);
d.Tables.CollectionChanged += new CollectionChangeEventHandler(Tables_CollectionChanged);
trackeradapter.Fill(data.TrackersTable);
}
void Tables_CollectionChanged(object sender, CollectionChangeEventArgs e)
{
datasetbusy = false;
}
void Tables_CollectionChanging(object sender, CollectionChangeEventArgs e)
{
datasetbusy = true;
}
public void AddTorrent(Torrent torrent)
{
#region Information Contents
/* **Information[0-10] -- Music information**
*
* information[0] --> Artist
* information[1] --> Album
* information[2] --> AlbumType
* information[3] --> bitrate
* information[4] --> year
* information[5] --> physical format (CD,DVD,VINYL,WEB)
* information[6] --> bit format (MP3,FLAC)
*
* **Information[10-20] -- File Information**
*
* information[10] --> path
* information[11] --> file name
* information[12] --> birth
* information[13] --> destination path
* information[14] --> discard
* */
#endregion
dataset.TorrentsTableRow row = data.TorrentsTable.NewTorrentsTableRow();
string[] information = torrent.GetInformation();
row.BeginEdit();
row.File = information[11];
row.Artist = information[0];
row.Album = information[1];
row.Save_Structure = information[13];
row.Sent = false;
row.Release_Format = information[2];
row.Bit_Rate = information[3];
row.Year = information[4];
row.Physical_Format = information[5];
row.Bit_Format = information[6];
row.File_Path = information[10];
row.Site_Origin = information[12];
row.EndEdit();
while (datasetbusy) System.Threading.Thread.Sleep(100);//sleep while changes are occuring..
DataRow dr = data.TorrentsTable.Rows.Find(row.ID);
while (dr != null)
{
row.ID++;
dr = data.TorrentsTable.Rows.Find(row.ID);
}
data.TorrentsTable.AddTorrentsTableRow(row);
musicadapter.Update(row);
}
public void AddMovieTorrent(Movie m)
{
dataset.MoviesTableRow row = data.MoviesTable.NewMoviesTableRow();
string[] information = m.GetMovieInformation();
row.BeginEdit();
row.File = information[11];
row.Movie_Title = information[0];
row.Year = information[1];
row.Save_Structure = information[13];
row.Sent = false;
row.Source_Media = information[2];
row.Codec_Format = information[3];
row.File_Format = information[4];
row.File_Path = information[10];
row.Site_Origin = information[12];
row.EndEdit();
DataRow dr = data.TorrentsTable.Rows.Find(row.ID);
while (dr != null)
{
row.ID++;
dr = data.TorrentsTable.Rows.Find(row.ID);
}
data.MoviesTable.AddMoviesTableRow(row);
}
public void AddOtherTorrent(Torrent torrent)
{
string[] information = torrent.GetInformation();
dataset.OthersTableRow row = data.OthersTable.NewOthersTableRow();
row.File = information[11];
row.File_Path = information[10];
row.Save_Structure = information[13];
row.Site_Origin = information[12];
row.Sent = false;
data.OthersTable.AddOthersTableRow(row);
}
public void AddTracker(string tracker, string name)
{
dataset.TrackersTableRow row = data.TrackersTable.NewTrackersTableRow();
row.BeginEdit();
row.Tracker = tracker;
row.Activated = true;
row.Name = name;
row.EndEdit();
/* DataRow dr = data.TrackersTable.Rows.Find(row.id);
while (dr != null)
{
row.id++;
dr = data.TrackersTable.Rows.Find(row.id);
}*/
data.TrackersTable.AddTrackersTableRow(row);
trackeradapter.Update(row);
}
static public DataRowCollection GetTrackers()
{
try { return data.TrackersTable.Rows; }
catch { return null; }
}
static public string CheckTracker(string tracker)
{
foreach (dataset.TrackersTableRow r in data.TrackersTable.Rows)
{
if (r.Tracker.Equals(tracker))
{
if (r.Activated)
return "true";
else
return "false";
}
}
return "na";
}
public void UpdateTracker(int id, bool activate)
{
dataset.TrackersTableRow r = data.TrackersTable.FindByid(id);
r.BeginEdit();
r.Activated = activate;
r.EndEdit();
trackeradapter.Update(r);
}
static public void RemoveTorrent(string datatable, int index)
{
switch (datatable)
{
case "music":
try
{
(data.TorrentsTable.Rows.Find(index)).Delete();
}
catch (Exception e) { DirectoryHandler.LogError(e.Message + "\n" + e.StackTrace); }
break;
case "movies":
try
{
(data.MoviesTable.Rows.Find(index)).Delete();
}
catch (Exception e) { DirectoryHandler.LogError(e.Message + "\n" + e.StackTrace); }
break;
case "others":
try
{
(data.OthersTable.Rows.Find(index)).Delete();
}
catch (Exception e) { DirectoryHandler.LogError(e.Message + "\n" + e.StackTrace); }
break;
}
}
static public void RemoveAll(string datatable)
{
//Can't get table.Clear() to work..
switch (datatable)
{
case "music":
foreach (DataRow dr in data.TorrentsTable.Rows)
dr.Delete();
break;
case "movies":
foreach (DataRow dr in data.MoviesTable.Rows)
dr.Delete();
break;
case "others":
foreach (DataRow dr in data.OthersTable.Rows)
dr.Delete();
break;
}
}
}
}