| 1 | #nullable enable |
| 2 | |
| 3 | using CascadeIDE.Contracts; |
| 4 | |
| 5 | namespace CascadeIDE.Features.EnvironmentReadiness.DataAcquisition; |
| 6 | |
| 7 | /// <summary>Классификация путей env для agent-notes (DAL, без UI-текстов).</summary> |
| 8 | public enum AgentNotesFilePathKind |
| 9 | { |
| 10 | Unset, |
| 11 | ParentDirForGlobalFile, |
| 12 | FileExists, |
| 13 | ParentMissing, |
| 14 | InvalidPath |
| 15 | } |
| 16 | |
| 17 | public enum AgentNotesConfigPathKind |
| 18 | { |
| 19 | Unset, |
| 20 | FileExists, |
| 21 | FileMissing, |
| 22 | InvalidPath |
| 23 | } |
| 24 | |
| 25 | public enum NetcoreDbgPathKind |
| 26 | { |
| 27 | UnsetFoundOnPath, |
| 28 | UnsetNotOnPath, |
| 29 | ExplicitResolved, |
| 30 | InvalidPath, |
| 31 | ExplicitBareNameNotInPath, |
| 32 | ExplicitFilePathMissing |
| 33 | } |
| 34 | |
| 35 | /// <summary>Fs/PATH-логика для строк env-готовности; Application только маппит в AnnunciatorLampItem.</summary> |
| 36 | [IoBoundary] |
| 37 | public static class EnvironmentReadinessPathAcquisition |
| 38 | { |
| 39 | public static AgentNotesFilePathKind ClassifyAgentNotesFilePath(string? raw) |
| 40 | { |
| 41 | if (string.IsNullOrWhiteSpace(raw)) |
| 42 | return AgentNotesFilePathKind.Unset; |
| 43 | |
| 44 | try |
| 45 | { |
| 46 | var full = CanonicalFilePath.Normalize(raw.Trim()); |
| 47 | var parent = Path.GetDirectoryName(full); |
| 48 | if (!string.IsNullOrEmpty(parent) && Directory.Exists(parent)) |
| 49 | return AgentNotesFilePathKind.ParentDirForGlobalFile; |
| 50 | |
| 51 | if (File.Exists(full)) |
| 52 | return AgentNotesFilePathKind.FileExists; |
| 53 | |
| 54 | return AgentNotesFilePathKind.ParentMissing; |
| 55 | } |
| 56 | catch |
| 57 | { |
| 58 | return AgentNotesFilePathKind.InvalidPath; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public static AgentNotesConfigPathKind ClassifyAgentNotesConfigPath(string? raw) |
| 63 | { |
| 64 | if (string.IsNullOrWhiteSpace(raw)) |
| 65 | return AgentNotesConfigPathKind.Unset; |
| 66 | |
| 67 | try |
| 68 | { |
| 69 | var full = CanonicalFilePath.Normalize(raw.Trim()); |
| 70 | return File.Exists(full) ? AgentNotesConfigPathKind.FileExists : AgentNotesConfigPathKind.FileMissing; |
| 71 | } |
| 72 | catch |
| 73 | { |
| 74 | return AgentNotesConfigPathKind.InvalidPath; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public static NetcoreDbgPathKind ClassifyNetcoreDbgPath( |
| 79 | string? raw, |
| 80 | Func<string?>? tryResolveNetcoreDbgWhenUnset = null) |
| 81 | { |
| 82 | if (string.IsNullOrWhiteSpace(raw)) |
| 83 | { |
| 84 | var onPath = tryResolveNetcoreDbgWhenUnset is not null |
| 85 | ? tryResolveNetcoreDbgWhenUnset.Invoke() |
| 86 | : EnvironmentReadinessExecutablePathProbe.TryResolveExecutablePath("netcoredbg"); |
| 87 | return onPath is not null |
| 88 | ? NetcoreDbgPathKind.UnsetFoundOnPath |
| 89 | : NetcoreDbgPathKind.UnsetNotOnPath; |
| 90 | } |
| 91 | |
| 92 | var trimmed = raw.Trim(); |
| 93 | if (EnvironmentReadinessExecutablePathProbe.TryResolveExecutablePath(trimmed) is not null) |
| 94 | return NetcoreDbgPathKind.ExplicitResolved; |
| 95 | |
| 96 | try |
| 97 | { |
| 98 | _ = CanonicalFilePath.Normalize(trimmed); |
| 99 | } |
| 100 | catch |
| 101 | { |
| 102 | return NetcoreDbgPathKind.InvalidPath; |
| 103 | } |
| 104 | |
| 105 | if (EnvironmentReadinessExecutablePathProbe.IsBareExecutableName(trimmed)) |
| 106 | return NetcoreDbgPathKind.ExplicitBareNameNotInPath; |
| 107 | |
| 108 | return NetcoreDbgPathKind.ExplicitFilePathMissing; |
| 109 | } |
| 110 | } |
| 111 | |