11using DiscUtils ;
2+ using MobilePackageGen . UpdateHistory ;
23using System . Xml ;
34using System . Xml . Linq ;
45
@@ -62,7 +63,7 @@ public static List<AppxPackage> ReadAppxPackagesFromFM(Stream strm)
6263
6364 XDocument xdoc = XDocument . Load ( strm , LoadOptions . None ) ;
6465 XNamespace ns = xdoc . Root ! . GetDefaultNamespace ( ) ;
65-
66+
6667 IEnumerable < XElement > packages = xdoc . Descendants ( ns + "AppXPackages" ) ;
6768
6869 if ( packages != null )
@@ -83,51 +84,101 @@ public static List<AppxPackage> ReadAppxPackagesFromFM(Stream strm)
8384 return appList ;
8485 }
8586
86- public static List < AppxPackage > GetAppList ( IEnumerable < IDisk > disks , string destination_path )
87+ public static List < AppxPackage > GetAppList ( IEnumerable < IDisk > disks )
8788 {
8889 List < AppxPackage > appList = [ ] ;
89- string OEMInputPath = Path . Combine ( destination_path , "OEMInput.xml" ) ;
9090
91- if ( ! File . Exists ( OEMInputPath ) )
91+ string ? content = GetOEMInputContent ( disks ) ;
92+
93+ if ( content == null )
9294 {
9395 return [ ] ;
9496 }
9597
96- string [ ] FMs = File . ReadAllLines ( OEMInputPath ) ;
98+ string [ ] FMs = content . Split ( "\n " ) ;
99+
97100 FMs = [ .. FMs . Where ( x => x . Contains ( "<AdditionalFM>" ) ) . Select ( x => x . Split ( ">" ) [ 1 ] . Split ( "<" ) [ 0 ] ) ] ;
98101
99102 foreach ( string FM in FMs )
100103 {
101- string destFM = Path . Combine ( destination_path , ReformatDestinationPath ( FM ) ) ;
102-
103- if ( File . Exists ( destFM ) )
104+ foreach ( IDisk disk in disks )
104105 {
105- using Stream strm = File . OpenRead ( destFM ) ;
106-
107- try
106+ foreach ( IPartition partition in disk . Partitions )
108107 {
109- appList . AddRange ( ReadAppxPackagesFromFM ( strm ) ) ;
108+ IFileSystem ? fileSystem = partition . FileSystem ;
109+
110+ if ( fileSystem != null )
111+ {
112+ if ( fileSystem . FileExists ( $@ "Windows\ImageUpdate\FeatureManifest\Microsoft\{ Path . GetFileName ( FM ) } ") )
113+ {
114+ using Stream strm = fileSystem . OpenFile ( $@ "Windows\ImageUpdate\FeatureManifest\Microsoft\{ Path . GetFileName ( FM ) } ", FileMode . Open , FileAccess . Read ) ;
115+
116+ try
117+ {
118+ appList . AddRange ( ReadAppxPackagesFromFM ( strm ) ) ;
119+ }
120+ catch ( XmlException )
121+ {
122+ // Skip all unreadable xml
123+ }
124+ }
125+ else if ( fileSystem . FileExists ( $@ "Windows\ImageUpdate\FeatureManifest\OEM\{ Path . GetFileName ( FM ) } ") )
126+ {
127+ using Stream strm = fileSystem . OpenFile ( $@ "Windows\ImageUpdate\FeatureManifest\OEM\{ Path . GetFileName ( FM ) } ", FileMode . Open , FileAccess . Read ) ;
128+
129+ try
130+ {
131+ appList . AddRange ( ReadAppxPackagesFromFM ( strm ) ) ;
132+ }
133+ catch ( XmlException )
134+ {
135+ // Skip all unreadable xml
136+ }
137+ }
138+ }
110139 }
111- catch ( XmlException )
140+ }
141+ }
142+
143+ return appList ;
144+ }
145+
146+ public static string ? GetOEMInputContent ( IEnumerable < IDisk > disks )
147+ {
148+ foreach ( IDisk disk in disks )
149+ {
150+ foreach ( IPartition partition in disk . Partitions )
151+ {
152+ IFileSystem ? fileSystem = partition . FileSystem ;
153+
154+ if ( fileSystem != null )
112155 {
113- // Skip all unreadable xml
156+ if ( fileSystem . FileExists ( @"Windows\ImageUpdate\OEMInput.xml" ) )
157+ {
158+ using Stream OEMInputFileStream = fileSystem . OpenFile ( @"Windows\ImageUpdate\OEMInput.xml" , FileMode . Open , FileAccess . Read ) ;
159+ using StreamReader streamReader = new StreamReader ( OEMInputFileStream ) ;
160+ string content = streamReader . ReadToEnd ( ) ;
161+
162+ return content ;
163+ }
114164 }
115165 }
116166 }
117167
118- return appList ;
168+ return null ;
119169 }
120170
121171 public static void GetFeatureManifests ( IEnumerable < IDisk > disks , string destination_path )
122172 {
123- string OEMInputPath = Path . Combine ( destination_path , "OEMInput.xml" ) ;
173+ string ? content = GetOEMInputContent ( disks ) ;
124174
125- if ( ! File . Exists ( OEMInputPath ) )
175+ if ( content == null )
126176 {
127177 return ;
128178 }
129179
130- string [ ] FMs = File . ReadAllLines ( OEMInputPath ) ;
180+ string [ ] FMs = content . Split ( "\n " ) ;
181+
131182 FMs = [ .. FMs . Where ( x => x . Contains ( "<AdditionalFM>" ) ) . Select ( x => x . Split ( ">" ) [ 1 ] . Split ( "<" ) [ 0 ] ) ] ;
132183
133184 foreach ( string FM in FMs )
@@ -407,7 +458,7 @@ public static (string cabFileName, string cabFile) GetPackageNamingForINF(string
407458 string cabFile = "" ;
408459
409460 bool found = false ;
410-
461+
411462 string infFileName = Path . GetFileNameWithoutExtension ( inf ) ;
412463
413464 if ( updateHistory != null )
0 commit comments