-
Notifications
You must be signed in to change notification settings - Fork 1
/
FormWebBrowser.cs
124 lines (104 loc) · 4.36 KB
/
FormWebBrowser.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
using System;
using System.Windows.Forms;
namespace Leaf.Forms
{
public partial class FormWebBrowser : Form
{
// TODO:
//public CookieContainer Cookies { get; private set; }
//public SteamSession Session { get; private set; }
public FormWebBrowser()
{
InitializeComponent();
wb.Modernize();
}
/// <summary>
/// Clean up browser allocated memory and close the form.
/// </summary>
private void CleanAndClose()
{
wb.Visible = false;
wb.Dispose();
wb = null;
// Collect 2 generations of trash
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Close();
}
private void FormLogin_Load(object sender, EventArgs e)
{
wb.Navigated += Wb_Navigated;
wb.Navigate("https://partner.steamgames.com/apps/");
}
private void Wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
// Inject css
//IHTMLDocument2 doc = (wb.Document.DomDocument) as IHTMLDocument2;
//IHTMLStyleSheet ss = doc.createStyleSheet("", 0);
//ss.cssText = @".navbar,.navbar-header,.form-group,.header-content,footer { display: none !important; } header.full-header,.reg { background-image: none !important; background-color: white !important; } .form-group:nth-child(3) {display: block !important}";
if (tmrWatcher.Enabled)
return;
tmrWatcher_Tick(null, null);
tmrWatcher.Start();
}
//private const int InternetCookieHttponly = 0x2000;
/*
private static CookieContainer GetCookieContainer(string baseUrl)
{
var uri = new Uri(baseUrl);
// Determine the size of the cookie
int datasize = 8192 * 16;
var cookieData = new StringBuilder(datasize);
if (!NativeMethods.InternetGetCookieEx(baseUrl, null, cookieData, ref datasize, InternetCookieHttponly, IntPtr.Zero))
{
if (datasize < 0)
return null;
// Allocate stringbuilder large enough to hold the cookie
cookieData = new StringBuilder(datasize);
if (!NativeMethods.InternetGetCookieEx(baseUrl, null, cookieData, ref datasize, InternetCookieHttponly,
IntPtr.Zero))
return null;
}
if (cookieData.Length <= 0)
return null;
var cookies = new CookieContainer();
cookies.SetCookies(uri, cookieData.ToString().Replace(';', ','));
return cookies;
}
*/
private void ReportError(string message, bool panic = true)
{
MessageBox.Show(message, "Ошибка", MessageBoxButtons.OK,
panic ? MessageBoxIcon.Error : MessageBoxIcon.Exclamation);
if (panic)
CleanAndClose();
}
private void tmrWatcher_Tick(object sender, EventArgs e)
{
// TODO: universal solution
if (wb == null || wb.Document == null || wb.Document.Body == null ||
!wb.Document.Body.InnerHtml.Contains("https://partner.steamgames.com/login/logout"))
{
return;
}
tmrWatcher.Stop();
//var cookieContainer = GetCookieContainer("https://partner.steamgames.com/");
var owner = wb.Document.GetElementById("landingHeader")?.GetElementsByTagName("h1");
//string userName = null;
if (owner == null || owner.Count == 0 || owner[0] == null)
{
ReportError("Не могу определить имя аккаунта, ничего страшного." +
" Просто не будет отображаться имя аккаунта в программе",
false);
}
//else
// userName = owner[0].InnerText;
//Session = new SteamSession(cookieContainer, userName);
// Session.Save();
// BinarySerializer.Serialize(Session, "session.dat");
//Session.Serialize();
CleanAndClose();
}
}
}