-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
328 lines (227 loc) · 10.2 KB
/
MainWindow.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
using System;
using System.Collections.Generic;
using System.Linq;
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;
using System.Windows.Forms;
using System.Diagnostics;
using System.Net;
using System.Net.Http;
using System.IO;
using System.IO.Compression;
using IWshRuntimeLibrary;
using System.Reflection;
using System.Drawing.Drawing2D;
using System.Security.AccessControl;
using System.Security.Principal;
namespace EyeTRackVR_Installer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary
///
public static class Extensions
{
public static async Task DownloadFile(this HttpClient client, string address, string fileName)
{
using (var response = await client.GetAsync(address))
using (var stream = await response.Content.ReadAsStreamAsync())
using (var file = System.IO.File.OpenWrite(fileName))
{
stream.CopyTo(file);
}
}
}
///
///
///
///
///
///
///
///
///
///
///
///
///
/// >
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string rootPath = @AppDomain.CurrentDomain.BaseDirectory;
string[] dirs = Directory.GetDirectories(rootPath, "*", SearchOption.TopDirectoryOnly);
//public static void ExtractToDirectory(string sourceArchiveFileName, string destinationDirectoryName);
}
public void ExtractZipFileToDirectory(string sourceZipFilePath, string destinationDirectoryName, bool overwrite)
{
using (var archive = ZipFile.Open(sourceZipFilePath, ZipArchiveMode.Read))
{
if (!overwrite)
{
archive.ExtractToDirectory(destinationDirectoryName);
return;
}
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName);
string destinationDirectoryFullPath = di.FullName;
foreach (ZipArchiveEntry file in archive.Entries)
{
string completeFileName = System.IO.Path.GetFullPath(System.IO.Path.Combine(destinationDirectoryFullPath, file.FullName));
if (!completeFileName.StartsWith(destinationDirectoryFullPath, StringComparison.OrdinalIgnoreCase))
{
throw new IOException("Trying to extract file outside of destination directory. See this link for more info: https://snyk.io/research/zip-slip-vulnerability");
}
if (file.Name == "")
{// Assuming Empty for Directory
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(completeFileName));
continue;
}
file.ExtractToFile(completeFileName, true);
}
}
}
private static void GrantAccess(string file)
{
bool exists = System.IO.Directory.Exists(file);
if (!exists)
{
DirectoryInfo di = System.IO.Directory.CreateDirectory(file);
}
DirectoryInfo dInfo = new DirectoryInfo(file);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
private void CloseButton_Click(object sender, RoutedEventArgs e) //when X is clicked, close
{
Close();
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e) //when - is clicked, minimize
{
this.WindowState = WindowState.Minimized;
}
public string folderdir;
public string inspath;
public bool? mkshortcut;
public bool? delinstaller;
public void ChangePath_Click(object sender, RoutedEventArgs e) //open file browser
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.RootFolder = Environment.SpecialFolder.Desktop;
fbd.Description = "Select Install folder";
fbd.ShowNewFolderButton = false;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
inspath = fbd.SelectedPath + "\\EyeTrackVRtemp.zip"; //set selected path to that path and append /eyetrackvr to it
folderdir = fbd.SelectedPath + "\\EyeTrackVR";
textBox1.Text = folderdir;
}
}
private void mkUnchecked(object sender, RoutedEventArgs e) // check if check is checked
{
mkshortcut = false;
}
private void mkCheck(object sender, RoutedEventArgs e)
{
mkshortcut = true;
}
private void delUnchecked(object sender, RoutedEventArgs e) // check if check is checked
{
delinstaller = false;
}
private void delCheck(object sender, RoutedEventArgs e)
{
delinstaller = true;
}
private void Docs_Click(object sender, RoutedEventArgs e) //docs link at top
{
Process DocsProcess = new Process();
DocsProcess.StartInfo.UseShellExecute = true;
DocsProcess.StartInfo.FileName = "https://redhawk989.github.io/EyeTrackVR/";
DocsProcess.Start();
}
private void Github_Click(object sender, RoutedEventArgs e) //github link at top
{
Process GithubProcess = new Process();
GithubProcess.StartInfo.UseShellExecute = true;
GithubProcess.StartInfo.FileName = "https://github.com/RedHawk989/EyeTrackVR";
GithubProcess.Start();
}
private void Discord_Click(object sender, RoutedEventArgs e) //discord link at top
{
Process DiscordProcess = new Process();
DiscordProcess.StartInfo.UseShellExecute = true;
DiscordProcess.StartInfo.FileName = "https://discord.gg/kkXYbVykZX";
DiscordProcess.Start();
}
public async void InstallButton_Click(object sender, RoutedEventArgs e)
{
//actually install stuff lmao
textBox2.Text = "";
InstallButton.Content = "Installing...";
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData("https://raw.githubusercontent.com/RedHawk989/EyeTrackVR-Installer/master/Version-Data/Latest_Version.txt"); //get download link from repo
string webData = System.Text.Encoding.UTF8.GetString(raw);
webData = webData.Replace("\n", "").Replace("\r", "");
System.Net.WebClient wc2 = new System.Net.WebClient();
byte[] raw2 = wc.DownloadData("https://raw.githubusercontent.com/RedHawk989/EyeTrackVR-Installer/master/Version-Data/Version_Num.txt"); //get latest version num
string webData2 = System.Text.Encoding.UTF8.GetString(raw2);
webData2 = webData2.Replace("\n", "").Replace("\r", "");
if (string.IsNullOrEmpty(folderdir)) //define default dirs
{
folderdir = "C:\\Program Files\\EyeTrackVR";
}
if (string.IsNullOrEmpty(inspath))
{
inspath = "C:\\Program Files\\EyeTrackVR\\EyeTrackVRtemp.zip"; //name of zip folder once downloaded
}
System.IO.Directory.CreateDirectory(folderdir); //create install dir
InstallButton.Content = "Downloading...";
using (var httpClient = new HttpClient()) // download zip
{
HttpClient httpClient1 = httpClient;
await httpClient1.DownloadFile(webData, inspath);
}
InstallButton.Content = "Extracting...";
await Task.Delay(500); //give OS time. fixes odd bug where System.IO.InvalidDataException: 'Central Directory corrupt.' would be called
// ZipFile.ExtractToDirectory(inspath, folderdir); //extract zip
ExtractZipFileToDirectory(inspath, folderdir, true);
GrantAccess(folderdir); //make perms on install folder user, this keeps the eyetracking app from trowing no permission errors.
InstallButton.Content = "Cleaning...";
System.IO.File.Delete(inspath); // delete zip
if (!mkshortcut.HasValue || mkshortcut is true) // if box is checked make a shortcut on desktop
{
InstallButton.Content = "Making Shortcut...";
string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string exepath = folderdir + "\\EyeTrackApp-" + webData2 + "-win-amd-64\\EyeTrackApp.exe";
string link = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
+ System.IO.Path.DirectorySeparatorChar + "EyeTrackVR" + ".lnk";
var shell = new WshShell();
var shortcut = shell.CreateShortcut(link) as IWshShortcut;
shortcut.TargetPath = exepath;
shortcut.WorkingDirectory = folderdir; //where output files will be made from the eyetrack app
shortcut.Save();
}
textBox2.Text = "Successfully Installed!";
InstallButton.Content = "Installed!";
}
private void Get_MouseDown(object sender, MouseButtonEventArgs e) //allow window to be moved on the top
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
}
}