1212
1313namespace StartPro . Api ;
1414
15- #if WINDOWS
16-
15+ #if WINDOWS7_0_OR_GREATER
1716public static partial class SystemTiles
1817{
1918 private static readonly Dictionary < string , TileSize > SizeMap = new ( )
@@ -24,7 +23,7 @@ public static partial class SystemTiles
2423 [ "4x4" ] = TileSize . Large
2524 } ;
2625
27- public static TileBase CreateTile ( TileData data )
26+ public static TileBase CreateTile ( TileRaw data )
2827 {
2928 return new AppTile
3029 {
@@ -42,11 +41,11 @@ public static TileBase CreateTile(TileData data)
4241 } ;
4342 }
4443
45- public static List < TileData > ImportData ( )
44+ public static List < TileRaw > ImportData ( )
4645 {
4746 if ( ! GetXml ( out XDocument xml ) )
4847 return [ ] ;
49- List < TileData > result = [ ] ;
48+ List < TileRaw > result = [ ] ;
5049
5150 IEnumerable < XElement > groups = xml
5251 . Descendants ( )
@@ -73,7 +72,7 @@ public static List<TileData> ImportData( )
7372 int row = int . TryParse ( rowRaw , out int _row ) ? _row : 0 ;
7473 if ( row > rowMax ) rowMax = row ;
7574
76- TileData tileData = ParseTileData ( tile , row + rowAdjust , col + colAdjust ) ;
75+ TileRaw tileData = ParseTileData ( tile , row + rowAdjust , col + colAdjust ) ;
7776 result . Add ( tileData ) ;
7877 }
7978 colAdjust += groupWidth + 1 ;
@@ -154,7 +153,7 @@ private static bool GetXml(out XDocument xml)
154153 }
155154 }
156155
157- public record TileData (
156+ public record TileRaw (
158157 string AppName ,
159158 string AppPath ,
160159 string Arguments ,
@@ -164,7 +163,7 @@ public record TileData(
164163 int Column
165164 ) ;
166165
167- private static TileData ParseTileData ( XElement tile , int row , int col )
166+ private static TileRaw ParseTileData ( XElement tile , int row , int col )
168167 {
169168 TileSize size = SizeMap [ tile . Attribute ( "Size" ) ! . Value ] ;
170169 string name , path , arguments , icon ;
@@ -189,17 +188,19 @@ private static TileData ParseTileData(XElement tile, int row, int col)
189188 icon = string . IsNullOrEmpty ( arguments ) ? path : lnk ;
190189 }
191190 }
192- return new TileData ( name , path , arguments , icon , size , row , col ) ;
191+ return new TileRaw ( name , path , arguments , icon , size , row , col ) ;
193192 }
194193}
194+ #endif
195195
196+ #if WINDOWS
196197public class SystemApp
197198{
198199 public static ReadOnlyCollection < SystemApp > Apps ;
199200 public static string SystemAppsPath = Environment . ExpandEnvironmentVariables ( "%ProgramData%\\ Microsoft\\ Windows\\ Start Menu\\ Programs" ) ;
200201 public static string UserAppsPath = Environment . ExpandEnvironmentVariables ( "%AppData%\\ Microsoft\\ Windows\\ Start Menu\\ Programs" ) ;
201202
202- private Icon appIcon ;
203+ private IntPtr appIcon ;
203204 public BitmapSource AppIcon { get ; set ; }
204205
205206 public string AppName { get ; set ; }
@@ -210,37 +211,43 @@ public class SystemApp
210211
211212 public static void LoadApps ( )
212213 {
213- Apps = new ReadOnlyCollection < SystemApp > (
214- [ .. Directory . GetFiles ( UserAppsPath , "*.lnk" , SearchOption . AllDirectories )
215- . Concat ( Directory . GetFiles ( SystemAppsPath , "*.lnk" , SearchOption . AllDirectories ) )
216- . Select ( FromLazy ) . Where ( static item => item is not null ) ]
217- ) ;
214+ string [ ] UserApps = Directory . GetFiles ( UserAppsPath , "*.lnk" , SearchOption . AllDirectories ) ;
215+ string [ ] SystemApps = Directory . GetFiles ( SystemAppsPath , "*.lnk" , SearchOption . AllDirectories ) ;
216+ Apps = new ( [ .. UserApps . Concat ( SystemApps ) . Select ( FromLazy ) ] ) ;
218217 }
219218
220219 public static void LoadIcon ( )
221220 {
222221 foreach ( SystemApp app in Apps )
223222 {
224- app . AppIcon =
225- PEIcon . FromIcon ( app . appIcon , out BitmapSource source )
226- ? source : new BitmapImage ( ) ;
223+ app . AppIcon = PEIcon . FromIcon ( Icon . FromHandle ( app . appIcon ) , out BitmapSource source )
224+ ? source
225+ : PEIcon . FromBitmap ( app . appIcon , out BitmapSource source1 )
226+ ? source1
227+ : new BitmapImage ( ) ;
227228 app . AppIcon . Freeze ( ) ;
228229 }
229230 }
230231
231232 private static SystemApp FromLazy ( string appPath )
232233 {
233234 string appName = Path . GetFileNameWithoutExtension ( appPath ) ;
234- return ! Integration . ResolveShortcut ( appPath , out string target , out string arguments )
235- ? null
236- : new SystemApp
235+ return appPath . EndsWith ( "*.lnk" , StringComparison . InvariantCultureIgnoreCase )
236+ && Integration . ResolveShortcut ( appPath , out string target , out string arguments )
237+ ? new SystemApp
237238 {
238239 AppName = appName ,
239240 AppPath = target ,
240241 Arguments = arguments ,
241- appIcon = PEIcon . GetDirect ( target ) ,
242+ appIcon = PEIcon . DirectIcon ( target ) ? . Handle ?? IntPtr . Zero ,
243+ }
244+ : new SystemApp
245+ {
246+ AppName = appName ,
247+ AppPath = appPath ,
248+ Arguments = string . Empty ,
249+ appIcon = PEIcon . ComplexBitmap ( appPath )
242250 } ;
243251 }
244252}
245-
246253#endif
0 commit comments