WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
WinGetAdminSettingBuilder.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
6
8{
12 internal class WinGetAdminSettingBuilder : WinGetObjectBuilder<WinGetAdminSetting?>
13 {
14 private string _entryName = string.Empty;
15 private string _rawContent = string.Empty;
16 private bool _hasShortenedContent = false;
17 private bool? _isEnabled = false;
18
22 public WinGetAdminSettingBuilder()
23 {
24 // Provide empty constructor
25 }
26
31 public void AddEntryName(string entryName)
32 {
33 _entryName = entryName;
34 }
35
43 public void AddRawContent(string rawContent)
44 {
45 _hasShortenedContent = CheckShortenedValue(rawContent);
46
47 if (_hasShortenedContent)
48 {
49 // Remove the char at the end of the shortened content.
50#if NETCOREAPP3_1_OR_GREATER
51 _rawContent = rawContent[..^1];
52#elif NETSTANDARD2_0
53 _rawContent = rawContent.Remove(rawContent.Length - 1);
54#endif
55 }
56 else
57 {
58 _rawContent = rawContent;
59 }
60
61 SetIsEnabled(_rawContent, _hasShortenedContent);
62 }
63
74 public void AddStatus(bool status)
75 {
76 _isEnabled = status;
77
78 // Set the raw content to a value that could be parsed.
79 if (_isEnabled.Value)
80 {
81 _rawContent = "Enabled";
82 }
83 else
84 {
85 _rawContent = "Disabled";
86 }
87 }
88
95 public override WinGetAdminSetting? GetInstance()
96 {
97 if (!_isEnabled.HasValue)
98 {
99 return null;
100 }
101
102 return new WinGetAdminSetting(_entryName, _rawContent, _hasShortenedContent, _isEnabled.Value);
103 }
104
106 public override void Clear()
107 {
108 _entryName = string.Empty;
109 _rawContent = string.Empty;
110 _hasShortenedContent = false;
111 _isEnabled = false;
112 }
113
123 private void SetIsEnabled(string rawContent, bool hasShortenedContent)
124 {
125 _isEnabled = null;
126
127 if (!hasShortenedContent)
128 {
129 switch (rawContent.ToUpper())
130 {
131 case "ENABLED":
132 _isEnabled = true;
133 break;
134 case "DISABLED":
135 _isEnabled = false;
136 break;
137 }
138 }
139 else
140 {
141 // Try to parse data with smalles amount of information possible.
142 // But the value is short enough, so it should not come to this.
143#if NETCOREAPP3_1_OR_GREATER
144 if (rawContent.ToUpper().StartsWith('E'))
145 {
146 _isEnabled = true;
147 }
148 else if (rawContent.ToUpper().StartsWith('D'))
149 {
150 _isEnabled = false;
151 }
152#elif NETSTANDARD2_0
153 if (rawContent.ToUpper().StartsWith("E"))
154 {
155 _isEnabled = true;
156 }
157 else if (rawContent.ToUpper().StartsWith("D"))
158 {
159 _isEnabled = false;
160 }
161#endif
162 }
163 }
164 }
165}
Represents a winget admin settings entry.