-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHomePage.xaml.cs
104 lines (86 loc) · 1.92 KB
/
HomePage.xaml.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace _8Banner
{
public partial class HomePage : Page
{
internal static HomePage page;
string boardAddress;
public static string BoardName;
GetImageWorker giw;
public HomePage()
{
InitializeComponent();
page = this;
}
private void boardBox_Enter(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SetupWindow();
}
}
private void button_Click(object sender, RoutedEventArgs e)
{
SetupWindow();
}
private void SetupWindow()
{
boardAddress = @"https://banners.8ch.net/random/" + boardBox.Text;
if (BoardExists(boardBox.Text))
{
MainWindow.main.Status = "Preparing...";
MainWindow.main.frame.Navigate(new BannerPage());
MainWindow.main.btnCancel.Visibility = Visibility.Visible;
giw = new GetImageWorker();
giw.Start();
}
else
{
MessageBox.Show("Please enter a valid board");
}
}
private bool BoardExists(string newBoardName)
{
MainWindow.main.Status = "Checking if board exists...";
newBoardName.Replace("/", "");
BoardName = newBoardName.ToLower();
try
{
if (newBoardName == "")
throw new Exception();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://8ch.net/"
+ BoardName
+ @"/index.html");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
}
catch
{
return false;
}
finally
{
MainWindow.main.Status = "Done!";
}
return true;
}
internal void CancelTask()
{
giw.Cancel();
}
}
}