diff --git a/VFS/BasicFileRedirectingManager.cs b/VFS/BasicFileRedirectingManager.cs index 9083317..0caed0b 100644 --- a/VFS/BasicFileRedirectingManager.cs +++ b/VFS/BasicFileRedirectingManager.cs @@ -54,10 +54,10 @@ public void Load() { var queryFile = SanitizePath(name); // Debug Logging - // _logger.Trace($"CreateFileA {name} ({queryFile}) => {_fileMap.ContainsKey(queryFile)}"); - //if (_fileMap.ContainsKey(queryFile)) _logger.Trace($"{queryFile} redirected to {_fileMap[queryFile]}"); - //if (!_fileMap.ContainsKey(queryFile)) _logger.Trace($"{queryFile} could not be redirected"); - var fileName = _fileMap.ContainsKey(queryFile) ? _fileMap[queryFile] : name; + //_logger.Trace($"CreateFileA {name} ({queryFile}) => {_fileMap.ContainsKey(queryFile)}"); + // if (_fileMap.ContainsKey(queryFile)) _logger.Trace($"{queryFile} redirected to {_fileMap[queryFile]}"); + // if (!_fileMap.ContainsKey(queryFile)) _logger.Trace($"{queryFile} could not be redirected"); + var fileName = _fileMap.TryGetValue(queryFile, out var value) ? value : name; return _createFileHook.Original(fileName, access, mode,attributes, disposition, andAttributes, file); }, this); @@ -76,7 +76,7 @@ public void Load() // Games like Test Drive Unlimited (2006) are abusing FindFirstFile with an explicit file name to // get all file attributes, such as the file size. var queryFile = SanitizePath(name); - var fileName = _fileMap.ContainsKey(queryFile) ? _fileMap[queryFile] : name; + var fileName = _fileMap.TryGetValue(queryFile, out var value) ? value : name; return _findFirstFileHook.Original(fileName, data); }, this); @@ -128,7 +128,7 @@ public void ClearMappings() ///
/// This method should NOT be called by Mods, only by the modding framework.
/// This is because conflicts cannot be handled and would overwrite each-other.
- /// Instead the Framework should handle this gracefully and use a priority value + /// Instead, the Framework should handle this gracefully and use a priority value /// or ask the user via the Host Application on a per-file basis. /// /// The path the target application searches for @@ -149,7 +149,7 @@ public void AddMapping(string sourcePath, string destPath) public string? QueryMapping(string sourcePath) { var queryFile = SanitizePath(sourcePath); - return _fileMap.ContainsKey(queryFile) ? _fileMap[queryFile] : null; + return _fileMap.TryGetValue(queryFile, out var value) ? value : null; } #nullable restore }