41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Threading;
|
|
using Questionable.Model.Gathering;
|
|
using Questionable.Model.IO;
|
|
|
|
namespace Questionable.GatheringPaths;
|
|
|
|
internal static class AssemblyGatheringLocationLoader
|
|
{
|
|
private static readonly Lazy<IReadOnlyDictionary<ushort, GatheringRoot>> Locations = new Lazy<IReadOnlyDictionary<ushort, GatheringRoot>>(LoadLocations, LazyThreadSafetyMode.ExecutionAndPublication);
|
|
|
|
internal static TimeSpan? DecodeDuration { get; private set; }
|
|
|
|
internal static Stream GatheringSchema => typeof(AssemblyGatheringLocationLoader).Assembly.GetManifestResourceStream("Questionable.GatheringPaths.GatheringLocationSchema");
|
|
|
|
internal static IReadOnlyDictionary<ushort, GatheringRoot> GetLocations()
|
|
{
|
|
return Locations.Value;
|
|
}
|
|
|
|
private static IReadOnlyDictionary<ushort, GatheringRoot> LoadLocations()
|
|
{
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
using Stream stream = typeof(AssemblyGatheringLocationLoader).Assembly.GetManifestResourceStream("Questionable.GatheringPaths.GatheringBundle");
|
|
byte[] array = PathBundleSecret.Key();
|
|
List<KeyValuePair<string, GatheringRoot>> list = PathBundle.Deserialize<GatheringRoot>(stream, array);
|
|
CryptographicOperations.ZeroMemory(array);
|
|
Dictionary<ushort, GatheringRoot> dictionary = new Dictionary<ushort, GatheringRoot>(list.Count);
|
|
foreach (var (s, value) in list)
|
|
{
|
|
dictionary[ushort.Parse(s, CultureInfo.InvariantCulture)] = value;
|
|
}
|
|
DecodeDuration = stopwatch.Elapsed;
|
|
return dictionary;
|
|
}
|
|
}
|