-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddTorrentParams.cs
203 lines (170 loc) · 6.39 KB
/
AddTorrentParams.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
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Tsunami.Core
{
using AddTorrentParamsHandle = HandleRef;
using TorrentInfoHandle = HandleRef;
public class AddTorrentParams : IDisposable
{
#region PInvoke
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr AddTorrentParams_Create();
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Destroy(AddTorrentParamsHandle h);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Name_Set(AddTorrentParamsHandle handle, string name);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Name_Get(AddTorrentParamsHandle handle, StringBuilder str, int size);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_SavePath_Set(AddTorrentParamsHandle handle, string name);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_SavePath_Get(AddTorrentParamsHandle handle, StringBuilder str, int size);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr AddTorrentParams_TorrentInfo_Get(AddTorrentParamsHandle handle);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_TorrentInfo_Set(AddTorrentParamsHandle handle, TorrentInfoHandle ti);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Flags_Set(AddTorrentParamsHandle handle, uint flags);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern uint AddTorrentParams_Flags_Get(AddTorrentParamsHandle handle);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Url_Set(AddTorrentParamsHandle handle, string name);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Url_Get(AddTorrentParamsHandle handle, StringBuilder str, int size);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern uint AddTorrentParams_Trackers_Size_Get(AddTorrentParamsHandle handle);
[DllImport("TsunamiBridge", CallingConvention = CallingConvention.StdCall)]
public static extern void AddTorrentParams_Trackers_Get(AddTorrentParamsHandle handle, [In][Out][MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)]string[] trk, uint size);
#endregion PInvoke
AddTorrentParamsHandle handle;
private StringBuilder sb = new StringBuilder(256);
private ATPFlags flags;
public ATPFlags Flags
{
get
{
flags = (ATPFlags)AddTorrentParams_Flags_Get(handle);
return flags;
}
set
{
flags = value;
AddTorrentParams_Flags_Set(handle, (uint)value);
}
}
public TorrentInfo ti
{
get
{
ti.Handle = new HandleRef(this,AddTorrentParams_TorrentInfo_Get(handle));
return ti;
}
set
{
AddTorrentParams_TorrentInfo_Set(handle, value.Handle);
}
}
private string name;
public string Name
{
get
{
if (String.IsNullOrEmpty(name))
{
AddTorrentParams_Name_Get(handle, sb, sb.Capacity);
name = sb.ToString();
}
return name;
}
set
{
name = value;
AddTorrentParams_Name_Set(handle, value);
}
}
private string url;
public string Url
{
get
{
if (String.IsNullOrEmpty(url))
{
AddTorrentParams_Url_Get(handle, sb, sb.Capacity);
url = sb.ToString();
}
return url;
}
set
{
url = value;
AddTorrentParams_Url_Set(handle, value);
}
}
private string[] trackers;
public string[] Trackers
{
get
{
if (trackers == null)
{
uint size = AddTorrentParams_Trackers_Size_Get(handle);
if (size != 0)
{
trackers = new string[size];
AddTorrentParams_Trackers_Get(handle, trackers, size);
}
}
return trackers;
}
set
{
trackers = value;
}
}
private string save_path;
public string SavePath
{
get
{
if (String.IsNullOrEmpty(save_path))
{
AddTorrentParams_SavePath_Get(handle, sb, sb.Capacity);
save_path = sb.ToString();
}
return save_path;
}
set
{
save_path = value;
AddTorrentParams_SavePath_Set(handle, value);
}
}
public AddTorrentParams()
{
IntPtr h = AddTorrentParams_Create();
handle = new HandleRef(this, h);
}
public AddTorrentParamsHandle Handle
{
get
{
return handle;
}
}
public void Dispose()
{
CleanUp();
GC.SuppressFinalize(this);
}
private void CleanUp()
{
AddTorrentParams_Destroy(handle);
handle = new HandleRef(this, IntPtr.Zero);
}
~AddTorrentParams()
{
CleanUp();
}
}
}