remove boilerplate code, change to concurrent dict

This commit is contained in:
Stanley Dimant
2022-10-02 01:25:02 +02:00
parent fb7943cdcd
commit a2d884718a
3 changed files with 3 additions and 24 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
@@ -203,13 +204,13 @@ public class PeriodicFileScanner : IDisposable
Logger.Debug("Getting files from " + penumbraDir + " and " + _pluginConfiguration.CacheFolder);
string[] ext = { ".mdl", ".tex", ".mtrl", ".tmb", ".pap", ".avfx", ".atex", ".sklb", ".eid", ".phyb", ".scd", ".skp" };
var scannedFiles = Directory.EnumerateFiles(penumbraDir, "*.*", SearchOption.AllDirectories)
var scannedFiles = new ConcurrentDictionary<string, bool>(Directory.EnumerateFiles(penumbraDir, "*.*", SearchOption.AllDirectories)
.Select(s => s.ToLowerInvariant())
.Where(f => ext.Any(e => f.EndsWith(e)) && !f.Contains(@"\bg\") && !f.Contains(@"\bgcommon\") && !f.Contains(@"\ui\"))
.Concat(Directory.EnumerateFiles(_pluginConfiguration.CacheFolder, "*.*", SearchOption.TopDirectoryOnly)
.Where(f => new FileInfo(f).Name.Length == 40)
.Select(s => s.ToLowerInvariant()).ToList())
.ToDictionary(c => c, c => false);
.Select(c => new KeyValuePair<string, bool>(c, false)));
TotalFiles = scannedFiles.Count;

View File

@@ -37,8 +37,6 @@ public class OnlinePlayerManager : IDisposable
_fileDbManager = fileDbManager;
_apiController.PairedClientOnline += ApiControllerOnPairedClientOnline;
_apiController.PairedClientOffline += ApiControllerOnPairedClientOffline;
_apiController.PairedWithOther += ApiControllerOnPairedWithOther;
_apiController.UnpairedFromOther += ApiControllerOnUnpairedFromOther;
_apiController.Connected += ApiControllerOnConnected;
_apiController.Disconnected += ApiControllerOnDisconnected;
_apiController.CharacterReceived += ApiControllerOnCharacterReceived;
@@ -137,8 +135,6 @@ public class OnlinePlayerManager : IDisposable
_apiController.PairedClientOnline -= ApiControllerOnPairedClientOnline;
_apiController.PairedClientOffline -= ApiControllerOnPairedClientOffline;
_apiController.PairedWithOther -= ApiControllerOnPairedWithOther;
_apiController.UnpairedFromOther -= ApiControllerOnUnpairedFromOther;
_apiController.Disconnected -= ApiControllerOnDisconnected;
_apiController.Connected -= ApiControllerOnConnected;
@@ -169,20 +165,6 @@ public class OnlinePlayerManager : IDisposable
return;
}
private void ApiControllerOnPairedWithOther(string charHash)
{
if (string.IsNullOrEmpty(charHash)) return;
Logger.Debug("Pairing with " + charHash);
AddPlayer(charHash);
}
private void ApiControllerOnUnpairedFromOther(string? characterHash)
{
if (string.IsNullOrEmpty(characterHash)) return;
Logger.Debug("Unpairing from " + characterHash);
RemovePlayer(characterHash);
}
private void AddPlayer(string characterNameHash)
{
if (_onlineCachedPlayers.TryGetValue(characterNameHash, out var cachedPlayer))

View File

@@ -80,10 +80,6 @@ public partial class ApiController : IDisposable
public event SimpleStringDelegate? PairedClientOffline;
public event SimpleStringDelegate? PairedClientOnline;
public event SimpleStringDelegate? PairedWithOther;
public event SimpleStringDelegate? UnpairedFromOther;
public event VoidDelegate? DownloadStarted;
public event VoidDelegate? DownloadFinished;