@@ -175,227 +175,6 @@ public static IReadOnlyList<string> GetAvailableRidsFromZipFile(string zipPath)
175175 }
176176 }
177177
178- /// <summary>
179- /// Gets statistics about the runtime assets in a package, showing what would be included vs excluded.
180- /// </summary>
181- /// <param name="archive">The zip archive to analyze.</param>
182- /// <returns>A RuntimeFilterStats object with filtering statistics.</returns>
183- public static RuntimeFilterStats GetFilteringStatistics ( ZipArchive archive )
184- {
185- if ( archive == null )
186- {
187- throw new ArgumentNullException ( nameof ( archive ) ) ;
188- }
189-
190- var stats = new RuntimeFilterStats
191- {
192- CurrentRid = RuntimeIdentifierHelper . GetCurrentRuntimeIdentifier ( ) ,
193- CompatibleRids = RuntimeIdentifierHelper . GetCompatibleRuntimeIdentifiers ( ) . ToList ( )
194- } ;
195-
196- foreach ( ZipArchiveEntry entry in archive . Entries )
197- {
198- if ( entry . Length == 0 )
199- {
200- continue ; // Skip directories
201- }
202-
203- if ( IsRuntimesEntry ( entry . FullName ) )
204- {
205- string rid = GetRidFromRuntimesEntry ( entry . FullName ) ;
206-
207- if ( ShouldIncludeEntry ( entry . FullName ) )
208- {
209- stats . IncludedRuntimeEntriesCount ++ ;
210- stats . IncludedRuntimeEntriesSize += entry . Length ;
211-
212- if ( ! string . IsNullOrEmpty ( rid ) )
213- {
214- if ( ! stats . IncludedRids . Contains ( rid ) )
215- {
216- stats . IncludedRids . Add ( rid ) ;
217- }
218- }
219- }
220- else
221- {
222- stats . ExcludedRuntimeEntriesCount ++ ;
223- stats . ExcludedRuntimeEntriesSize += entry . Length ;
224-
225- if ( ! string . IsNullOrEmpty ( rid ) )
226- {
227- if ( ! stats . ExcludedRids . Contains ( rid ) )
228- {
229- stats . ExcludedRids . Add ( rid ) ;
230- }
231- }
232- }
233- }
234- else
235- {
236- stats . NonRuntimeEntriesCount ++ ;
237- stats . NonRuntimeEntriesSize += entry . Length ;
238- }
239- }
240-
241- return stats ;
242- }
243-
244- /// <summary>
245- /// Filters zip entries based on the current platform's RID.
246- /// Returns only entries that should be extracted for this platform.
247- /// </summary>
248- /// <param name="entries">The collection of zip entries to filter.</param>
249- /// <returns>Filtered entries that should be extracted.</returns>
250- public static IEnumerable < ZipArchiveEntry > FilterEntriesForCurrentPlatform ( IEnumerable < ZipArchiveEntry > entries )
251- {
252- if ( entries == null )
253- {
254- throw new ArgumentNullException ( nameof ( entries ) ) ;
255- }
256-
257- foreach ( ZipArchiveEntry entry in entries )
258- {
259- if ( ShouldIncludeEntry ( entry . FullName ) )
260- {
261- yield return entry ;
262- }
263- }
264- }
265-
266- /// <summary>
267- /// Checks if a package has any platform-specific runtime assets.
268- /// </summary>
269- /// <param name="archive">The zip archive to check.</param>
270- /// <returns>True if the package contains runtime assets; otherwise, false.</returns>
271- public static bool HasRuntimeAssets ( ZipArchive archive )
272- {
273- if ( archive == null )
274- {
275- return false ;
276- }
277-
278- foreach ( ZipArchiveEntry entry in archive . Entries )
279- {
280- if ( IsRuntimesEntry ( entry . FullName ) )
281- {
282- return true ;
283- }
284- }
285-
286- return false ;
287- }
288-
289178 #endregion
290179 }
291-
292- /// <summary>
293- /// Statistics about runtime asset filtering for a package.
294- /// </summary>
295- internal class RuntimeFilterStats
296- {
297- /// <summary>
298- /// The current platform's runtime identifier.
299- /// </summary>
300- public string CurrentRid { get ; set ; }
301-
302- /// <summary>
303- /// List of RIDs compatible with the current platform.
304- /// </summary>
305- public List < string > CompatibleRids { get ; set ; } = new List < string > ( ) ;
306-
307- /// <summary>
308- /// RIDs that will be included in the installation.
309- /// </summary>
310- public List < string > IncludedRids { get ; set ; } = new List < string > ( ) ;
311-
312- /// <summary>
313- /// RIDs that will be excluded from the installation.
314- /// </summary>
315- public List < string > ExcludedRids { get ; set ; } = new List < string > ( ) ;
316-
317- /// <summary>
318- /// Number of non-runtime entries in the package.
319- /// </summary>
320- public int NonRuntimeEntriesCount { get ; set ; }
321-
322- /// <summary>
323- /// Total size of non-runtime entries in bytes.
324- /// </summary>
325- public long NonRuntimeEntriesSize { get ; set ; }
326-
327- /// <summary>
328- /// Number of runtime entries that will be included.
329- /// </summary>
330- public int IncludedRuntimeEntriesCount { get ; set ; }
331-
332- /// <summary>
333- /// Total size of included runtime entries in bytes.
334- /// </summary>
335- public long IncludedRuntimeEntriesSize { get ; set ; }
336-
337- /// <summary>
338- /// Number of runtime entries that will be excluded.
339- /// </summary>
340- public int ExcludedRuntimeEntriesCount { get ; set ; }
341-
342- /// <summary>
343- /// Total size of excluded runtime entries in bytes.
344- /// </summary>
345- public long ExcludedRuntimeEntriesSize { get ; set ; }
346-
347- /// <summary>
348- /// Total size of all entries in the package in bytes.
349- /// </summary>
350- public long TotalPackageSize => NonRuntimeEntriesSize + IncludedRuntimeEntriesSize + ExcludedRuntimeEntriesSize ;
351-
352- /// <summary>
353- /// Total size that will be installed in bytes.
354- /// </summary>
355- public long InstalledSize => NonRuntimeEntriesSize + IncludedRuntimeEntriesSize ;
356-
357- /// <summary>
358- /// Total size that will be saved by filtering in bytes.
359- /// </summary>
360- public long SavedSize => ExcludedRuntimeEntriesSize ;
361-
362- /// <summary>
363- /// Percentage of space saved by filtering.
364- /// </summary>
365- public double SavedPercentage => TotalPackageSize > 0
366- ? ( double ) SavedSize / TotalPackageSize * 100
367- : 0 ;
368-
369- /// <summary>
370- /// Returns a human-readable summary of the filtering statistics.
371- /// </summary>
372- public override string ToString ( )
373- {
374- return $ "Current RID: { CurrentRid } \n " +
375- $ "Compatible RIDs: { string . Join ( ", " , CompatibleRids ) } \n " +
376- $ "Included RIDs: { string . Join ( ", " , IncludedRids ) } \n " +
377- $ "Excluded RIDs: { string . Join ( ", " , ExcludedRids ) } \n " +
378- $ "Non-runtime files: { NonRuntimeEntriesCount } ({ FormatBytes ( NonRuntimeEntriesSize ) } )\n " +
379- $ "Included runtime files: { IncludedRuntimeEntriesCount } ({ FormatBytes ( IncludedRuntimeEntriesSize ) } )\n " +
380- $ "Excluded runtime files: { ExcludedRuntimeEntriesCount } ({ FormatBytes ( ExcludedRuntimeEntriesSize ) } )\n " +
381- $ "Total package size: { FormatBytes ( TotalPackageSize ) } \n " +
382- $ "Installed size: { FormatBytes ( InstalledSize ) } \n " +
383- $ "Space saved: { FormatBytes ( SavedSize ) } ({ SavedPercentage : F1} %)";
384- }
385-
386- private static string FormatBytes ( long bytes )
387- {
388- string [ ] suffixes = { "B" , "KB" , "MB" , "GB" } ;
389- int suffixIndex = 0 ;
390- double size = bytes ;
391-
392- while ( size >= 1024 && suffixIndex < suffixes . Length - 1 )
393- {
394- size /= 1024 ;
395- suffixIndex ++ ;
396- }
397-
398- return $ "{ size : F2} { suffixes [ suffixIndex ] } ";
399- }
400- }
401180}
0 commit comments