Refactor cache validation and add startup cleanup

- Move cache folder completeness check to CacheHelper utility
- Replace Width with RightOffset in screenshot crop config
- Add startup cleanup to remove incomplete cache folders
- Validate cache folders before use in BomRadarService
This commit is contained in:
2025-12-07 14:35:38 +10:00
parent 18e0a7a01f
commit 27dd44aaa1
9 changed files with 196 additions and 34 deletions
+51
View File
@@ -0,0 +1,51 @@
namespace BomLocalService.Utilities;
/// <summary>
/// Utility methods for cache folder validation and operations.
/// </summary>
public static class CacheHelper
{
/// <summary>
/// Checks if a cache folder is complete (has all required files).
/// A complete cache folder must have:
/// - All 7 frame images (frame_0.png through frame_6.png)
/// - metadata.json file
/// - frames.json file
/// </summary>
/// <param name="cacheFolderPath">The path to the cache folder to check</param>
/// <returns>True if the folder is complete, false otherwise</returns>
public static bool IsCacheFolderComplete(string cacheFolderPath)
{
if (string.IsNullOrEmpty(cacheFolderPath) || !Directory.Exists(cacheFolderPath))
{
return false;
}
// Check for all 7 frames
for (int i = 0; i < 7; i++)
{
var framePath = FilePathHelper.GetFrameFilePath(cacheFolderPath, i);
if (!File.Exists(framePath))
{
return false;
}
}
// Check for metadata.json
var metadataPath = FilePathHelper.GetMetadataFilePath(cacheFolderPath);
if (!File.Exists(metadataPath))
{
return false;
}
// Check for frames.json
var framesMetadataPath = FilePathHelper.GetFramesMetadataFilePath(cacheFolderPath);
if (!File.Exists(framesMetadataPath))
{
return false;
}
return true;
}
}
+9
View File
@@ -88,5 +88,14 @@ public static class FilePathHelper
{
return Path.Combine(cacheFolderPath, ".writing");
}
/// <summary>
/// Gets the frames metadata file path within a cache folder.
/// Format: "{CacheFolderPath}/frames.json"
/// </summary>
public static string GetFramesMetadataFilePath(string cacheFolderPath)
{
return Path.Combine(cacheFolderPath, "frames.json");
}
}