Handle failing to read images for OVRTK when they're in use, retry crop print when file in use

This commit is contained in:
Natsumi
2025-10-30 01:34:16 +11:00
parent 3836b9b4ce
commit 515f48a9e4
2 changed files with 35 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing.Processing;
@@ -213,7 +214,31 @@ namespace VRCX
oldPngFile.Dispose();
newPngFile.Dispose();
File.Move(tempPath, path, true);
// check if file is in use and we have permission to write
for (var i = 0; i < 10; i++)
{
try
{
await using (File.Open(path, FileMode.Append, FileAccess.Write, FileShare.None))
{
break;
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
await Task.Delay(1000);
}
}
try
{
File.Move(tempPath, path, true);
}
catch (Exception ex)
{
logger.Error(ex, "Failed to replace cropped print image");
return false;
}
return true;
}

View File

@@ -94,15 +94,19 @@ namespace VRCX
{
List<OvrtMessage> messages = [];
byte[] imageBytes;
if(!string.IsNullOrWhiteSpace(image) && File.Exists(image))
byte[] imageBytes = null;
try
{
imageBytes = File.ReadAllBytes(image);
if (!string.IsNullOrWhiteSpace(image) && File.Exists(image))
{
imageBytes = File.ReadAllBytes(image);
}
}
else
catch (Exception ex)
{
imageBytes = _vrcxIcon;
logger.Error(ex, "Failed to read OVRT notification image");
}
imageBytes ??= _vrcxIcon;
if (wristNotification)
{