41 lines
1.7 KiB
C#
41 lines
1.7 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.IO;
|
|
using Questionable.Model.Questing;
|
|
|
|
namespace Questionable.SeasonalDutyPaths;
|
|
|
|
internal static class AssemblySeasonalDutyDefinitionLoader
|
|
{
|
|
private static readonly Lazy<IReadOnlyDictionary<ushort, SeasonalDutyDefinition>> Definitions = new Lazy<IReadOnlyDictionary<ushort, SeasonalDutyDefinition>>(LoadDefinitions, LazyThreadSafetyMode.ExecutionAndPublication);
|
|
|
|
internal static TimeSpan? DecodeDuration { get; private set; }
|
|
|
|
internal static Stream SeasonalDutyDefinitionSchema => typeof(AssemblySeasonalDutyDefinitionLoader).Assembly.GetManifestResourceStream("Questionable.SeasonalDutyPaths.SeasonalDutyDefinitionSchema");
|
|
|
|
internal static IReadOnlyDictionary<ushort, SeasonalDutyDefinition> GetDefinitions()
|
|
{
|
|
return Definitions.Value;
|
|
}
|
|
|
|
private static IReadOnlyDictionary<ushort, SeasonalDutyDefinition> LoadDefinitions()
|
|
{
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
using Stream stream = typeof(AssemblySeasonalDutyDefinitionLoader).Assembly.GetManifestResourceStream("Questionable.SeasonalDutyPaths.SeasonalDutyBundle");
|
|
byte[] array = PathBundleSecret.Key();
|
|
List<KeyValuePair<string, SeasonalDutyDefinition>> list = PathBundle.Deserialize<SeasonalDutyDefinition>(stream, array);
|
|
CryptographicOperations.ZeroMemory(array);
|
|
Dictionary<ushort, SeasonalDutyDefinition> dictionary = new Dictionary<ushort, SeasonalDutyDefinition>(list.Count);
|
|
foreach (var (s, value) in list)
|
|
{
|
|
dictionary[ushort.Parse(s, CultureInfo.InvariantCulture)] = value;
|
|
}
|
|
DecodeDuration = stopwatch.Elapsed;
|
|
return dictionary;
|
|
}
|
|
}
|