-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
410 lines (374 loc) · 14.8 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
using QRCoder;
using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Newtonsoft.Json;
using SIAQr.Models;
using Microsoft.Win32;
using System.Diagnostics;
using System.Drawing;
namespace SIAQr
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
FunctionLoadCombos();
FunctionCollapseAll();
}
private void FunctionLoadCombos()
{
cmbWifiSecurity.Items.Add("NONE");
cmbWifiSecurity.Items.Add("WPA/WPA2-PSK");
//cmbWifiSecurity.Items.Add("WPA/WPA2-EAP");
cmbWifiSecurity.Items.Add("WEP");
}
private void FunctionMessageBox(string caption, string messageBoxText, string type)
{
// string messageBoxText = "Export to CSV file failed";
// string caption = "Error: Export failed";
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxImage icon = MessageBoxImage.Information;
if (type == "Error")
{
icon = MessageBoxImage.Error;
}
if (type == "Warning")
{
icon = MessageBoxImage.Warning;
}
MessageBoxResult result;
result = MessageBox.Show(messageBoxText, caption, button, icon, MessageBoxResult.OK);
}
private void FunctionDev(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo
{
FileName = "https://github.com/sibranda",
UseShellExecute = true
});
}
private string qrCodeJSONData;
private bool configWifi;
private bool wifiHidden;
private bool wifiProxy;
private bool allSysApps;
private bool customLogo;
private string customLogoSrc;
private string FunctionGenerateJSONData()
{
PROVISIONINGADMINEXTRASBUNDLE aQRChild = new PROVISIONINGADMINEXTRASBUNDLE();
AndroidQR aQR = new AndroidQR();
aQR.PROVISIONING_DEVICE_ADMIN_COMPONENT_NAME = "com.google.android.apps.work.clouddpc/.receivers.CloudDeviceAdminReceiver";
aQR.PROVISIONING_DEVICE_ADMIN_SIGNATURE_CHECKSUM = "I5YvS0O5hXY46mb01BlRjq4oJJGs2kuUcHvVkAPEXlg";
aQR.PROVISIONING_DEVICE_ADMIN_PACKAGE_DOWNLOAD_LOCATION = "https://play.google.com/managed/downloadManagingApp?identifier=setup";
aQRChild.EXTRA_ENROLLMENT_TOKEN = txtBoxIntuneToken.Text;
aQR.PROVISIONING_ADMIN_EXTRAS_BUNDLE = aQRChild;
if (configWifi)
{
aQR.PROVISIONING_WIFI_SSID = txtBoxWifiSSID.Text;
aQR.PROVISIONING_WIFI_PASSWORD = psdWifiPassword.Password;
switch (cmbWifiSecurity.Text)
{
case "WPA/WPA2-PSK":
aQR.PROVISIONING_WIFI_SECURITY_TYPE = "WPA";
break;
case "WPA/WPA2-EAP":
aQR.PROVISIONING_WIFI_SECURITY_TYPE = "EAP";
break;
default:
aQR.PROVISIONING_WIFI_SECURITY_TYPE = cmbWifiSecurity.Text;
break;
}
aQR.PROVISIONING_WIFI_HIDDEN = wifiHidden;
if (wifiProxy)
{
aQR.PROVISIONING_WIFI_PROXY_HOST = txtBoxProxyHost.Text;
aQR.PROVISIONING_WIFI_PROXY_PORT = txtBoxProxyPort.Text;
aQR.PROVISIONING_WIFI_PROXY_BYPASS = txtBoxProxyBypass.Text;
}
}
if (allSysApps)
{
aQR.PROVISIONING_LEAVE_ALL_SYSTEM_APPS_ENABLED = allSysApps;
}
qrCodeJSONData = JsonConvert.SerializeObject(aQR);
return qrCodeJSONData;
}
private void FunctionCheckData(object sender, EventArgs e)
{
imgQRCode.Source = null;
bool allok = true;
bool save = false;
var btnClicked = ((Button)sender).Name;
if (btnClicked == "SaveFile")
{
save = true;
}
if (txtBoxIntuneToken.Text == "")
{
allok = false;
FunctionMessageBox("Information: Missing Intune Code", "You must to type an Intune Token code", "Info");
}
else if (configWifi)
{
if(txtBoxWifiSSID.Text == "")
{
allok = false;
FunctionMessageBox("Information: Missing SSID", "You must to type a WiFi SSID Name", "Info");
}
else if(cmbWifiSecurity.SelectedValue == null)
{
allok = false;
FunctionMessageBox("Information: WiFi Security", "You must select WiFi Security", "Info");
}
}
if (allok)
{
FunctionGenerateQRCode(save);
}
}
private void FunctionGenerateQRCode(bool save)
{
//BitmapImage qrIco = new BitmapImage(new Uri ("C:\\Scripts\\VS\\WPF\\SIAQr\\SIAQr.ico"));
//https://github.com/codebude/QRCoder/wiki/Advanced-usage---QR-Code-renderers#21-qrcode-renderer-in-detail
//https://github.com/codebude/QRCoder
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(FunctionGenerateJSONData(), QRCodeGenerator.ECCLevel.L); //ECCLevel.L its the same Intune uses
BitmapImage bitmapimage = new BitmapImage();
if (customLogo)
{
string srcImg;
if (customLogoSrc != null)
{
srcImg = customLogoSrc;
}
else
{
srcImg = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "SIAQr.png");
}
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, (Bitmap)Bitmap.FromFile(srcImg));
using (MemoryStream memory = new MemoryStream())
{
qrCodeImage.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
memory.Position = 0;
bitmapimage.BeginInit();
bitmapimage.StreamSource = memory;
bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
bitmapimage.EndInit();
}
}
else
{
BitmapByteQRCode qrCode = new BitmapByteQRCode(qrCodeData);
byte[] qrCodeAsBitmapByteArr = qrCode.GetGraphic(20);
bitmapimage.BeginInit();
bitmapimage.StreamSource = new MemoryStream(qrCodeAsBitmapByteArr);
bitmapimage.EndInit();
}
imgQRCode.Source = bitmapimage;
if (save)
{
FunctionSavetoFile(bitmapimage);
}
}
private void FunctionOpenCustomLogo(object sender, EventArgs e)
{
imgQRCode.Source = null;
try
{
OpenFileDialog customLogoFile = new OpenFileDialog();
customLogoFile.Title = "Save QR Code to File";
customLogoFile.DefaultExt = "png";
customLogoFile.Filter = "PNG files (*.png)|*.png|All files (*.*)|*.*";
customLogoFile.FilterIndex = 1;
customLogoFile.RestoreDirectory = true;
customLogoFile.ShowDialog();
if (customLogoFile.FileName != "")
{
customLogoSrc = customLogoFile.FileName;
}
}
catch (Exception)
{
FunctionMessageBox("Error: Opening File", "Error opening custom logo file", "Error");
}
}
/* private void FunctionSavetoJSON(object sender, EventArgs e)
{
string JSONresult = FunctionGenerateJSONData();
string path = @"C:\Temp\AndroidQR.json";
if (File.Exists(path))
{
File.Delete(path);
using (var tw = new StreamWriter(path, true))
{
tw.WriteLine(JSONresult.ToString());
tw.Close();
}
}
else if (!File.Exists(path))
{
using (var tw = new StreamWriter(path, true))
{
tw.WriteLine(JSONresult.ToString());
tw.Close();
}
}
}*/
private void FunctionSavetoFile(BitmapImage image)
{
try
{
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.Title = "Save QR Code to File";
saveFile.DefaultExt = "png";
saveFile.Filter = "PNG files (*.png)|*.png|All files (*.*)|*.*";
saveFile.FilterIndex = 1;
saveFile.RestoreDirectory = true;
saveFile.ShowDialog();
var filePath = saveFile.FileName;
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
using (var fileStream = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
encoder.Save(fileStream);
}
}
catch (Exception)
{
FunctionMessageBox("Error: Saving File", "QRCode PNG File was not Saved", "Error");
}
}
private void FunctionCollapseAll()
{
lblWifiSSID.Visibility = Visibility.Collapsed;
lblWifiSecurity.Visibility = Visibility.Collapsed;
txtBoxWifiSSID.Visibility = Visibility.Collapsed;
chkWifiHidden.Visibility = Visibility.Collapsed;
chkWifiHidden.Visibility = Visibility.Collapsed;
cmbWifiSecurity.Visibility = Visibility.Collapsed;
lblWifiPassword.Visibility = Visibility.Collapsed;
psdWifiPassword.Visibility = Visibility.Collapsed;
chkConfigProxy.Visibility = Visibility.Collapsed;
lblProxyHost.Visibility = Visibility.Collapsed;
txtBoxProxyHost.Visibility = Visibility.Collapsed;
lblProxyPort.Visibility = Visibility.Collapsed;
txtBoxProxyPort.Visibility = Visibility.Collapsed;
lblProxyBypass.Visibility = Visibility.Collapsed;
txtBoxProxyBypass.Visibility = Visibility.Collapsed;
}
private void FunctionConfigureWifi(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
if (chkConfigWifi.IsChecked == true)
{
lblWifiSSID.Visibility = Visibility.Visible;
lblWifiSecurity.Visibility = Visibility.Visible;
txtBoxWifiSSID.Visibility = Visibility.Visible;
chkWifiHidden.Visibility = Visibility.Visible;
chkWifiHidden.Visibility = Visibility.Visible;
cmbWifiSecurity.Visibility = Visibility.Visible;
lblWifiPassword.Visibility = Visibility.Visible;
psdWifiPassword.Visibility = Visibility.Visible;
chkConfigProxy.Visibility = Visibility.Visible;
configWifi = true;
}
else
{
FunctionCollapseAll();
configWifi = false;
chkWifiHidden.IsChecked = false;
wifiHidden = false;
cmbWifiSecurity.SelectedItem = null;
psdWifiPassword.Password = null;
chkConfigProxy.IsChecked = false;
wifiProxy = false;
txtBoxProxyHost.Text = null;
txtBoxProxyPort.Text = null;
txtBoxProxyBypass.Text = null;
}
}
private void FunctionWifiHidden(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
if (chkWifiHidden.IsChecked == true)
{
wifiHidden = true;
}
else
{
wifiHidden = false;
}
}
private void FunctionConfigProxy(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
if (chkConfigProxy.IsChecked == true)
{
wifiProxy = true;
lblProxyHost.Visibility = Visibility.Visible;
txtBoxProxyHost.Visibility = Visibility.Visible;
lblProxyPort.Visibility = Visibility.Visible;
txtBoxProxyPort.Visibility = Visibility.Visible;
lblProxyBypass.Visibility = Visibility.Visible;
txtBoxProxyBypass.Visibility = Visibility.Visible;
}
else
{
wifiProxy = false;
lblProxyHost.Visibility = Visibility.Collapsed;
txtBoxProxyHost.Visibility = Visibility.Collapsed;
lblProxyPort.Visibility = Visibility.Collapsed;
txtBoxProxyPort.Visibility = Visibility.Collapsed;
lblProxyBypass.Visibility = Visibility.Collapsed;
txtBoxProxyBypass.Visibility = Visibility.Collapsed;
txtBoxProxyHost.Text = null;
txtBoxProxyPort.Text = null;
txtBoxProxyBypass.Text = null;
}
}
private void FunctionEnableSysApps(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
if (chkAllSystemApps.IsChecked == true)
{
allSysApps = true;
}
else
{
allSysApps = false;
}
}
private void FunctionEnableCustomLogo(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
if (chkCustomLogo.IsChecked == true)
{
btnCustomLogo.Visibility = Visibility.Visible;
customLogo = true;
}
else
{
btnCustomLogo.Visibility = Visibility.Collapsed;
customLogo = false;
customLogoSrc = null;
}
}
private void FunctionNullQr (object sender, TextChangedEventArgs e)
{
imgQRCode.Source = null;
}
private void FunctionNullQrPsd(object sender, RoutedEventArgs e)
{
imgQRCode.Source = null;
}
}
}