Tanoda
FilePickerExternalDataMapper.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using TriLibCore.SFB;
5using TriLibCore.Utils;
6
7namespace TriLibCore.Mappers
8{
10 public class FilePickerExternalDataMapper : ExternalDataMapper
11 {
13 public override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)
14 {
15 if (!string.IsNullOrEmpty(originalFilename))
16 if (assetLoaderContext.CustomData is IEnumerable<ItemWithStream> itemsWithStream)
17 {
18 var shortFileName = FileUtils.GetShortFilename(originalFilename).ToLowerInvariant();
19 foreach (var itemWithStream in itemsWithStream)
20 {
21 if (!itemWithStream.HasData) continue;
22
23 var checkingFileShortName = FileUtils.GetShortFilename(itemWithStream.Name).ToLowerInvariant();
24 if (shortFileName == checkingFileShortName)
25 {
26 finalPath = itemWithStream.Name;
27 return itemWithStream.OpenStream();
28 }
29 }
30 }
31 else
32 {
33 throw new Exception("Missing custom context data.");
34 }
35
36 finalPath = null;
37 return null;
38 }
39 }
40}
Represents a class used to load external data from a series of selected files.
override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)