forked from aly/qstbak
muffin v7.5.6
This commit is contained in:
parent
6266f9e6b7
commit
addf2d530f
619 changed files with 264792 additions and 446022 deletions
|
|
@ -1,148 +1,78 @@
|
|||
#define RELEASE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Dalamud.Plugin;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Questionable.Model.Questing;
|
||||
using Questionable.SeasonalDutyPaths;
|
||||
using Questionable.Windows.QuestComponents;
|
||||
using Questionable.Validation;
|
||||
using Questionable.Validation.Validators;
|
||||
|
||||
namespace Questionable.Controller;
|
||||
|
||||
internal sealed class SeasonalDutyDefinitionRegistry
|
||||
internal sealed class SeasonalDutyDefinitionRegistry : DefinitionRegistry<SeasonalDutyDefinition>
|
||||
{
|
||||
private readonly IDalamudPluginInterface _pluginInterface;
|
||||
|
||||
private readonly ILogger<SeasonalDutyDefinitionRegistry> _logger;
|
||||
|
||||
private readonly Dictionary<ushort, SeasonalDutyDefinition> _definitions = new Dictionary<ushort, SeasonalDutyDefinition>();
|
||||
|
||||
public IReadOnlyDictionary<ushort, SeasonalDutyDefinition> Definitions => _definitions;
|
||||
|
||||
public SeasonalDutyDefinitionRegistry(IDalamudPluginInterface pluginInterface, ILogger<SeasonalDutyDefinitionRegistry> logger)
|
||||
protected override string TypeLabel
|
||||
{
|
||||
_pluginInterface = pluginInterface;
|
||||
_logger = logger;
|
||||
Reload();
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
_definitions.Clear();
|
||||
LoadFromAssembly();
|
||||
try
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
LoadFromDirectory(new DirectoryInfo(Path.Combine(_pluginInterface.ConfigDirectory.FullName, "SeasonalDutyDefinitions")));
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.LogError(exception, "Failed to load seasonal duty definitions from user directory (some may have been successfully loaded)");
|
||||
}
|
||||
RemoveExpiredDefinitions();
|
||||
_logger.LogInformation("Loaded {Count} seasonal duty definitions in total", _definitions.Count);
|
||||
}
|
||||
|
||||
[Conditional("RELEASE")]
|
||||
private void LoadFromAssembly()
|
||||
{
|
||||
_logger.LogInformation("Loading seasonal duty definitions from assembly");
|
||||
IReadOnlyDictionary<ushort, SeasonalDutyDefinition> definitions = AssemblySeasonalDutyDefinitionLoader.GetDefinitions();
|
||||
_logger.LogInformation("AssemblySeasonalDutyDefinitionLoader returned {Count} definitions", definitions.Count);
|
||||
foreach (var (key, value) in definitions)
|
||||
{
|
||||
_definitions[key] = value;
|
||||
}
|
||||
_logger.LogInformation("Loaded {Count} seasonal duty definitions from assembly", _definitions.Count);
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void LoadFromProjectDirectory()
|
||||
{
|
||||
DirectoryInfo directoryInfo = _pluginInterface.AssemblyLocation.Directory?.Parent?.Parent;
|
||||
if (directoryInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DirectoryInfo directoryInfo2 = new DirectoryInfo(Path.Combine(directoryInfo.FullName, "SeasonalDutyPaths"));
|
||||
if (directoryInfo2.Exists)
|
||||
{
|
||||
try
|
||||
{
|
||||
LoadFromDirectory(directoryInfo2);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_definitions.Clear();
|
||||
_logger.LogError(exception, "Failed to load seasonal duty definitions from project directory");
|
||||
}
|
||||
return global::_003CModule_003E._202A_206B_206D_200C_206B_200E_200E_202A_200B_202E_206A_206F_206A_206B_200E_200D_200F_206D_206E_206A_206F_200C_206C_202C_202A_206E_202C_200B_206E_202A_206E_202B_206B_202E_202E_206A_206D_206D_202C_200F_202E<string>(-1124229794);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadFromDirectory(DirectoryInfo directory)
|
||||
protected override string ConfigDirectoryName
|
||||
{
|
||||
if (!directory.Exists)
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
_logger.LogInformation("Not loading seasonal duty definitions from {DirectoryName} (doesn't exist)", directory);
|
||||
return;
|
||||
}
|
||||
FileInfo[] files = directory.GetFiles("*.json");
|
||||
foreach (FileInfo fileInfo in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
ushort? num = ExtractIdFromName(fileInfo.Name);
|
||||
if (!num.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
using FileStream utf8Json = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read);
|
||||
SeasonalDutyDefinition seasonalDutyDefinition = JsonSerializer.Deserialize<SeasonalDutyDefinition>(utf8Json);
|
||||
if (seasonalDutyDefinition != null)
|
||||
{
|
||||
_definitions[num.Value] = seasonalDutyDefinition;
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.LogError(exception, "Unable to load seasonal duty definition file {FileName}", fileInfo.FullName);
|
||||
}
|
||||
return global::_003CModule_003E._202E_206C_200F_206B_206A_202A_202C_206F_200C_206C_202B_206B_206D_206D_206D_202D_206E_202E_206C_206E_206D_202C_206F_200D_202D_202E_206A_206D_202A_206A_202B_200D_200C_206D_202B_200B_200D_200C_206E_206B_202E<string>(393634060);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveExpiredDefinitions()
|
||||
protected override string ProjectDirectoryName
|
||||
{
|
||||
foreach (ushort item in (from kvp in _definitions.Where<KeyValuePair<ushort, SeasonalDutyDefinition>>(delegate(KeyValuePair<ushort, SeasonalDutyDefinition> kvp)
|
||||
{
|
||||
DateTime? eventExpiry = kvp.Value.EventExpiry;
|
||||
if (eventExpiry.HasValue)
|
||||
{
|
||||
DateTime valueOrDefault = eventExpiry.GetValueOrDefault();
|
||||
return EventInfoComponent.NormalizeExpiry(valueOrDefault) < DateTime.UtcNow;
|
||||
}
|
||||
return false;
|
||||
})
|
||||
select kvp.Key).ToList())
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
_logger.LogInformation("Removing expired seasonal duty definition {Id} '{Name}'", item, _definitions[item].Name);
|
||||
_definitions.Remove(item);
|
||||
return global::_003CModule_003E._206C_202A_206D_206A_206E_202A_202B_206F_206D_200F_202D_200F_202D_206A_202C_202B_206D_206A_200E_200E_202D_202D_200D_200C_200D_200D_206D_206E_202A_200F_206E_206C_206D_206A_206D_202B_200F_200D_206E_200C_202E<string>(-1200839821);
|
||||
}
|
||||
}
|
||||
|
||||
private static ushort? ExtractIdFromName(string fileName)
|
||||
protected override EPathType PathType => EPathType.SeasonalDuty;
|
||||
|
||||
public SeasonalDutyDefinitionRegistry(IDalamudPluginInterface pluginInterface, SeasonalDutySchemaValidator seasonalDutySchemaValidator, QuestValidator questValidator, ILogger<SeasonalDutyDefinitionRegistry> logger)
|
||||
: base(pluginInterface, (IDefinitionSchemaValidator)seasonalDutySchemaValidator, questValidator, (ILogger)logger)
|
||||
{
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
||||
if (!fileNameWithoutExtension.Contains('_', StringComparison.Ordinal))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (ushort.TryParse(fileNameWithoutExtension.Split('_', 2)[0], out var result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override IReadOnlyDictionary<ushort, SeasonalDutyDefinition> GetAssemblyDefinitions()
|
||||
{
|
||||
return _206F_206D_202B_206C_202C_206F_206C_200C_202A_200F_200E_202E_206B_200F_206C_202E_202A_206F_202A_206D_206D_202D_200E_206F_200E_206E_206C_206D_202E_206F_202A_202B_200D_206C_202C_206B_200C_202A_206A_202E();
|
||||
}
|
||||
|
||||
protected override DateTime? GetExpiry(SeasonalDutyDefinition definition)
|
||||
{
|
||||
return _206D_206E_202D_206B_200B_202E_202E_200E_206C_202C_202C_200C_202A_202C_206E_206A_202B_206D_206E_206B_202D_200C_206C_206F_200B_202E_206F_206E_202D_202E_202B_202C_200C_206E_200D_202D_202E_200E_206B_202E(definition);
|
||||
}
|
||||
|
||||
protected override string? GetName(SeasonalDutyDefinition definition)
|
||||
{
|
||||
return _200E_202A_200E_202E_202D_206B_202D_200F_200C_206E_206F_206A_200C_202D_206A_200F_206F_202C_202C_200F_202D_206D_200E_200B_206A_200D_202A_202D_200F_200F_206A_200E_200B_200C_200B_202D_200C_200C_206D_200C_202E(definition);
|
||||
}
|
||||
|
||||
static IReadOnlyDictionary<ushort, SeasonalDutyDefinition> _206F_206D_202B_206C_202C_206F_206C_200C_202A_200F_200E_202E_206B_200F_206C_202E_202A_206F_202A_206D_206D_202D_200E_206F_200E_206E_206C_206D_202E_206F_202A_202B_200D_206C_202C_206B_200C_202A_206A_202E()
|
||||
{
|
||||
return AssemblySeasonalDutyDefinitionLoader.GetDefinitions();
|
||||
}
|
||||
|
||||
static DateTime? _206D_206E_202D_206B_200B_202E_202E_200E_206C_202C_202C_200C_202A_202C_206E_206A_202B_206D_206E_206B_202D_200C_206C_206F_200B_202E_206F_206E_202D_202E_202B_202C_200C_206E_200D_202D_202E_200E_206B_202E(SeasonalDutyDefinition P_0)
|
||||
{
|
||||
return P_0.EventExpiry;
|
||||
}
|
||||
|
||||
static string _200E_202A_200E_202E_202D_206B_202D_200F_200C_206E_206F_206A_200C_202D_206A_200F_206F_202C_202C_200F_202D_206D_200E_200B_206A_200D_202A_202D_200F_200F_206A_200E_200B_200C_200B_202D_200C_200C_206D_200C_202E(SeasonalDutyDefinition P_0)
|
||||
{
|
||||
return P_0.Name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue