This repository has been archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
MainPage.xaml.cs
842 lines (689 loc) · 36.1 KB
/
MainPage.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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Background;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Foundation.Metadata;
using Windows.Management.Deployment;
using Windows.Storage;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.IO.Compression;
using Windows.UI.Core;
using System.Threading.Tasks;
using System.Xml.Linq;
using Windows.UI.Xaml.Media.Imaging;
using Windows.ApplicationModel;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace UWPPackageInstaller
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public StorageFile packageInContext;
APx.Package data = null;
List<Uri> dependencies = new List<Uri>();
//ValueSet cannot contain values of the URI class which is why there is another list below.
//This is required to update the progress in a notification using a background task.
List<string> dependenciesAsString = new List<string>();
bool pkgRegistered = false;
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// Attempts to get appx/appxbundle from the OnFileActivated event in App.xaml.cs
///If the cast fails in the try statement then the catch statement will change
///the UI so the user can load the required files themselves.
/// </summary>
/// <param name="e"></param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
try
{
StorageFile package = (StorageFile)e.Parameter;
packageInContext = package;
updateUIForPackageInstallation();
}
catch (Exception x)
{
Debug.WriteLine(x.Message);
permissionTextBlock.Text = "Load an .appx/.appxbundle file to install";
installProgressBar.Visibility = Visibility.Collapsed;
installValueTextBlock.Visibility = Visibility.Collapsed;
installButton.Visibility = Visibility.Collapsed;
cancelButton.Content = "Exit";
packageNameTextBlock.Text = "No package Selected";
}
}
private async void updateUIForPackageInstallation()
{
packageNameTextBlock.Text = packageInContext.DisplayName;
await Task.Run(async () =>
{
Task.Yield();
Stream stream = null;
string text = null;
if (packageInContext.Path.ToLower().EndsWith(".appx"))
{
using (ZipArchive archive = new ZipArchive((await packageInContext.OpenAsync(FileAccessMode.Read)).AsStreamForRead(), ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.ToString() == "AppxManifest.xml")
{
stream = entry.Open();
StreamReader reader = new StreamReader(stream);
text = reader.ReadToEnd();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
text = RemoveAllNamespaces(text);
data = APx.XmlConverter.ToClass<APx.Package>(text);
packageNameTextBlock.Text = data.Properties.DisplayName;
});
}
}
bool jk = false;
foreach (ZipArchiveEntry entry in archive.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (text != null && data != null)
{
string srnam = null;
if (entry.Name.ToString().Contains(".scale-"))
{
srnam = entry.Name.ToString().Substring(0, entry.Name.ToString().Length - 14);
}
else
{
srnam = entry.Name.ToString();
}
if (data.Properties.Logo.Contains(srnam))
{
stream = entry.Open();
BitmapImage bitmap = new BitmapImage();
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Position = 0;
bitmap.SetSource(memStream.AsRandomAccessStream());
pkgi.Source = bitmap;
}
jk = true;
}
}
});
if (jk)
{
break;
}
}
}
}
else
{
bool xc = false;
using (ZipArchive archive = new ZipArchive((await packageInContext.OpenAsync(FileAccessMode.Read)).AsStreamForRead(), ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (entry.Name.ToLower().EndsWith("x86.appx".ToLower()) || entry.Name.ToLower().EndsWith("x64.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm64.appx".ToLower()) || entry.Name.ToLower().EndsWith("x64_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("x86_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm64_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("anycpu.appx".ToLower()) || entry.Name.ToLower().EndsWith("anycpu_master.appx".ToLower()))
{
xc = true;
ZipArchive archive2 = new ZipArchive(entry.Open(), ZipArchiveMode.Read);
foreach (ZipArchiveEntry entry2 in archive2.Entries)
{
if (entry2.FullName.ToString() == "AppxManifest.xml")
{
stream = entry2.Open();
StreamReader reader = new StreamReader(stream);
text = reader.ReadToEnd();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
text = RemoveAllNamespaces(text);
data = APx.XmlConverter.ToClass<APx.Package>(text);
packageNameTextBlock.Text = data.Properties.DisplayName;
});
}
}
bool dy = false;
foreach (ZipArchiveEntry entry2 in archive2.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (text != null && data != null)
{
string srnam = null;
if (entry2.Name.ToString().Contains(".scale-"))
{
srnam = entry2.Name.ToString().Substring(0, entry2.Name.ToString().Length - 14);
}
else
{
srnam = entry2.Name.ToString();
}
if (data.Properties.Logo.Contains(srnam))
{
stream = entry2.Open();
BitmapImage bitmap = new BitmapImage();
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Position = 0;
bitmap.SetSource(memStream.AsRandomAccessStream());
pkgi.Source = bitmap;
}
dy = true;
}
}
});
if (dy)
{
break;
}
}
}
});
if (xc)
{
break;
}
}
}
}
});
var vp = new Version(data.Identity.Version);
PackageManager PkgManager = new PackageManager();
var ListOfInstalledPackages = PkgManager.FindPackagesForUserWithPackageTypes("", PackageTypes.Main);
List<Package> AllPackages = new List<Package>();
AllPackages = ListOfInstalledPackages.ToList();
Package PKG = null;
foreach (var pkg in AllPackages)
{
if (pkg.Id.Name == data.Identity.Name)
{
PKG = pkg;
}
}
if (PKG != null)
{
var vi = new Version(PKG.Id.Version.Major.ToString() + "." + PKG.Id.Version.Minor.ToString() + "." + PKG.Id.Version.Build.ToString() + "." + PKG.Id.Version.Revision.ToString());
if (vp > vi)
{
installButton.Content = "Update";
}
else
{
installButton.Content = "Re-Install";
}
}
else
{
installButton.Content = "Install";
}
loadFileButton.Content = "Load a different file";
}
public static string RemoveAllNamespaces(string xmlDocument)
{
XElement xmlDocumentWithoutNs = RemoveAllNamespaces(XElement.Parse(xmlDocument));
return xmlDocumentWithoutNs.ToString();
}
//Core recursion function
private static XElement RemoveAllNamespaces(XElement xmlDocument)
{
if (!xmlDocument.HasElements)
{
XElement xElement = new XElement(xmlDocument.Name.LocalName);
xElement.Value = xmlDocument.Value;
foreach (XAttribute attribute in xmlDocument.Attributes())
xElement.Add(attribute);
return xElement;
}
return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el)));
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
Application.Current.Exit();
}
/// <summary>
/// <para>
/// Installs the the package with or without it's dependencies depending on whether the user loads their dependecies or not.
/// The AddPackageAsync method uses the Uri of the files used to install the packages and dependencies.
/// </para>
/// <para>
/// WARNING: In order to use some PackageManager class' methods, restricted capabilities need to be added to
/// the appxmanifest. In this case, the restricted capability that has been added is the "packageManagement".
/// </para>
/// If they are not added, to your app and you use certain methods, your app will crash unexpectedly.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void installButton_Click(object sender, RoutedEventArgs e)
{
loadFileButton.Visibility = Visibility.Collapsed;
loadDependenciesButton.Visibility = Visibility.Collapsed;
installButton.Visibility = Visibility.Collapsed;
cancelButton.Visibility = Visibility.Collapsed;
//Modern Test:
//showProgressInNotification();
//Legacy Test:
//showProgressInApp();
//Normal Code:
//If the device is on the creators update or later, install progress is shown in the action center and App UI
//Otherwise, all progress is shown in the App's UI.
if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
{
showProgressInNotification();
}
else
{
showProgressInApp();
}
}
private async void showProgressInApp()
{
installProgressBar.Visibility = Visibility.Visible;
installValueTextBlock.Visibility = Visibility.Visible;
PackageManager pkgManager = new PackageManager();
Progress<DeploymentProgress> progressCallback = new Progress<DeploymentProgress>(installProgress);
string resultText = "Nothing";
notification.showInstallationHasStarted(packageInContext.Name);
if (dependencies != null && dependencies.Count > 0)
{
try
{
var result = await pkgManager.AddPackageAsync(new Uri(packageInContext.Path), dependencies, DeploymentOptions.ForceTargetApplicationShutdown).AsTask(progressCallback);
checkIfPackageRegistered(result, resultText);
}
catch (Exception e)
{
resultText = e.Message;
}
}
else
{
try
{
var result = await pkgManager.AddPackageAsync(new Uri(packageInContext.Path), null, DeploymentOptions.ForceTargetApplicationShutdown).AsTask(progressCallback);
checkIfPackageRegistered(result, resultText);
}
catch (Exception e)
{
resultText = e.Message;
}
}
cancelButton.Content = "Exit";
cancelButton.Visibility = Visibility.Visible;
if (pkgRegistered == true)
{
permissionTextBlock.Text = "Completed";
notification.ShowInstallationHasCompleted(packageInContext.Name);
}
else
{
resultTextBlock.Text = resultText;
notification.sendError(resultText);
}
}
private void checkIfPackageRegistered(DeploymentResult result, string resultText)
{
if (result.IsRegistered)
{
pkgRegistered = true;
}
else
{
resultText = result.ErrorText;
}
}
/// <summary>
/// Passes package file path and of file paths dependencies into the backgroundTask
/// using a ValueSet.
/// </summary>
private async void showProgressInNotification()
{
permissionTextBlock.Text = "Check Your Notifications/Action Center 😉";
var thingsToPassOver = new ValueSet();
thingsToPassOver.Add("packagePath", packageInContext.Path);
if (dependenciesAsString != null & dependenciesAsString.Count > 0)
{
int count = dependenciesAsString.Count();
for (int i = 0; i < count; i++)
{
thingsToPassOver.Add($"dependencies{i}", dependenciesAsString[i]);
}
thingsToPassOver.Add("installType", 1);
}
else
{
thingsToPassOver.Add("installType", 0);
}
PackageManager pkgManager = new PackageManager();
ApplicationTrigger appTrigger = new ApplicationTrigger();
var backgroundTask = RegisterBackgroundTask("installTask.install", "installTask", appTrigger);
//backgroundTask.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
backgroundTask.Progress += new BackgroundTaskProgressEventHandler(OnProgress);
var result = await appTrigger.RequestAsync(thingsToPassOver);
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "installTask")
{
AttachCompletedHandler(task.Value);
}
}
installProgressBar.Visibility = Visibility.Visible;
installValueTextBlock.Visibility = Visibility.Visible;
}
private async void OnProgress(BackgroundTaskRegistration sender, BackgroundTaskProgressEventArgs args)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
installProgressBar.Value = args.Progress;
installValueTextBlock.Text = $"{args.Progress}%";
});
}
private void AttachCompletedHandler(IBackgroundTaskRegistration task)
{
task.Completed += new BackgroundTaskCompletedEventHandler(OnCompleted);
}
private async void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
{
//UpdateUI;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
cancelButton.Content = "Exit";
cancelButton.Visibility = Visibility.Visible;
permissionTextBlock.Text = "Insall Task Complete, check notifications for results";
});
}
public static BackgroundTaskRegistration RegisterBackgroundTask(string taskEntryPoint,
string taskName,
IBackgroundTrigger trigger)
{
//
// Check for existing registrations of this background task.
//
foreach (var cur in BackgroundTaskRegistration.AllTasks)
{
if (cur.Value.Name == taskName)
{
//
// The task is already registered.
//
return (BackgroundTaskRegistration)(cur.Value);
}
}
//
// Register the background task.
//
var builder = new BackgroundTaskBuilder();
builder.Name = taskName;
builder.TaskEntryPoint = taskEntryPoint;
builder.SetTrigger(trigger);
BackgroundTaskRegistration task = builder.Register();
return task;
}
/// <summary>
/// Updates the progress bar and status of the installation in the app's UI.
/// </summary>
/// <param name="installProgress"></param>
private void installProgress(DeploymentProgress installProgress)
{
double installPercentage = installProgress.percentage;
permissionTextBlock.Text = "Installing...";
installProgressBar.Value = installPercentage;
string percentageAsString = String.Format($"{installPercentage}%");
installValueTextBlock.Text = percentageAsString;
}
/// <summary>
/// Retreives an appx/appxbundle file using the file picker
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void loadFileButton_Click(object sender, RoutedEventArgs e)
{
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
picker.FileTypeFilter.Add(".appx");
picker.FileTypeFilter.Add(".appxbundle");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
//UI changes to allow the user to install the package
packageInContext = file;
permissionTextBlock.Text = "Do you want to install this package?";
installButton.Visibility = Visibility.Visible;
cancelButton.Content = "Cancel";
packageNameTextBlock.Text = packageInContext.DisplayName;
await Task.Run(async () =>
{
Task.Yield();
Stream stream = null;
string text = null;
if (packageInContext.Path.ToLower().EndsWith(".appx"))
{
using (ZipArchive archive = new ZipArchive((await packageInContext.OpenAsync(FileAccessMode.Read)).AsStreamForRead(), ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.ToString() == "AppxManifest.xml")
{
stream = entry.Open();
StreamReader reader = new StreamReader(stream);
text = reader.ReadToEnd();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
// Your UI update code goes here!
//Debug.WriteLine("TEXT: " + text);
//tt5.Text = text;
text = RemoveAllNamespaces(text);
data = APx.XmlConverter.ToClass<APx.Package>(text);
packageNameTextBlock.Text = data.Properties.DisplayName;
});
}
}
bool jk = false;
foreach (ZipArchiveEntry entry in archive.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
/* _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Debug.WriteLine(packageNameTextBlock.Text);
}
);*/
if (text != null && data != null)
{
string srnam = null;
if (entry.Name.ToString().Contains(".scale-"))
{
srnam = entry.Name.ToString().Substring(0, entry.Name.ToString().Length - 14);
}
else
{
srnam = entry.Name.ToString();
}
if (data.Properties.Logo.Contains(srnam))
{
stream = entry.Open();
BitmapImage bitmap = new BitmapImage();
//Debug.WriteLine("Done 2");
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Position = 0;
bitmap.SetSource(memStream.AsRandomAccessStream());
pkgi.Source = bitmap;
}
jk = true;
}
}
});
if (jk)
{
break;
}
}
}
}
else
{
bool xc = false;
using (ZipArchive archive = new ZipArchive((await packageInContext.OpenAsync(FileAccessMode.Read)).AsStreamForRead(), ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
if (entry.Name.ToLower().EndsWith("x86.appx".ToLower()) || entry.Name.ToLower().EndsWith("x64.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm64.appx".ToLower()) || entry.Name.ToLower().EndsWith("x64_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("x86_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("arm64_master.appx".ToLower()) || entry.Name.ToLower().EndsWith("anycpu.appx".ToLower()) || entry.Name.ToLower().EndsWith("anycpu_master.appx".ToLower()))
{
xc = true;
ZipArchive archive2 = new ZipArchive(entry.Open(), ZipArchiveMode.Read);
foreach (ZipArchiveEntry entry2 in archive2.Entries)
{
if (entry2.FullName.ToString() == "AppxManifest.xml")
{
stream = entry2.Open();
StreamReader reader = new StreamReader(stream);
text = reader.ReadToEnd();
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
// Your UI update code goes here!
//Debug.WriteLine("TEXT: " + text);
//tt5.Text = text;
text = RemoveAllNamespaces(text);
data = APx.XmlConverter.ToClass<APx.Package>(text);
packageNameTextBlock.Text = data.Properties.DisplayName;
});
}
}
bool dy = false;
foreach (ZipArchiveEntry entry2 in archive2.Entries)
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
/* _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
Debug.WriteLine(packageNameTextBlock.Text);
}
);*/
if (text != null && data != null)
{
string srnam = null;
if (entry2.Name.ToString().Contains(".scale-"))
{
srnam = entry2.Name.ToString().Substring(0, entry2.Name.ToString().Length - 14);
}
else
{
srnam = entry2.Name.ToString();
}
if (data.Properties.Logo.Contains(srnam))
{
stream = entry2.Open();
BitmapImage bitmap = new BitmapImage();
//Debug.WriteLine("Done 2");
using (var memStream = new MemoryStream())
{
await stream.CopyToAsync(memStream);
memStream.Position = 0;
bitmap.SetSource(memStream.AsRandomAccessStream());
pkgi.Source = bitmap;
}
dy = true;
}
}
});
if (dy)
{
break;
}
}
}
});
if (xc)
{
break;
}
}
}
}
});
var vp = new Version(data.Identity.Version);
PackageManager PkgManager = new PackageManager();
//var inpkg = PkgManager.FindPackage(data.Identity.Name);
var ListOfInstalledPackages = PkgManager.FindPackagesForUserWithPackageTypes("", PackageTypes.Main);
List<Package> AllPackages = new List<Package>();
AllPackages = ListOfInstalledPackages.ToList();
Package PKG = null;
foreach (var pkg in AllPackages)
{
if (pkg.Id.Name == data.Identity.Name)
{
PKG = pkg;
}
}
if (PKG != null)
{
var vi = new Version(PKG.Id.Version.Major.ToString() + "." + PKG.Id.Version.Minor.ToString() + "." + PKG.Id.Version.Build.ToString() + "." + PKG.Id.Version.Revision.ToString());
if (vp > vi)
{
installButton.Content = "Update";
}
else
{
installButton.Content = "Re-Install";
}
}
else
{
installButton.Content = "Install";
}
loadFileButton.Content = "Load a different file";
}
}
/// <summary>
/// Retrieves one OR MORE dependencies using the file picker
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void loadDependenciesButton_Click(object sender, RoutedEventArgs e)
{
dependencies = new List<Uri>();
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
picker.FileTypeFilter.Add(".appx");
picker.FileTypeFilter.Add(".appxbundle");
var files = await picker.PickMultipleFilesAsync();
if (files != null)
{
foreach (var dependency in files)
{
dependencies.Add(new Uri(dependency.Path));
}
foreach (var dependency in files)
{
dependenciesAsString.Add(dependency.Path);
}
loadDependenciesButton.Content = "Load different dependencies";
}
}
}
}