-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #920 from WolvenKit/fix/xbm-fixes
XBM Fixes
- Loading branch information
Showing
6 changed files
with
80 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Splat; | ||
using WolvenKit.Common; | ||
using WolvenKit.Common.FNV1A; | ||
using WolvenKit.RED4.Archive; | ||
using WolvenKit.RED4.CR2W.Archive; | ||
|
||
namespace WolvenKit.Functionality.Converters; | ||
|
||
public class JsonFileEntryConverter : JsonConverter<FileEntry> | ||
{ | ||
public override FileEntry Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (Locator.Current.GetService<IArchiveManager>() is not ArchiveManager archiveManager) | ||
{ | ||
throw new Exception(); | ||
} | ||
|
||
var fileHash = reader.TokenType switch | ||
{ | ||
JsonTokenType.String => FNV1A64HashAlgorithm.HashString(reader.GetString()), | ||
JsonTokenType.Number => reader.GetUInt64(), | ||
_ => throw new NotImplementedException() | ||
}; | ||
|
||
var fileEntry = archiveManager.Lookup(fileHash); | ||
if (fileEntry.HasValue) | ||
{ | ||
return (FileEntry)fileEntry.Value; | ||
} | ||
|
||
throw new FileNotFoundException(); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, FileEntry value, JsonSerializerOptions options) | ||
{ | ||
JsonSerializer.Serialize(writer, value.NameOrHash); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters