mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 06:56:04 +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.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Drawing.Processing;
|
using SixLabors.ImageSharp.Drawing.Processing;
|
||||||
@@ -213,7 +214,31 @@ namespace VRCX
|
|||||||
oldPngFile.Dispose();
|
oldPngFile.Dispose();
|
||||||
newPngFile.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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,15 +94,19 @@ namespace VRCX
|
|||||||
{
|
{
|
||||||
List<OvrtMessage> messages = [];
|
List<OvrtMessage> messages = [];
|
||||||
|
|
||||||
byte[] imageBytes;
|
byte[] imageBytes = null;
|
||||||
if(!string.IsNullOrWhiteSpace(image) && File.Exists(image))
|
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)
|
if (wristNotification)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user