From b6245bb37c2c552b989b7f81000f658f0fd83a47 Mon Sep 17 00:00:00 2001 From: Night The Fox Date: Sun, 10 Nov 2024 19:56:17 +0100 Subject: [PATCH] adding + merging metadata --- GFS/GFS.csproj | 2 +- GFS/RevergePackage.cs | 13 ++++++++++++- GFS/RevergePackageMetadata.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/GFS/GFS.csproj b/GFS/GFS.csproj index 58a8fc8..1008f94 100644 --- a/GFS/GFS.csproj +++ b/GFS/GFS.csproj @@ -4,7 +4,7 @@ enable enable ThemModdingHerds.$(MSBuildProjectName) - 2.1.0 + 2.1.1 NightTheFox GFS parser library for C# https://github.com/ThemModdingHerds diff --git a/GFS/RevergePackage.cs b/GFS/RevergePackage.cs index fca5967..9b0711f 100644 --- a/GFS/RevergePackage.cs +++ b/GFS/RevergePackage.cs @@ -12,7 +12,10 @@ public static RevergePackage Merge(string id,string ver,params RevergePackage[] RevergePackageHeader header = new(id,ver); RevergePackage gfs = new(header); foreach(RevergePackage pak in files) + { + gfs.Metadata.Add(pak.Metadata); gfs.AddRange(pak); + } gfs.RecalculateEntries(); return gfs; } @@ -53,8 +56,16 @@ public static RevergePackage Create(string path,string id,string ver) entry.Offset = runningOffset; runningOffset += entry.Size; } + RevergePackage gfs = new(header,entries); + // check if perhaps a metadata file exists + string metadatapath = $"{path}.metadata"; + if(File.Exists(metadatapath)) + { + RevergePackageMetadata metadata = RevergePackageMetadata.Read(metadatapath); + gfs.Metadata.Merge(metadata); + } // create the package - return new(header,entries); + return gfs; } public static RevergePackage Open(string path) { diff --git a/GFS/RevergePackageMetadata.cs b/GFS/RevergePackageMetadata.cs index bd7366f..f815048 100644 --- a/GFS/RevergePackageMetadata.cs +++ b/GFS/RevergePackageMetadata.cs @@ -34,6 +34,37 @@ public void Save(string output) writer.Write(this); writer.Close(); } + public void Add(RevergePackageMetadata other) + { + foreach(var pair in other) + { + if(ContainsKey(pair.Key)) + continue; + Add(pair.Key,pair.Value); + } + } + public void Merge(RevergePackageMetadata other) + { + foreach(var pair in other) + { + if(ContainsKey(pair.Key)) + { + this[pair.Key] = pair.Value; + continue; + } + Add(pair.Key,pair.Value); + } + } + public void Add(IEnumerable others) + { + foreach(RevergePackageMetadata metadata in others) + Add(metadata); + } + public void Merge(IEnumerable others) + { + foreach(RevergePackageMetadata metadata in others) + Merge(metadata); + } } public static class RevergePackageMetadataExt {