45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Threading;
|
|
using Questionable.Model.IO;
|
|
using Questionable.Model.Questing;
|
|
|
|
namespace Questionable.QuestPaths;
|
|
|
|
internal static class AssemblyQuestLoader
|
|
{
|
|
private static readonly Lazy<IReadOnlyDictionary<ElementId, QuestRoot>> Quests = new Lazy<IReadOnlyDictionary<ElementId, QuestRoot>>(LoadQuests, LazyThreadSafetyMode.ExecutionAndPublication);
|
|
|
|
internal static TimeSpan? DecodeDuration { get; private set; }
|
|
|
|
internal static Stream QuestSchema => typeof(AssemblyQuestLoader).Assembly.GetManifestResourceStream("Questionable.QuestPaths.QuestSchema");
|
|
|
|
internal static IReadOnlyDictionary<ElementId, QuestRoot> GetQuests()
|
|
{
|
|
return Quests.Value;
|
|
}
|
|
|
|
internal static string? GetQuestPath(ElementId questId)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
private static IReadOnlyDictionary<ElementId, QuestRoot> LoadQuests()
|
|
{
|
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
|
using Stream stream = typeof(AssemblyQuestLoader).Assembly.GetManifestResourceStream("Questionable.QuestPaths.QuestBundle");
|
|
byte[] array = PathBundleSecret.Key();
|
|
List<KeyValuePair<string, QuestRoot>> list = PathBundle.Deserialize<QuestRoot>(stream, array);
|
|
CryptographicOperations.ZeroMemory(array);
|
|
Dictionary<ElementId, QuestRoot> dictionary = new Dictionary<ElementId, QuestRoot>(list.Count);
|
|
foreach (var (value, value2) in list)
|
|
{
|
|
dictionary[ElementId.FromString(value)] = value2;
|
|
}
|
|
DecodeDuration = stopwatch.Elapsed;
|
|
return dictionary;
|
|
}
|
|
}
|