-
Notifications
You must be signed in to change notification settings - Fork 0
/
WbClient.cs
85 lines (69 loc) · 2.33 KB
/
WbClient.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
using System.Collections.Generic;
using System.Net;
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Text;
namespace xk3yDVDMenu
{
internal class WbClient : WebClient
{
public WbClient()
{
}
public bool waiting;
byte[] data = null;
public Dictionary<string, object> Cache = new Dictionary<string, object>();
public string RedirectURL(ISO game,string baseURL)
{
if (game.RedirectURL == "")
{
Uri uri = new Uri(baseURL);
HttpWebRequest httpreqRequest = (HttpWebRequest)WebRequest.Create(uri);
httpreqRequest.Method = "GET";
httpreqRequest.AllowAutoRedirect = true;
game.RedirectURL = httpreqRequest.GetResponse().ResponseUri.AbsoluteUri;
;
}
return game.RedirectURL;
}
public byte[] DownloadData(string address, ProgressBar pb)
{
pb.Maximum = 100;
base.DownloadProgressChanged += (object s, DownloadProgressChangedEventArgs e) => pb.Value = e.ProgressPercentage;
base.DownloadDataCompleted += (object s, DownloadDataCompletedEventArgs e) =>
{
if (e.Error == null)
{
this.waiting = false;
this.data = e.Result;
}
};
base.DownloadDataAsync(new Uri(address));
while (waiting)
{
Application.DoEvents();
}
return data;
}
public void DownloadFile(string address, string filename, ProgressBar pb)
{
pb.Maximum = 100;
base.DownloadProgressChanged += (object s, DownloadProgressChangedEventArgs e) => pb.Value = e.ProgressPercentage;
base.DownloadFileCompleted += (object s, AsyncCompletedEventArgs e) => this.waiting = false;
base.DownloadFileAsync(new Uri(address), filename);
while (waiting)
{
Application.DoEvents();
}
}
new public string DownloadString(string address)
{
if (Cache.ContainsKey(address))
return Cache[address].ToString();
base.Encoding = Encoding.UTF8;
Cache.Add(address, base.DownloadString(address));
return Cache[address].ToString();
}
}
}