mirror of
https://github.com/alexhopeoconnor/bom-local-service.git
synced 2026-10-04 03:28:11 +10:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user