This repository has been archived by the owner on Jul 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.xaml.cs
195 lines (167 loc) · 6.48 KB
/
Game.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
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
using System;
using System.Net;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Windows.Media.Animation;
namespace Index
{
public partial class Game : System.Windows.Controls.Page
{
public int id;
public Game(Int16 gameID)
{
InitializeComponent();
GameData game = Data.games[gameID];
if (game == null)
{
MessageBox.Show($"Game not found {gameID}");
return;
}
id = gameID;
Dispatcher.Invoke(async () =>
{
GameName.Content = game.Metadata.Name;
GameDesc.Text = game.Metadata.Description;
GameVersion.Content = $"Build {game.Download.LatestVersion}";
if (!Properties.Settings.Default.Installed.Contains(id))
{
uninstallButton.Visibility = Visibility.Hidden;
verifyButton.Visibility = Visibility.Hidden;
}
try
{
var memStream = new MemoryStream();
using (var client = new HttpClient())
{
var response = await client.GetAsync(game.Images.Banners[0]);
if (response is { StatusCode: HttpStatusCode.OK })
{
using var stream = await response.Content.ReadAsStreamAsync();
await stream.CopyToAsync(memStream);
memStream.Position = 0;
}
}
MemoryStream ms = new MemoryStream();
(new Bitmap(memStream)).Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
BitmapImage image = new BitmapImage();
image.BeginInit();
ms.Seek(0, SeekOrigin.Begin);
image.StreamSource = ms;
image.EndInit();
gameImage1.Source = image;
DoubleAnimation da = new DoubleAnimation
{
From = 0.0,
To = 1.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
gameImage1.BeginAnimation(OpacityProperty, da);
}
catch
{
Methods.CheckConnection("Game background image");
}
});
}
private void Download(object sender, MouseButtonEventArgs e)
{
var window = Application.Current.MainWindow;
Methods.Download(id);
Data.visible = "Downloads";
var da = new DoubleAnimation
{
From = 1.0,
To = 0.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
var da1 = new DoubleAnimation
{
From = 0.0,
To = 1.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
da1.Completed += DownloadCompleted;
(window as Main).Game.BeginAnimation(OpacityProperty, da);
(window as Main).Home.BeginAnimation(OpacityProperty, da);
(window as Main).Downloads.Navigate(new Downloads());
(window as Main).Downloads.Visibility = Visibility.Visible;
(window as Main).Downloads.BeginAnimation(OpacityProperty, da1);
}
private void Verify(object sender, MouseButtonEventArgs e)
{
var window = Application.Current.MainWindow;
Methods.Verify(id);
Data.visible = "Downloads";
var da = new DoubleAnimation
{
From = 1.0,
To = 0.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
var da1 = new DoubleAnimation
{
From = 0.0,
To = 1.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
da1.Completed += DownloadCompleted;
(window as Main).Game.BeginAnimation(OpacityProperty, da);
(window as Main).Home.BeginAnimation(OpacityProperty, da);
(window as Main).Downloads.Navigate(new Downloads());
(window as Main).Downloads.Visibility = Visibility.Visible;
(window as Main).Downloads.BeginAnimation(OpacityProperty, da1);
}
private void Uninstall(object sender, MouseButtonEventArgs e)
{
var window = Application.Current.MainWindow;
Methods.Uninstall(id);
Data.visible = "Downloads";
Downloads d = new Downloads();
var da = new DoubleAnimation
{
From = 1.0,
To = 0.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
var da1 = new DoubleAnimation
{
From = 0.0,
To = 1.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
da1.Completed += DownloadCompleted;
(window as Main).Game.BeginAnimation(OpacityProperty, da);
(window as Main).Home.BeginAnimation(OpacityProperty, da);
(window as Main).Downloads.Navigate(new Downloads());
(window as Main).Downloads.Visibility = Visibility.Visible;
(window as Main).Downloads.BeginAnimation(OpacityProperty, da1);
}
private void DownloadCompleted(object sender, EventArgs e)
{
var window = Application.Current.MainWindow;
(window as Main).Game.Visibility = Visibility.Hidden;
}
private void goBackClick(object sender, MouseButtonEventArgs e)
{
var window = Application.Current.MainWindow;
var da = new DoubleAnimation
{
From = 1.0,
To = 0.0,
Duration = new Duration(TimeSpan.FromSeconds(.25))
};
da.Completed += Completed;
(window as Main).Game.BeginAnimation(OpacityProperty, da);
}
private void Completed(object sender, EventArgs e)
{
var window = Application.Current.MainWindow;
(window as Main).Game.Visibility = Visibility.Hidden;
}
}
}