Tanoda
ZipFileExternalDataMapper.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using ICSharpCode.SharpZipLib.Zip;
4using TriLibCore.Utils;
5
6namespace TriLibCore.Mappers
7{
9 public class ZipFileExternalDataMapper : ExternalDataMapper
10 {
12 public override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)
13 {
14 if (!(assetLoaderContext.CustomData is ZipLoadCustomContextData zipLoadCustomContextData))
15 {
16 throw new Exception("Missing custom context data.");
17 }
18 var zipFile = zipLoadCustomContextData.ZipFile;
19 if (zipFile == null)
20 {
21 throw new Exception("Zip file instance is null.");
22 }
23 var shortFileName = FileUtils.GetShortFilename(originalFilename).ToLowerInvariant();
24 foreach (ZipEntry zipEntry in zipFile)
25 {
26 if (!zipEntry.IsFile)
27 {
28 continue;
29 }
30 var checkingFileShortName = FileUtils.GetShortFilename(zipEntry.Name).ToLowerInvariant();
31 if (shortFileName == checkingFileShortName)
32 {
33 finalPath = zipFile.Name;
34 string _;
35 return AssetLoaderZip.ZipFileEntryToStream(out _, zipEntry, zipFile);
36 }
37 }
38 finalPath = null;
39 return null;
40 }
41 }
42}
Represents a mapper class used to load external data from Zip files.
override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)
Represents a class passed as the custom data to the Asset Loader Context when loading Models from Zip...