0.2.0-dev Download ZIP
50 lines ·1.5 KB Raw
| 1 | using EvilEngine.Mounts; |
| 2 | |
| 3 | namespace EvilEngine.Adapters.Unreal; |
| 4 | |
| 5 | public sealed class IoStoreContainer : IIndexedContainer |
| 6 | { |
| 7 | public string Id => "unreal.iostore"; |
| 8 | |
| 9 | public bool Recognises(IFileSource parent, VirtualPath path) |
| 10 | { |
| 11 | if (!path.Extension.Equals("utoc", StringComparison.OrdinalIgnoreCase) || |
| 12 | !parent.TryOpenAccess(path, out var access)) |
| 13 | return false; |
| 14 | using (access) |
| 15 | { |
| 16 | return IoStoreToc.Recognises(access); |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | public byte[] ReadIndex(IFileSource parent, VirtualPath path) |
| 21 | { |
| 22 | return parent.ReadAllBytes(path); |
| 23 | } |
| 24 | |
| 25 | public IFileSource Open(IFileSource parent, VirtualPath path) |
| 26 | { |
| 27 | return OpenStore(parent, path); |
| 28 | } |
| 29 | |
| 30 | public static VirtualPath DataPath(VirtualPath toc, int partition) |
| 31 | { |
| 32 | var stem = toc.WithoutExtension; |
| 33 | return partition == 0 ? $"{stem.Value}.ucas" : $"{stem.Value}_s{partition}.ucas"; |
| 34 | } |
| 35 | |
| 36 | public static IoStoreSource OpenStore(IFileSource parent, VirtualPath path) |
| 37 | { |
| 38 | var location = $"{parent.Location}/{path}"; |
| 39 | IoStoreToc toc; |
| 40 | using (var access = parent.OpenAccess(path)) |
| 41 | { |
| 42 | toc = IoStoreToc.Read(access, location); |
| 43 | } |
| 44 | |
| 45 | for (var i = 0; i < toc.Partitions; i++) |
| 46 | if (!parent.Exists(DataPath(path, i))) |
| 47 | throw new MountException($"'{location}' needs {DataPath(path, i)} beside it, which isn't there."); |
| 48 | return new IoStoreSource(location, toc, partition => parent.OpenAccess(DataPath(path, partition))); |
| 49 | } |
| 50 | } |