diff --git a/Dotnet/AppApi/Common/ImageSaving.cs b/Dotnet/AppApi/Common/ImageSaving.cs index a1f6604a..e2d054d8 100644 --- a/Dotnet/AppApi/Common/ImageSaving.cs +++ b/Dotnet/AppApi/Common/ImageSaving.cs @@ -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); diff --git a/Dotnet/AppApi/Common/Screenshot.cs b/Dotnet/AppApi/Common/Screenshot.cs index 809967c4..717d1849 100644 --- a/Dotnet/AppApi/Common/Screenshot.cs +++ b/Dotnet/AppApi/Common/Screenshot.cs @@ -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); diff --git a/Dotnet/ScreenshotMetadata/PNGFile.cs b/Dotnet/ScreenshotMetadata/PNGFile.cs index d5a87cde..71b15211 100644 --- a/Dotnet/ScreenshotMetadata/PNGFile.cs +++ b/Dotnet/ScreenshotMetadata/PNGFile.cs @@ -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; - + /// /// Initializes a new instance of class with the specified file path. /// Opens the PNG file for reading and writing. /// /// The path to the PNG file to open for reading and writing. - public PNGFile(string filePath) + /// Open file with write permissions. + 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) diff --git a/Dotnet/ScreenshotMetadata/ScreenshotHelper.cs b/Dotnet/ScreenshotMetadata/ScreenshotHelper.cs index 637ab41b..06367fc2 100644 --- a/Dotnet/ScreenshotMetadata/ScreenshotHelper.cs +++ b/Dotnet/ScreenshotMetadata/ScreenshotHelper.cs @@ -196,7 +196,7 @@ namespace VRCX /// public static List ReadTextMetadata(string path) { - using var pngFile = new PNGFile(path); + using var pngFile = new PNGFile(path, false); var result = new List(); 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);;