74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
namespace RobotNet10.RobotApp.SLAM.Cartographer.Helpers;
|
|
|
|
/// <summary>
|
|
/// Centralizes map directory path construction and legacy file name resolution.
|
|
/// Eliminates duplicated Path.Combine + legacy fallback patterns across CartographerService.
|
|
/// </summary>
|
|
public static class MapPathHelper
|
|
{
|
|
#region Path Construction
|
|
|
|
/// <summary>
|
|
/// Get the full path to a map directory, sanitizing the map name.
|
|
/// </summary>
|
|
public static string GetMapPath(string mapsDirectory, string mapName)
|
|
{
|
|
var sanitizedMapName = MapNameHelper.Sanitize(mapName);
|
|
return Path.Combine(Path.GetFullPath(mapsDirectory), sanitizedMapName);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region File Resolution
|
|
|
|
/// <summary>
|
|
/// Resolve metadata JSON path, trying map.json first then legacy metadata.json.
|
|
/// Returns null if neither exists.
|
|
/// </summary>
|
|
public static string? ResolveMetadataPath(string mapPath)
|
|
{
|
|
var metadataPath = Path.Combine(mapPath, "map.json");
|
|
if (File.Exists(metadataPath))
|
|
return metadataPath;
|
|
|
|
var legacyPath = Path.Combine(mapPath, "metadata.json");
|
|
if (File.Exists(legacyPath))
|
|
return legacyPath;
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolve pbstream path, trying map.pbstream first then any .pbstream file in the directory.
|
|
/// Returns null if none found.
|
|
/// </summary>
|
|
public static string? ResolvePbstreamPath(string mapPath)
|
|
{
|
|
var pbstreamPath = Path.Combine(mapPath, "map.pbstream");
|
|
if (File.Exists(pbstreamPath))
|
|
return pbstreamPath;
|
|
|
|
var pbstreamFiles = Directory.GetFiles(mapPath, "*.pbstream");
|
|
return pbstreamFiles.Length > 0 ? pbstreamFiles[0] : null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Resolve map image path (PNG or JPG).
|
|
/// Returns null if no image found.
|
|
/// </summary>
|
|
public static string? ResolveImagePath(string mapPath)
|
|
{
|
|
var pngPath = Path.Combine(mapPath, "map.png");
|
|
if (File.Exists(pngPath))
|
|
return pngPath;
|
|
|
|
var jpgPath = Path.Combine(mapPath, "map.jpg");
|
|
if (File.Exists(jpgPath))
|
|
return jpgPath;
|
|
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
}
|