Files
UnrealEngineUWP/Engine/Source/Programs/Shared/EpicGames.Perforce.Managed/StreamSnapshot.cs
joe kirchoff 358a7b5ea5 [Backout] - CL20565613
#fyi joe.kirchoff
Original CL Desc
-----------------------------------------------------------------
EpicGames.Perforce*: net6.0 upgrade

#rnx
#rb none
#preflight 62a117e03f024e3f240489d9

[CL 20583327 by joe kirchoff in ue5-main branch]
2022-06-09 15:38:08 -04:00

61 lines
1.6 KiB
C#

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