|
| 1 | +#r "System.Xml.XDocument.dll" |
| 2 | + |
| 3 | +using System |
| 4 | +using System.IO |
| 5 | +using System.Xml.Linq |
| 6 | + |
| 7 | +// |
| 8 | +VAR appDataRoamingPath := Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) |
| 9 | +VAR nugetConfigPath := Path.Combine(appDataRoamingPath, "NuGet\\nuget.config") |
| 10 | +VAR xsharpOffLine := "XSharp Offline Packages" |
| 11 | +VAR sourceUrl := GetXSharpInstallationPath() |
| 12 | + |
| 13 | +local doc as XDocument |
| 14 | +IF !File.Exists(nugetConfigPath) |
| 15 | + doc := XDocument{XElement{"configuration"}} |
| 16 | +ELSE |
| 17 | + doc := XDocument.Load(nugetConfigPath) |
| 18 | +endif |
| 19 | + |
| 20 | +VAR configElement := doc:Element("configuration") |
| 21 | +VAR packageSources := configElement:Element("packageSources") |
| 22 | + |
| 23 | +if packageSources == null |
| 24 | + packageSources := XElement{"packageSources"} |
| 25 | + configElement:Add(packageSources) |
| 26 | +endif |
| 27 | +VAR found := false |
| 28 | +foreach elt as XElement in packageSources:Elements("add") |
| 29 | + if elt:Attribute("key")?:Value == xsharpOffLine |
| 30 | + found := true |
| 31 | + exit |
| 32 | + endif |
| 33 | +next |
| 34 | +if !found |
| 35 | + packageSources:Add(XElement{"add", XAttribute{"key", xsharpOffLine}, XAttribute{"value", sourceUrl}}) |
| 36 | +endif |
| 37 | +// |
| 38 | +VAR packageSourceMapping := configElement:Element("packageSourceMapping") |
| 39 | +if packageSourceMapping == null |
| 40 | + packageSourceMapping := XElement{"packageSourceMapping"} |
| 41 | + configElement:Add(packageSourceMapping) |
| 42 | +endif |
| 43 | +found := false |
| 44 | +foreach elt as XElement in packageSourceMapping:Elements() |
| 45 | + if elt:Attribute("key")?:Value == xsharpOffLine |
| 46 | + found := true |
| 47 | + exit |
| 48 | + endif |
| 49 | +next |
| 50 | +if !found |
| 51 | + VAR packageSource := XElement{"packageSource", XAttribute{"key", xsharpOffLine}, XElement{"package", XAttribute{"pattern", "XSharp.*"}}} |
| 52 | + packageSourceMapping:Add(packageSource) |
| 53 | +endif |
| 54 | +doc:Save(nugetConfigPath) |
| 55 | + |
| 56 | + |
| 57 | +FUNCTION GetXSharpInstallationPath() as string |
| 58 | + // |
| 59 | + VAR pathVariable := Environment.GetEnvironmentVariable("PATH") |
| 60 | + VAR xsharpPath := "c:\\Program Files (x86)\\XSharp" |
| 61 | + if pathVariable != null |
| 62 | + VAR paths := pathVariable:Split(';') |
| 63 | + VAR folderFound := false |
| 64 | + foreach path as string in paths |
| 65 | + if (Directory.Exists(path)) .AND. (path:Contains("XSharp")) |
| 66 | + xsharpPath := Path.GetDirectoryName(path) |
| 67 | + exit |
| 68 | + endif |
| 69 | + next |
| 70 | + endif |
| 71 | +return xsharpPath |
0 commit comments