mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 22:46:06 +02:00
Fix error reading metadata
This commit is contained in:
@@ -199,8 +199,8 @@ namespace VRCX
|
|||||||
|
|
||||||
await print.SaveAsPngAsync(tempPath);
|
await print.SaveAsPngAsync(tempPath);
|
||||||
|
|
||||||
var oldPngFile = new PNGFile(path);
|
var oldPngFile = new PNGFile(path, false);
|
||||||
var newPngFile = new PNGFile(tempPath);
|
var newPngFile = new PNGFile(tempPath, true);
|
||||||
|
|
||||||
// Copy all iTXt chunks to new file
|
// Copy all iTXt chunks to new file
|
||||||
var textChunks = oldPngFile.GetChunksOfType(PNGChunkTypeFilter.iTXt);
|
var textChunks = oldPngFile.GetChunksOfType(PNGChunkTypeFilter.iTXt);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public partial class AppApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using var png = new PNGFile(path);
|
using var png = new PNGFile(path, false);
|
||||||
metadata.Add("fileResolution", PNGHelper.ReadResolution(png));
|
metadata.Add("fileResolution", PNGHelper.ReadResolution(png));
|
||||||
|
|
||||||
var creationDate = File.GetCreationTime(path);
|
var creationDate = File.GetCreationTime(path);
|
||||||
|
|||||||
@@ -23,9 +23,10 @@ public class PNGFile : IDisposable
|
|||||||
/// Opens the PNG file for reading and writing.
|
/// Opens the PNG file for reading and writing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath">The path to the PNG file to open for reading and writing.</param>
|
/// <param name="filePath">The path to the PNG file to open for reading and writing.</param>
|
||||||
public PNGFile(string filePath)
|
/// <param name="writeAccess">Open file with write permissions.</param>
|
||||||
|
public PNGFile(string filePath, bool writeAccess)
|
||||||
{
|
{
|
||||||
fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, 4096);
|
fileStream = new FileStream(filePath, FileMode.Open, writeAccess ? FileAccess.ReadWrite : FileAccess.Read, FileShare.ReadWrite, 4096);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PNGFile(string filePath, int bufferSize)
|
public PNGFile(string filePath, int bufferSize)
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ namespace VRCX
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static List<string> ReadTextMetadata(string path)
|
public static List<string> ReadTextMetadata(string path)
|
||||||
{
|
{
|
||||||
using var pngFile = new PNGFile(path);
|
using var pngFile = new PNGFile(path, false);
|
||||||
var result = new List<string>();
|
var result = new List<string>();
|
||||||
var metadata = PNGHelper.ReadTextChunk("Description", pngFile);
|
var metadata = PNGHelper.ReadTextChunk("Description", pngFile);
|
||||||
var vrchatMetadata = PNGHelper.ReadTextChunk("XML:com.adobe.xmp", pngFile);
|
var vrchatMetadata = PNGHelper.ReadTextChunk("XML:com.adobe.xmp", pngFile);
|
||||||
@@ -231,7 +231,7 @@ namespace VRCX
|
|||||||
|
|
||||||
public static bool WriteVRCXMetadata(string text, string path)
|
public static bool WriteVRCXMetadata(string text, string path)
|
||||||
{
|
{
|
||||||
using var pngFile = new PNGFile(path);
|
using var pngFile = new PNGFile(path, true);
|
||||||
var chunk = PNGHelper.GenerateTextChunk("Description", text);
|
var chunk = PNGHelper.GenerateTextChunk("Description", text);
|
||||||
|
|
||||||
return pngFile.WriteChunk(chunk);;
|
return pngFile.WriteChunk(chunk);;
|
||||||
|
|||||||
Reference in New Issue
Block a user