@@ -78,7 +78,7 @@ private void InitializeAppInfo()
78
78
{
79
79
var e = Marshal . GetExceptionForHR ( ( int ) hResult ) ;
80
80
ProgramLogger . LogException ( $ "|UWP|InitializeAppInfo|{ path } " +
81
- "|Error caused while trying to get the details of the UWP program" , e ) ;
81
+ "|Error caused while trying to get the details of the UWP program" , e ) ;
82
82
83
83
Apps = new List < Application > ( ) . ToArray ( ) ;
84
84
}
@@ -91,38 +91,45 @@ private void InitializeAppInfo()
91
91
92
92
93
93
94
+
94
95
/// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
95
96
private string [ ] XmlNamespaces ( string path )
96
97
{
97
98
XDocument z = XDocument . Load ( path ) ;
98
99
if ( z . Root != null )
99
100
{
100
- var namespaces = z . Root . Attributes ( ) .
101
- Where ( a => a . IsNamespaceDeclaration ) .
102
- GroupBy (
103
- a => a . Name . Namespace == XNamespace . None ? string . Empty : a . Name . LocalName ,
104
- a => XNamespace . Get ( a . Value )
105
- ) . Select (
106
- g => g . First ( ) . ToString ( )
107
- ) . ToArray ( ) ;
101
+ var namespaces = z . Root . Attributes ( ) . Where ( a => a . IsNamespaceDeclaration ) . GroupBy (
102
+ a => a . Name . Namespace == XNamespace . None ? string . Empty : a . Name . LocalName ,
103
+ a => XNamespace . Get ( a . Value )
104
+ ) . Select (
105
+ g => g . First ( ) . ToString ( )
106
+ ) . ToArray ( ) ;
108
107
return namespaces ;
109
108
}
110
109
else
111
110
{
112
111
ProgramLogger . LogException ( $ "|UWP|XmlNamespaces|{ path } " +
113
- $ "|Error occured while trying to get the XML from { path } ", new ArgumentNullException ( ) ) ;
112
+ $ "|Error occured while trying to get the XML from { path } ", new ArgumentNullException ( ) ) ;
114
113
115
- return new string [ ] { } ;
114
+ return new string [ ]
115
+ {
116
+ } ;
116
117
}
117
118
}
118
119
119
120
private void InitPackageVersion ( string [ ] namespaces )
120
121
{
121
122
var versionFromNamespace = new Dictionary < string , PackageVersion >
122
123
{
123
- { "http://schemas.microsoft.com/appx/manifest/foundation/windows10" , PackageVersion . Windows10 } ,
124
- { "http://schemas.microsoft.com/appx/2013/manifest" , PackageVersion . Windows81 } ,
125
- { "http://schemas.microsoft.com/appx/2010/manifest" , PackageVersion . Windows8 } ,
124
+ {
125
+ "http://schemas.microsoft.com/appx/manifest/foundation/windows10" , PackageVersion . Windows10
126
+ } ,
127
+ {
128
+ "http://schemas.microsoft.com/appx/2013/manifest" , PackageVersion . Windows81
129
+ } ,
130
+ {
131
+ "http://schemas.microsoft.com/appx/2010/manifest" , PackageVersion . Windows8
132
+ } ,
126
133
} ;
127
134
128
135
foreach ( var n in versionFromNamespace . Keys )
@@ -135,8 +142,8 @@ private void InitPackageVersion(string[] namespaces)
135
142
}
136
143
137
144
ProgramLogger . LogException ( $ "|UWP|XmlNamespaces|{ Location } " +
138
- "|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version "
139
- + $ "{ FullName } from location { Location } is returned.", new FormatException ( ) ) ;
145
+ "|Trying to get the package version of the UWP program, but a unknown UWP appmanifest version "
146
+ + $ "{ FullName } from location { Location } is returned.", new FormatException ( ) ) ;
140
147
141
148
Version = PackageVersion . Unknown ;
142
149
}
@@ -172,15 +179,17 @@ public static Application[] All()
172
179
} ) . ToArray ( ) ;
173
180
174
181
var updatedListWithoutDisabledApps = applications
175
- . Where ( t1 => ! Main . _settings . DisabledProgramSources
176
- . Any ( x => x . UniqueIdentifier == t1 . UniqueIdentifier ) )
177
- . Select ( x => x ) ;
182
+ . Where ( t1 => ! Main . _settings . DisabledProgramSources
183
+ . Any ( x => x . UniqueIdentifier == t1 . UniqueIdentifier ) )
184
+ . Select ( x => x ) ;
178
185
179
186
return updatedListWithoutDisabledApps . ToArray ( ) ;
180
187
}
181
188
else
182
189
{
183
- return new Application [ ] { } ;
190
+ return new Application [ ]
191
+ {
192
+ } ;
184
193
}
185
194
}
186
195
@@ -216,7 +225,7 @@ private static IEnumerable<Package> CurrentUserPackages()
216
225
catch ( Exception e )
217
226
{
218
227
ProgramLogger . LogException ( "UWP" , "CurrentUserPackages" , $ "id", "An unexpected error occured and "
219
- + $ "unable to verify if package is valid", e ) ;
228
+ + $ "unable to verify if package is valid", e ) ;
220
229
return false ;
221
230
}
222
231
@@ -226,10 +235,30 @@ private static IEnumerable<Package> CurrentUserPackages()
226
235
}
227
236
else
228
237
{
229
- return new Package [ ] { } ;
238
+ return new Package [ ]
239
+ {
240
+ } ;
230
241
}
231
242
}
232
243
244
+ private static List < FileSystemWatcher > _watchers = new ( ) ;
245
+
246
+ private static void GenerateWatcher ( string path )
247
+ {
248
+ var watcher = new FileSystemWatcher ( path ) ;
249
+ watcher . Created += static ( _ , _ ) => Task . Run ( Main . IndexUwpPrograms ) ;
250
+ watcher . Deleted += static ( _ , _ ) => Task . Run ( Main . IndexUwpPrograms ) ;
251
+ watcher . EnableRaisingEvents = true ;
252
+ }
253
+
254
+ public static void WatchUWPInstallation ( )
255
+ {
256
+ PackageCatalog . OpenForCurrentUser ( ) . PackageStatusChanged += ( _ , _ ) =>
257
+ {
258
+ Task . Delay ( 10000 ) . ContinueWith ( t => Main . IndexUwpPrograms ( ) ) ;
259
+ } ;
260
+ }
261
+
233
262
public override string ToString ( )
234
263
{
235
264
return FamilyName ;
@@ -326,7 +355,7 @@ public Result Result(string query, IPublicAPI api)
326
355
e . SpecialKeyState . ShiftPressed &&
327
356
! e . SpecialKeyState . AltPressed &&
328
357
! e . SpecialKeyState . WinPressed
329
- ) ;
358
+ ) ;
330
359
331
360
if ( elevated && CanRunElevated )
332
361
{
@@ -359,14 +388,12 @@ public List<Result> ContextMenus(IPublicAPI api)
359
388
new Result
360
389
{
361
390
Title = api . GetTranslation ( "flowlauncher_plugin_program_open_containing_folder" ) ,
362
-
363
391
Action = _ =>
364
392
{
365
393
Main . Context . API . OpenDirectory ( Package . Location ) ;
366
394
367
395
return true ;
368
396
} ,
369
-
370
397
IcoPath = "Images/folder.png"
371
398
}
372
399
} ;
@@ -415,8 +442,7 @@ private async void LaunchElevated()
415
442
416
443
var info = new ProcessStartInfo ( command )
417
444
{
418
- UseShellExecute = true ,
419
- Verb = "runas" ,
445
+ UseShellExecute = true , Verb = "runas" ,
420
446
} ;
421
447
422
448
Main . StartProcess ( Process . Start , info ) ;
@@ -493,7 +519,7 @@ internal string ResourceFromPri(string packageFullName, string packageName, stri
493
519
else
494
520
{
495
521
ProgramLogger . LogException ( $ "|UWP|ResourceFromPri|{ Package . Location } |Can't load null or empty result "
496
- + $ "pri { source } in uwp location { Package . Location } ", new NullReferenceException ( ) ) ;
522
+ + $ "pri { source } in uwp location { Package . Location } ", new NullReferenceException ( ) ) ;
497
523
return string . Empty ;
498
524
}
499
525
}
@@ -533,9 +559,15 @@ internal string LogoUriFromManifest(AppxPackageHelper.IAppxManifestApplication a
533
559
{
534
560
var logoKeyFromVersion = new Dictionary < PackageVersion , string >
535
561
{
536
- { PackageVersion . Windows10 , "Square44x44Logo" } ,
537
- { PackageVersion . Windows81 , "Square30x30Logo" } ,
538
- { PackageVersion . Windows8 , "SmallLogo" } ,
562
+ {
563
+ PackageVersion . Windows10 , "Square44x44Logo"
564
+ } ,
565
+ {
566
+ PackageVersion . Windows81 , "Square30x30Logo"
567
+ } ,
568
+ {
569
+ PackageVersion . Windows8 , "SmallLogo"
570
+ } ,
539
571
} ;
540
572
if ( logoKeyFromVersion . ContainsKey ( Package . Version ) )
541
573
{
@@ -572,14 +604,40 @@ internal string LogoPathFromUri(string uri)
572
604
{
573
605
var end = path . Length - extension . Length ;
574
606
var prefix = path . Substring ( 0 , end ) ;
575
- var paths = new List < string > { path } ;
607
+ var paths = new List < string >
608
+ {
609
+ path
610
+ } ;
576
611
577
612
var scaleFactors = new Dictionary < PackageVersion , List < int > >
578
613
{
579
614
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
580
- { PackageVersion . Windows10 , new List < int > { 100 , 125 , 150 , 200 , 400 } } ,
581
- { PackageVersion . Windows81 , new List < int > { 100 , 120 , 140 , 160 , 180 } } ,
582
- { PackageVersion . Windows8 , new List < int > { 100 } }
615
+ {
616
+ PackageVersion . Windows10 , new List < int >
617
+ {
618
+ 100 ,
619
+ 125 ,
620
+ 150 ,
621
+ 200 ,
622
+ 400
623
+ }
624
+ } ,
625
+ {
626
+ PackageVersion . Windows81 , new List < int >
627
+ {
628
+ 100 ,
629
+ 120 ,
630
+ 140 ,
631
+ 160 ,
632
+ 180
633
+ }
634
+ } ,
635
+ {
636
+ PackageVersion . Windows8 , new List < int >
637
+ {
638
+ 100
639
+ }
640
+ }
583
641
} ;
584
642
585
643
if ( scaleFactors . ContainsKey ( Package . Version ) )
@@ -598,15 +656,15 @@ internal string LogoPathFromUri(string uri)
598
656
else
599
657
{
600
658
ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
601
- $ "|{ UserModelId } can't find logo uri for { uri } in package location: { Package . Location } ", new FileNotFoundException ( ) ) ;
659
+ $ "|{ UserModelId } can't find logo uri for { uri } in package location: { Package . Location } ", new FileNotFoundException ( ) ) ;
602
660
return string . Empty ;
603
661
}
604
662
}
605
663
else
606
664
{
607
665
ProgramLogger . LogException ( $ "|UWP|LogoPathFromUri|{ Package . Location } " +
608
- $ "|Unable to find extension from { uri } for { UserModelId } " +
609
- $ "in package location { Package . Location } ", new FileNotFoundException ( ) ) ;
666
+ $ "|Unable to find extension from { uri } for { UserModelId } " +
667
+ $ "in package location { Package . Location } ", new FileNotFoundException ( ) ) ;
610
668
return string . Empty ;
611
669
}
612
670
}
@@ -633,8 +691,8 @@ private BitmapImage ImageFromPath(string path)
633
691
else
634
692
{
635
693
ProgramLogger . LogException ( $ "|UWP|ImageFromPath|{ ( string . IsNullOrEmpty ( path ) ? "Not Avaliable" : path ) } " +
636
- $ "|Unable to get logo for { UserModelId } from { path } and" +
637
- $ " located in { Package . Location } ", new FileNotFoundException ( ) ) ;
694
+ $ "|Unable to get logo for { UserModelId } from { path } and" +
695
+ $ " located in { Package . Location } ", new FileNotFoundException ( ) ) ;
638
696
return new BitmapImage ( new Uri ( Constant . MissingImgIcon ) ) ;
639
697
}
640
698
}
@@ -682,8 +740,8 @@ private ImageSource PlatedImage(BitmapImage image)
682
740
else
683
741
{
684
742
ProgramLogger . LogException ( $ "|UWP|PlatedImage|{ Package . Location } " +
685
- $ "|Unable to convert background string { BackgroundColor } " +
686
- $ "to color for { Package . Location } ", new InvalidOperationException ( ) ) ;
743
+ $ "|Unable to convert background string { BackgroundColor } " +
744
+ $ "to color for { Package . Location } ", new InvalidOperationException ( ) ) ;
687
745
688
746
return new BitmapImage ( new Uri ( Constant . MissingImgIcon ) ) ;
689
747
}
@@ -701,6 +759,14 @@ public override string ToString()
701
759
}
702
760
}
703
761
762
+ public static void Dispose ( )
763
+ {
764
+ foreach ( var fileSystemWatcher in _watchers )
765
+ {
766
+ fileSystemWatcher . Dispose ( ) ;
767
+ }
768
+ }
769
+
704
770
public enum PackageVersion
705
771
{
706
772
Windows10 ,
@@ -728,5 +794,6 @@ private static extern Hresult SHCreateStreamOnFileEx(string fileName, Stgm grfMo
728
794
[ DllImport ( "shlwapi.dll" , CharSet = CharSet . Unicode ) ]
729
795
private static extern Hresult SHLoadIndirectString ( string pszSource , StringBuilder pszOutBuf , uint cchOutBuf ,
730
796
IntPtr ppvReserved ) ;
797
+
731
798
}
732
799
}
0 commit comments