// Copyright Epic Games, Inc. All Rights Reserved. using HordeServer.Users; namespace HordeServer.Configuration { /// /// Accessor for a specific revision of a config file. Provides metadata about the current revision, and allows reading its data. /// public interface IConfigFile { /// /// URI of the config file /// Uri Uri { get; } /// /// String used to identify a specific version of the config data. Used for ordinal comparisons, otherwise opaque. /// string Revision { get; } /// /// Author of this revision, if known /// IUser? Author { get; } /// /// Reads data for the config file /// /// Cancellation token for the operation /// UTF-8 encoded data for the config file ValueTask> ReadAsync(CancellationToken cancellationToken); } /// /// Extension methods for config files /// public static class ConfigFileExtensions { /// /// Formats a the URI for a config file in a format that is more readable for users /// /// Config file to get a path for public static string GetUserFormattedPath(this IConfigFile file) { const string DefaultPerforcePrefix = "perforce://default//"; string path = file.Uri.ToString(); if (path.StartsWith(DefaultPerforcePrefix, StringComparison.OrdinalIgnoreCase)) { path = path.Substring(DefaultPerforcePrefix.Length - 2); } if (!String.IsNullOrEmpty(file.Revision)) { path = $"{path}@{file.Revision}"; } return path; } } }