Skip to content

Commit

Permalink
adding + merging metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ghtTheF0x committed Nov 10, 2024
1 parent aec9100 commit b6245bb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion GFS/GFS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>ThemModdingHerds.$(MSBuildProjectName)</AssemblyName>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Authors>NightTheFox</Authors>
<Description>GFS parser library for C#</Description>
<PackageProjectUrl>https://github.com/ThemModdingHerds</PackageProjectUrl>
Expand Down
13 changes: 12 additions & 1 deletion GFS/RevergePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down
31 changes: 31 additions & 0 deletions GFS/RevergePackageMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RevergePackageMetadata> others)
{
foreach(RevergePackageMetadata metadata in others)
Add(metadata);
}
public void Merge(IEnumerable<RevergePackageMetadata> others)
{
foreach(RevergePackageMetadata metadata in others)
Merge(metadata);
}
}
public static class RevergePackageMetadataExt
{
Expand Down

0 comments on commit b6245bb

Please sign in to comment.