@@ -2,6 +2,7 @@ module Fsih.Parser
22
33open System
44open System.IO
5+ open System.Text .RegularExpressions
56open System.Xml
67open Spectre.Console
78
@@ -68,6 +69,23 @@ let trimDotNet (s: string) =
6869// WTF, seems like we loose inner xml (example content) if we cache an XmlDocument
6970let xmlDocCache = Collections.Generic.Dictionary< string, string>()
7071
72+ let toFallbackXmlPath ( xmlPath : string ) =
73+ let replaceLast ( s : string ) ( oldValue : string ) ( newValue : string ) =
74+ let idx = s.LastIndexOf( oldValue)
75+
76+ if idx >= 0 then
77+ s.Substring( 0 , idx) + newValue + s.Substring( idx + oldValue.Length)
78+ else
79+ s
80+
81+ let sep = Path.DirectorySeparatorChar
82+ let xmlPath = replaceLast xmlPath " shared" " packs"
83+ let xmlPath = replaceLast xmlPath $" .App{sep}" $" .App.Ref{sep}"
84+ let version = Regex.Match( xmlPath, @" \d+\.\d+\.\d+" ) .Value
85+ let release = version.Substring( 0 , version.LastIndexOf( '.' ))
86+ let xmlPath = replaceLast xmlPath version $" {version}{sep}ref{sep}net{release}"
87+ xmlPath
88+
7189let tryGetXmlDocument xmlPath =
7290#if DEBUG
7391 printfn $" trying xml file: %s {xmlPath}"
@@ -79,14 +97,26 @@ let tryGetXmlDocument xmlPath =
7997 xmlDocument.LoadXml( value)
8098 Some xmlDocument
8199 | _ ->
82- let rawXml = System.IO.File.ReadAllText( xmlPath)
100+ let fileExists = File.Exists( xmlPath)
101+
102+ let xmlPath =
103+ if fileExists then
104+ xmlPath
105+ else
106+ let fallback = toFallbackXmlPath xmlPath
107+ #if DEBUG
108+ printfn $" falling back to xml file: %s {fallback}"
109+ #endif
110+ fallback
111+
112+ let rawXml = File.ReadAllText( xmlPath)
83113 let xmlDocument = XmlDocument()
84114 xmlDocument.LoadXml( rawXml)
85- xmlDocCache.Add ( xmlPath, rawXml)
115+ xmlDocCache[ xmlPath] <- rawXml
86116 Some xmlDocument
87117 with _ ->
88118#if DEBUG
89- printfn $" xml file not found: {xmlPath} "
119+ printfn $" xml file not found"
90120#endif
91121 None
92122
0 commit comments