| | | 1 | | namespace EHonda.KicktippAi.Core; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Utility class for finding paths relative to the solution root |
| | | 5 | | /// </summary> |
| | | 6 | | public static class SolutionPathUtility |
| | | 7 | | { |
| | | 8 | | private const string SolutionFileName = "KicktippAi.slnx"; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Finds the solution root directory by looking for KicktippAi.slnx in parent directories. |
| | | 12 | | /// </summary> |
| | | 13 | | /// <returns>The path to the solution root directory.</returns> |
| | | 14 | | /// <exception cref="DirectoryNotFoundException">Thrown when the solution root cannot be found.</exception> |
| | | 15 | | public static string FindSolutionRoot() |
| | | 16 | | { |
| | 1 | 17 | | var currentDirectory = Directory.GetCurrentDirectory(); |
| | 1 | 18 | | var directory = new DirectoryInfo(currentDirectory); |
| | | 19 | | |
| | 1 | 20 | | while (directory != null) |
| | | 21 | | { |
| | 1 | 22 | | var solutionFile = Path.Combine(directory.FullName, SolutionFileName); |
| | 1 | 23 | | if (File.Exists(solutionFile)) |
| | | 24 | | { |
| | 1 | 25 | | return directory.FullName; |
| | | 26 | | } |
| | 1 | 27 | | directory = directory.Parent; |
| | | 28 | | } |
| | | 29 | | |
| | 1 | 30 | | throw new DirectoryNotFoundException( |
| | 1 | 31 | | $"Could not find solution root ({SolutionFileName}) starting from: {currentDirectory}"); |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Finds a directory under the solution root. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="relativePath">The relative path from the solution root (e.g., "prompts", "community-rules").</param |
| | | 38 | | /// <returns>The absolute path to the directory.</returns> |
| | | 39 | | /// <exception cref="DirectoryNotFoundException">Thrown when the solution root cannot be found.</exception> |
| | | 40 | | public static string FindDirectoryUnderSolutionRoot(string relativePath) |
| | | 41 | | { |
| | 1 | 42 | | var solutionRoot = FindSolutionRoot(); |
| | 1 | 43 | | return Path.Combine(solutionRoot, relativePath); |
| | | 44 | | } |
| | | 45 | | } |