// Copyright Epic Games, Inc. All Rights Reserved. using System.Collections.Generic; namespace EpicGames.Perforce.Managed { /// /// Interface for a stream snapshot /// public abstract class StreamSnapshot { /// /// Empty snapshot instance /// public static StreamSnapshot Empty => new StreamSnapshotFromMemory(new StreamTreeBuilder()); /// /// The root digest /// public abstract StreamTreeRef Root { get; } /// /// Lookup a directory by reference /// /// The reference /// public abstract StreamTree Lookup(StreamTreeRef treeRef); } /// /// Extension methods for IStreamSnapshot /// static class StreamSnapshotExtensions { /// /// Get all the files in this directory /// /// List of files public static List GetFiles(this StreamSnapshot snapshot) { List files = new List(); AppendFiles(snapshot, snapshot.Root, files); return files; } /// /// Append the contents of this directory and subdirectories to a list /// /// /// /// List to append to static void AppendFiles(StreamSnapshot snapshot, StreamTreeRef treeRef, List files) { StreamTree directoryInfo = snapshot.Lookup(treeRef); foreach (StreamTreeRef subDirRef in directoryInfo.NameToTree.Values) { AppendFiles(snapshot, subDirRef, files); } files.AddRange(directoryInfo.NameToFile.Values); } } }