Everything's a service.

This commit is contained in:
Ottermandias 2023-03-17 17:51:05 +01:00
parent 2670ba52c1
commit dd8c910597
45 changed files with 2155 additions and 2212 deletions

View file

@ -2,12 +2,13 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Penumbra.Util;
namespace Penumbra.Mods;
public sealed partial class Mod
{
public sealed partial class Manager : IReadOnlyList< Mod >
public sealed partial class Manager : IReadOnlyList<Mod>
{
// Set when reading Config and migrating from v4 to v5.
public static bool MigrateModBackups = false;
@ -16,55 +17,60 @@ public sealed partial class Mod
// Mods are added when they are created or imported.
// Mods are removed when they are deleted or when they are toggled in any collection.
// Also gets cleared on mod rediscovery.
public readonly HashSet< Mod > NewMods = new();
public readonly HashSet<Mod> NewMods = new();
private readonly List< Mod > _mods = new();
private readonly List<Mod> _mods = new();
public Mod this[ int idx ]
=> _mods[ idx ];
public Mod this[int idx]
=> _mods[idx];
public Mod this[ Index idx ]
=> _mods[ idx ];
public Mod this[Index idx]
=> _mods[idx];
public int Count
=> _mods.Count;
public IEnumerator< Mod > GetEnumerator()
public IEnumerator<Mod> GetEnumerator()
=> _mods.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator()
=> GetEnumerator();
public Manager( string modDirectory )
private readonly Configuration _config;
private readonly ChatService _chat;
public Manager(StartTracker time, Configuration config, ChatService chat)
{
using var timer = time.Measure(StartTimeType.Mods);
_config = config;
_chat = chat;
ModDirectoryChanged += OnModDirectoryChange;
SetBaseDirectory( modDirectory, true );
UpdateExportDirectory( Penumbra.Config.ExportDirectory, false );
SetBaseDirectory(config.ModDirectory, true);
UpdateExportDirectory(_config.ExportDirectory, false);
ModOptionChanged += OnModOptionChange;
ModPathChanged += OnModPathChange;
DiscoverMods();
}
// Try to obtain a mod by its directory name (unique identifier, preferred),
// or the first mod of the given name if no directory fits.
public bool TryGetMod( string modDirectory, string modName, [NotNullWhen( true )] out Mod? mod )
public bool TryGetMod(string modDirectory, string modName, [NotNullWhen(true)] out Mod? mod)
{
mod = null;
foreach( var m in _mods )
foreach (var m in _mods)
{
if( string.Equals(m.ModPath.Name, modDirectory, StringComparison.OrdinalIgnoreCase) )
if (string.Equals(m.ModPath.Name, modDirectory, StringComparison.OrdinalIgnoreCase))
{
mod = m;
return true;
}
if( m.Name == modName )
{
if (m.Name == modName)
mod ??= m;
}
}
return mod != null;
}
}
}
}