~ruther/NosSmooth

ref: fcd0751c2f76ffee45134260ce9d7c0bddf837d2 NosSmooth/Data/NosSmooth.Data.NOSFiles/Files/FileArchive.cs -rw-r--r-- 967 bytes
fcd0751c — František Boháček Merge pull request #22 from Rutherther/data 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
//  FileArchive.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Remora.Results;

namespace NosSmooth.Data.NOSFiles.Files;

/// <summary>
/// An archive of files.
/// </summary>
/// <param name="Files">The files in the archive.</param>
public record FileArchive(IReadOnlyList<RawFile> Files)
{
    /// <summary>
    /// Try to find the given file.
    /// </summary>
    /// <param name="name">The name of the file.</param>
    /// <returns>A file or an error.</returns>
    public Result<RawFile> FindFile(string name)
    {
        var foundFile = Files.OfType<RawFile?>().FirstOrDefault
            (x => Path.GetFileName(((RawFile)x!).Path) == name, null);
        if (foundFile is null)
        {
            return new NotFoundError($"Could not find file {name} in archive.");
        }

        return (RawFile)foundFile;
    }
}
Do not follow this link