mirror of
https://github.com/vrcx-team/VRCX.git
synced 2026-04-06 00:32:02 +02:00
Fix error reading metadata
This commit is contained in:
@@ -199,8 +199,8 @@ namespace VRCX
|
||||
|
||||
await print.SaveAsPngAsync(tempPath);
|
||||
|
||||
var oldPngFile = new PNGFile(path);
|
||||
var newPngFile = new PNGFile(tempPath);
|
||||
var oldPngFile = new PNGFile(path, false);
|
||||
var newPngFile = new PNGFile(tempPath, true);
|
||||
|
||||
// Copy all iTXt chunks to new file
|
||||
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));
|
||||
|
||||
var creationDate = File.GetCreationTime(path);
|
||||
|
||||
@@ -17,15 +17,16 @@ public class PNGFile : IDisposable
|
||||
private const int MAX_CHUNKS_TO_READ = 16;
|
||||
private const int CHUNK_FIELD_SIZE = 4;
|
||||
private const int CHUNK_NONDATA_SIZE = 12;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="PNGFile"/> class with the specified file path.
|
||||
/// Opens the PNG file for reading and writing.
|
||||
/// </summary>
|
||||
/// <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)
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace VRCX
|
||||
/// </remarks>
|
||||
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 metadata = PNGHelper.ReadTextChunk("Description", pngFile);
|
||||
var vrchatMetadata = PNGHelper.ReadTextChunk("XML:com.adobe.xmp", pngFile);
|
||||
@@ -231,7 +231,7 @@ namespace VRCX
|
||||
|
||||
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);
|
||||
|
||||
return pngFile.WriteChunk(chunk);;
|
||||
|
||||
Reference in New Issue
Block a user