From 2b5037e43a50652c58203c7b277fcb738347d52c Mon Sep 17 00:00:00 2001 From: AnimatedSwine37 <24914353+AnimatedSwine37@users.noreply.github.com> Date: Sun, 20 Apr 2025 19:26:26 +1000 Subject: [PATCH] Directly index concurrent dictionaries instead of using TryAdd --- Emulator/BF.File.Emulator/BfEmulator.cs | 4 ++-- Emulator/BMD.File.Emulator/BmdEmulator.cs | 4 ++-- Emulator/PAK.Stream.Emulator/PakEmulator.cs | 2 +- Emulator/SPD.File.Emulator/SpdEmulator.cs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Emulator/BF.File.Emulator/BfEmulator.cs b/Emulator/BF.File.Emulator/BfEmulator.cs index 63ed7c6..98e170f 100644 --- a/Emulator/BF.File.Emulator/BfEmulator.cs +++ b/Emulator/BF.File.Emulator/BfEmulator.cs @@ -116,7 +116,7 @@ public bool TryCreateEmulatedFile(IntPtr handle, string srcDataPath, string outp return false; stream = emulatedBf.Stream; - _pathToEmulated.TryAdd(outputPath, emulatedBf); + _pathToEmulated[outputPath] = emulatedBf; emulated = new EmulatedFile(stream, emulatedBf.LastWriteTime); _log.Info("[BfEmulator] Created Emulated file with Path {0} and Last Write {1}", outputPath, emulatedBf.LastWriteTime); @@ -150,7 +150,7 @@ public void UnregisterFile(string bfPath) public void RegisterFile(string destinationPath, Stream stream, DateTime lastWriteTime) { - _pathToEmulated.TryAdd(destinationPath, new EmulatedBf(stream, new List(), lastWriteTime)); + _pathToEmulated[destinationPath] = new EmulatedBf(stream, new List(), lastWriteTime); } private void DumpFile(string route, Stream stream) diff --git a/Emulator/BMD.File.Emulator/BmdEmulator.cs b/Emulator/BMD.File.Emulator/BmdEmulator.cs index b3bd782..767d543 100644 --- a/Emulator/BMD.File.Emulator/BmdEmulator.cs +++ b/Emulator/BMD.File.Emulator/BmdEmulator.cs @@ -115,7 +115,7 @@ public bool TryCreateEmulatedFile(IntPtr handle, string srcDataPath, string outp return false; stream = emulatedBmd.Stream; - _pathToEmulated.TryAdd(outputPath, emulatedBmd); + _pathToEmulated[outputPath] = emulatedBmd; emulated = new EmulatedFile(stream, emulatedBmd.LastWriteTime); _log.Info("[BmdEmulator] Created Emulated file with Path {0} and Last Write {1}", outputPath, emulatedBmd.LastWriteTime); @@ -149,7 +149,7 @@ public void UnregisterFile(string bmdPath) public void RegisterFile(string destinationPath, Stream stream, DateTime lastWriteTime) { - _pathToEmulated.TryAdd(destinationPath, new EmulatedBmd(stream, new List(), lastWriteTime)); + _pathToEmulated[destinationPath] = new EmulatedBmd(stream, new List(), lastWriteTime); } private void DumpFile(string route, Stream stream) diff --git a/Emulator/PAK.Stream.Emulator/PakEmulator.cs b/Emulator/PAK.Stream.Emulator/PakEmulator.cs index 2d6fe00..f4ac76a 100644 --- a/Emulator/PAK.Stream.Emulator/PakEmulator.cs +++ b/Emulator/PAK.Stream.Emulator/PakEmulator.cs @@ -83,7 +83,7 @@ public bool TryCreateEmulatedFile(IntPtr handle, string srcDataPath, string outp stream = builder!.Build(handle, srcDataPath); - _pathToStream.TryAdd(outputPath, stream); + _pathToStream[outputPath] = stream; emulated = new EmulatedFile(stream); _log.Info("[PakEmulator] Created Emulated file with Path {0}", outputPath); diff --git a/Emulator/SPD.File.Emulator/SpdEmulator.cs b/Emulator/SPD.File.Emulator/SpdEmulator.cs index 14b2c36..6355ecf 100644 --- a/Emulator/SPD.File.Emulator/SpdEmulator.cs +++ b/Emulator/SPD.File.Emulator/SpdEmulator.cs @@ -79,7 +79,7 @@ public bool TryCreateEmulatedFile(IntPtr handle, string srcDataPath, string outp _pathToStream[outputPath] = null; // Avoid recursion into same file. stream = builder!.Build(srcDataPath, _log); - _pathToStream.TryAdd(outputPath, stream); + _pathToStream[outputPath] = stream; emulated = new EmulatedFile(stream); _log.Info("[SpdEmulator] Created Emulated file with Path {0}", outputPath); @@ -123,7 +123,7 @@ public void UnregisterFile(string spdPath) public void RegisterFile(string destinationPath, Stream stream) { - _pathToStream.TryAdd(destinationPath, stream); + _pathToStream[destinationPath] = stream; } internal List GetInput() => _builderFactory.RouteGroupTuples;