in csharp/NativeUtils/ResourceLoader.cs [332:379]
public Resource(string resourcePath, int commonNamePrefixLength, int initialOrder, ResourceLoader owner)
{
this.ResourcePath = resourcePath;
var tags = new Dictionary<String, String>();
String filename = this.Name = GetTags(resourcePath.Substring(commonNamePrefixLength), tags)
.Replace('_', '.');
this.IsZstd = filename.EndsWith(".zst");
if (IsZstd)
filename = filename.Substring(0, filename.Length - 4);
// Owner can optionally rename the resource
this.Filename = filename;
this.IsDll = filename.EndsWith(OS.DllExt);
// Parse file order tags
this.Order = initialOrder;
foreach (var kv in tags)
{
String key = kv.Key;
String value = kv.Value;
if (key.Equals("order"))
{
int order;
if (!Int32.TryParse(value, out order) || order < 0)
throw new ArgumentException(
$"Order tag invalid, non-negative integer expected: [order@{value}]");
this.Order = order + int.MinValue; // Needed to combine natural order and explicit order
}
else
throw new ArgumentException($"Invalid Tag: [{key}@{value}]");
}
// Try to open. Record resource length
using (var resourceStream = owner.ResourceAssembly.GetManifestResourceStream(resourcePath))
{
if (null == resourceStream)
throw new Exception($"Resource file not found: {resourcePath}");
long length = resourceStream.Length;
if (length > int.MaxValue)
throw new Exception($"Resource file length is too big: {length}");
this.Length = (int)length;
}
owner.ResourceAdded(this);
}