mirror of
https://github.com/vrcx-team/VRCX.git
synced 2026-04-06 00:32:02 +02:00
Handle failing to read images for OVRTK when they're in use, retry crop print when file in use
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user