remove boilerplate code, change to concurrent dict
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| using System; | using System; | ||||||
| using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||||
|  | using System.Collections.Generic; | ||||||
| using System.IO; | using System.IO; | ||||||
| using System.Linq; | using System.Linq; | ||||||
| using System.Threading; | using System.Threading; | ||||||
| @@ -203,13 +204,13 @@ public class PeriodicFileScanner : IDisposable | |||||||
|         Logger.Debug("Getting files from " + penumbraDir + " and " + _pluginConfiguration.CacheFolder); |         Logger.Debug("Getting files from " + penumbraDir + " and " + _pluginConfiguration.CacheFolder); | ||||||
|         string[] ext = { ".mdl", ".tex", ".mtrl", ".tmb", ".pap", ".avfx", ".atex", ".sklb", ".eid", ".phyb", ".scd", ".skp" }; |         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()) |                             .Select(s => s.ToLowerInvariant()) | ||||||
|                             .Where(f => ext.Any(e => f.EndsWith(e)) && !f.Contains(@"\bg\") && !f.Contains(@"\bgcommon\") && !f.Contains(@"\ui\")) |                             .Where(f => ext.Any(e => f.EndsWith(e)) && !f.Contains(@"\bg\") && !f.Contains(@"\bgcommon\") && !f.Contains(@"\ui\")) | ||||||
|                             .Concat(Directory.EnumerateFiles(_pluginConfiguration.CacheFolder, "*.*", SearchOption.TopDirectoryOnly) |                             .Concat(Directory.EnumerateFiles(_pluginConfiguration.CacheFolder, "*.*", SearchOption.TopDirectoryOnly) | ||||||
|                                 .Where(f => new FileInfo(f).Name.Length == 40) |                                 .Where(f => new FileInfo(f).Name.Length == 40) | ||||||
|                                 .Select(s => s.ToLowerInvariant()).ToList()) |                                 .Select(s => s.ToLowerInvariant()).ToList()) | ||||||
|                             .ToDictionary(c => c, c => false); |                             .Select(c => new KeyValuePair<string, bool>(c, false))); | ||||||
|  |  | ||||||
|         TotalFiles = scannedFiles.Count; |         TotalFiles = scannedFiles.Count; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -37,8 +37,6 @@ public class OnlinePlayerManager : IDisposable | |||||||
|         _fileDbManager = fileDbManager; |         _fileDbManager = fileDbManager; | ||||||
|         _apiController.PairedClientOnline += ApiControllerOnPairedClientOnline; |         _apiController.PairedClientOnline += ApiControllerOnPairedClientOnline; | ||||||
|         _apiController.PairedClientOffline += ApiControllerOnPairedClientOffline; |         _apiController.PairedClientOffline += ApiControllerOnPairedClientOffline; | ||||||
|         _apiController.PairedWithOther += ApiControllerOnPairedWithOther; |  | ||||||
|         _apiController.UnpairedFromOther += ApiControllerOnUnpairedFromOther; |  | ||||||
|         _apiController.Connected += ApiControllerOnConnected; |         _apiController.Connected += ApiControllerOnConnected; | ||||||
|         _apiController.Disconnected += ApiControllerOnDisconnected; |         _apiController.Disconnected += ApiControllerOnDisconnected; | ||||||
|         _apiController.CharacterReceived += ApiControllerOnCharacterReceived; |         _apiController.CharacterReceived += ApiControllerOnCharacterReceived; | ||||||
| @@ -137,8 +135,6 @@ public class OnlinePlayerManager : IDisposable | |||||||
|  |  | ||||||
|         _apiController.PairedClientOnline -= ApiControllerOnPairedClientOnline; |         _apiController.PairedClientOnline -= ApiControllerOnPairedClientOnline; | ||||||
|         _apiController.PairedClientOffline -= ApiControllerOnPairedClientOffline; |         _apiController.PairedClientOffline -= ApiControllerOnPairedClientOffline; | ||||||
|         _apiController.PairedWithOther -= ApiControllerOnPairedWithOther; |  | ||||||
|         _apiController.UnpairedFromOther -= ApiControllerOnUnpairedFromOther; |  | ||||||
|         _apiController.Disconnected -= ApiControllerOnDisconnected; |         _apiController.Disconnected -= ApiControllerOnDisconnected; | ||||||
|         _apiController.Connected -= ApiControllerOnConnected; |         _apiController.Connected -= ApiControllerOnConnected; | ||||||
|  |  | ||||||
| @@ -169,20 +165,6 @@ public class OnlinePlayerManager : IDisposable | |||||||
|         return; |         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) |     private void AddPlayer(string characterNameHash) | ||||||
|     { |     { | ||||||
|         if (_onlineCachedPlayers.TryGetValue(characterNameHash, out var cachedPlayer)) |         if (_onlineCachedPlayers.TryGetValue(characterNameHash, out var cachedPlayer)) | ||||||
|   | |||||||
| @@ -80,10 +80,6 @@ public partial class ApiController : IDisposable | |||||||
|     public event SimpleStringDelegate? PairedClientOffline; |     public event SimpleStringDelegate? PairedClientOffline; | ||||||
|  |  | ||||||
|     public event SimpleStringDelegate? PairedClientOnline; |     public event SimpleStringDelegate? PairedClientOnline; | ||||||
|  |  | ||||||
|     public event SimpleStringDelegate? PairedWithOther; |  | ||||||
|  |  | ||||||
|     public event SimpleStringDelegate? UnpairedFromOther; |  | ||||||
|     public event VoidDelegate? DownloadStarted; |     public event VoidDelegate? DownloadStarted; | ||||||
|     public event VoidDelegate? DownloadFinished; |     public event VoidDelegate? DownloadFinished; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stanley Dimant
					Stanley Dimant