feat: Rewrite png metadata handling, new VRC metadata (#1311)

* refactor: Move ScreenshotHelper png parsing to PNGHelper, simplify interface

* refactor: Fix references to screenshotmanager

* fix: Read resolution, not description

* refactor: Rewrite/move all png reading logic into new class

* refactor: Integrate new metadata helper functions

* refactor: Add docs, re-add legacy mods support, change error handling

There are no longer specific errors for each metadata type as it was
just super unnecessary; A verbose log including the exception/string is
now logged to file instead and a generic error is given in the UI.

* fix: Show old vrc beta format images

They were being treated as a non-image
This commit is contained in:
Teacup
2025-08-03 23:05:40 -07:00
committed by GitHub
parent 7b38599193
commit 4e64177722
9 changed files with 769 additions and 508 deletions

View File

@@ -33,7 +33,8 @@ namespace VRCX
path = newPath;
}
ScreenshotHelper.WritePNGDescription(path, metadataString);
ScreenshotHelper.WriteVRCXMetadata(metadataString, path);
return path;
}
}

View File

@@ -198,8 +198,18 @@ namespace VRCX
return false;
await print.SaveAsPngAsync(tempPath);
if (ScreenshotHelper.HasTXt(path))
ScreenshotHelper.CopyTXt(path, tempPath);
using var oldPngFile = new PNGFile(path);
using var newPngFile = new PNGFile(tempPath);
// Copy all iTXt chunks to new file
var textChunks = oldPngFile.GetChunksOfType(PNGChunkTypeFilter.iTXt);
for (var i = 0; i < textChunks.Count; i++)
{
newPngFile.WriteChunk(textChunks[i]);
}
File.Move(tempPath, path, true);
return true;
}

View File

@@ -35,7 +35,8 @@ public partial class AppApi
}
}
metadata.Add("fileResolution", ScreenshotHelper.ReadPNGResolution(path));
using var png = new PNGFile(path);
metadata.Add("fileResolution", PNGHelper.ReadResolution(png));
var creationDate = File.GetCreationTime(path);
metadata.Add("creationDate", creationDate.ToString("yyyy-MM-dd HH:mm:ss"));

View File

@@ -37,7 +37,7 @@ namespace VRCX
path = newPath;
}
ScreenshotHelper.WritePNGDescription(path, metadataString);
ScreenshotHelper.WriteVRCXMetadata(path, metadataString);
return path;
}
}