|
| 1 | +//--------------------------------------------------// |
| 2 | +// Created by basicx-StrgV // |
| 3 | +// https://github.com/basicx-StrgV/ // |
| 4 | +//--------------------------------------------------// |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using WGetNET.Parser; |
| 8 | +using WGetNET.Abstractions; |
| 9 | + |
| 10 | +namespace WGetNET.Builder |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Builder to create a new <see cref="WGetNET.WinGetInfo"/> instance. |
| 14 | + /// </summary> |
| 15 | + internal class InfoSetBuilder : WinGetObjectBuilder<WinGetInfo> |
| 16 | + { |
| 17 | + private string _versionString = string.Empty; |
| 18 | + private Version? _version = null; |
| 19 | + private List<WinGetDirectory> _directories = new(); |
| 20 | + private List<WinGetLink> _links = new(); |
| 21 | + private List<WinGetAdminOption> _adminSettings = new(); |
| 22 | + |
| 23 | + /// <summary> |
| 24 | + /// Initializes a new instance of the <see cref="WGetNET.Builder.InfoSetBuilder"/> class. |
| 25 | + /// </summary> |
| 26 | + public InfoSetBuilder() |
| 27 | + { |
| 28 | + // Provide empty constructor |
| 29 | + } |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Adds the current winget version. |
| 33 | + /// </summary> |
| 34 | + /// <param name="version"> |
| 35 | + /// The current winget version contained in a <see cref="System.String"/>. |
| 36 | + /// </param> |
| 37 | + public void AddVersion(string version) |
| 38 | + { |
| 39 | + _versionString = version; |
| 40 | + _version = VersionParser.Parse(version); |
| 41 | + } |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Adds the current winget version. |
| 45 | + /// </summary> |
| 46 | + /// <param name="version"> |
| 47 | + /// The current winget version. |
| 48 | + /// </param> |
| 49 | + public void AddVersion(Version version) |
| 50 | + { |
| 51 | + _version = version; |
| 52 | + _versionString = version.ToString(); |
| 53 | + } |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Adds a <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetDirectory"/> objects. |
| 57 | + /// </summary> |
| 58 | + /// <param name="directories"> |
| 59 | + /// The <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetDirectory"/> objects. |
| 60 | + /// </param> |
| 61 | + public void AddDirectories(List<WinGetDirectory> directories) |
| 62 | + { |
| 63 | + _directories.AddRange(directories); |
| 64 | + } |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Adds a <see cref="WinGetDirectory"/> object. |
| 68 | + /// </summary> |
| 69 | + /// <param name="directory"> |
| 70 | + /// The <see cref="WinGetDirectory"/> object. |
| 71 | + /// </param> |
| 72 | + public void AddDirectory(WinGetDirectory? directory) |
| 73 | + { |
| 74 | + if (directory != null) |
| 75 | + { |
| 76 | + _directories.Add(directory); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + /// <summary> |
| 81 | + /// Adds a <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetLink"/> objects. |
| 82 | + /// </summary> |
| 83 | + /// <param name="links"> |
| 84 | + /// The <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetLink"/> objects. |
| 85 | + /// </param> |
| 86 | + public void AddLinks(List<WinGetLink> links) |
| 87 | + { |
| 88 | + _links.AddRange(links); |
| 89 | + } |
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// Adds a <see cref="WinGetLink"/> object. |
| 93 | + /// </summary> |
| 94 | + /// <param name="link"> |
| 95 | + /// The <see cref="WinGetLink"/> object. |
| 96 | + /// </param> |
| 97 | + public void AddLink(WinGetLink? link) |
| 98 | + { |
| 99 | + if (link != null) |
| 100 | + { |
| 101 | + _links.Add(link); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// Adds a <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetAdminOption"/> objects. |
| 107 | + /// </summary> |
| 108 | + /// <param name="adminOptions"> |
| 109 | + /// The <see cref="System.Collections.Generic.List{T}"/> of <see cref="WinGetAdminOption"/> objects. |
| 110 | + /// </param> |
| 111 | + public void AddAdminOptions(List<WinGetAdminOption> adminOptions) |
| 112 | + { |
| 113 | + _adminSettings.AddRange(adminOptions); |
| 114 | + } |
| 115 | + |
| 116 | + /// <summary> |
| 117 | + /// Adds a <see cref="WinGetAdminOption"/> object. |
| 118 | + /// </summary> |
| 119 | + /// <param name="adminOption"> |
| 120 | + /// The <see cref="WinGetAdminOption"/> object. |
| 121 | + /// </param> |
| 122 | + public void AddAdminOption(WinGetAdminOption? adminOption) |
| 123 | + { |
| 124 | + if (adminOption != null) |
| 125 | + { |
| 126 | + _adminSettings.Add(adminOption); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + /// <summary> |
| 131 | + /// Returns a <see cref="WGetNET.WinGetInfo"/> instance from data provided to the builder. |
| 132 | + /// </summary> |
| 133 | + /// <returns> |
| 134 | + /// The created <see cref="WGetNET.WinGetInfo"/> instance. |
| 135 | + /// </returns> |
| 136 | + public override WinGetInfo GetInstance() |
| 137 | + { |
| 138 | + if (_version == null) |
| 139 | + { |
| 140 | + _version = VersionParser.Parse(_versionString); |
| 141 | + } |
| 142 | + |
| 143 | + return new WinGetInfo(_versionString, _version, _directories, _links, _adminSettings); |
| 144 | + } |
| 145 | + |
| 146 | + /// <inheritdoc/> |
| 147 | + public override void Clear() |
| 148 | + { |
| 149 | + _versionString = string.Empty; |
| 150 | + _version = null; |
| 151 | + _directories = new List<WinGetDirectory>(); |
| 152 | + _links = new List<WinGetLink>(); |
| 153 | + _adminSettings = new List<WinGetAdminOption>(); |
| 154 | + } |
| 155 | + } |
| 156 | +} |
0 commit comments