namespace RobotNet10.RobotApp.SLAM.Cartographer.Helpers; /// /// Centralizes map directory path construction and legacy file name resolution. /// Eliminates duplicated Path.Combine + legacy fallback patterns across CartographerService. /// public static class MapPathHelper { #region Path Construction /// /// Get the full path to a map directory, sanitizing the map name. /// public static string GetMapPath(string mapsDirectory, string mapName) { var sanitizedMapName = MapNameHelper.Sanitize(mapName); return Path.Combine(Path.GetFullPath(mapsDirectory), sanitizedMapName); } #endregion #region File Resolution /// /// Resolve metadata JSON path, trying map.json first then legacy metadata.json. /// Returns null if neither exists. /// 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; } /// /// Resolve pbstream path, trying map.pbstream first then any .pbstream file in the directory. /// Returns null if none found. /// 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; } /// /// Resolve map image path (PNG or JPG). /// Returns null if no image found. /// 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 }