Skip to content

Commit 671d25a

Browse files
committed
Changed the ProcessOutputReader back to static; Fixed some errors in the implementation; Smaller improvements
1 parent 673e7da commit 671d25a

12 files changed

Lines changed: 103 additions & 130 deletions

src/WGet.NET/Builder/WinGetAdminSettingBuilder.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void AddRawContent(string rawContent)
5454
_rawContent = rawContent;
5555
}
5656

57-
_isEnabled = ParseToBool(_rawContent, _hasShortenedContent);
57+
SetIsEnabled(_rawContent, _hasShortenedContent);
5858
}
5959

6060
/// <summary>
@@ -108,33 +108,27 @@ public override void Clear()
108108
}
109109

110110
/// <summary>
111-
/// Parses the raw content to a <see cref="System.Boolean"/> value.
111+
/// Sets the is anabled value by parsing the raw content to a <see cref="System.Boolean"/> value.
112112
/// </summary>
113113
/// <param name="rawContent">
114114
/// A <see cref="System.String"/> containing the raw content.
115115
/// </param>
116116
/// <param name="hasShortenedContent">
117117
/// Indicates if the content is shortened or not.
118118
/// </param>
119-
/// <returns>
120-
/// The paresed <see cref="System.Boolean"/> value or <see langword="null"/> if parsing failed.
121-
/// </returns>
122-
private bool? ParseToBool(string rawContent, bool hasShortenedContent)
119+
private void SetIsEnabled(string rawContent, bool hasShortenedContent)
123120
{
124-
bool isEnabled = false;
125-
bool parsed = false;
121+
_isEnabled = null;
126122

127123
if (!hasShortenedContent)
128124
{
129125
switch (rawContent.ToUpper())
130126
{
131127
case "ENABLED":
132-
isEnabled = true;
133-
parsed = true;
128+
_isEnabled = true;
134129
break;
135130
case "DISABLED":
136-
isEnabled = false;
137-
parsed = true;
131+
_isEnabled = false;
138132
break;
139133
}
140134
}
@@ -145,34 +139,23 @@ public override void Clear()
145139
#if NETCOREAPP3_1_OR_GREATER
146140
if (rawContent.ToUpper().StartsWith('E'))
147141
{
148-
isEnabled = true;
149-
parsed = true;
142+
_isEnabled = true;
150143
}
151144
else if (rawContent.ToUpper().StartsWith('D'))
152145
{
153-
isEnabled = false;
154-
parsed = true;
146+
_isEnabled = false;
155147
}
156148
#elif NETSTANDARD2_0
157149
if (rawContent.ToUpper().StartsWith("E"))
158150
{
159-
isEnabled = true;
160-
parsed = true;
151+
_isEnabled = true;
161152
}
162153
else if (rawContent.ToUpper().StartsWith("D"))
163154
{
164-
isEnabled = false;
165-
parsed = true;
155+
_isEnabled = false;
166156
}
167157
#endif
168158
}
169-
170-
if (!parsed)
171-
{
172-
return null;
173-
}
174-
175-
return isEnabled;
176159
}
177160
}
178161
}

src/WGet.NET/Builder/WinGetDirectoryBuilder.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void AddRawContent(string rawContent)
5656
_rawContent = rawContent;
5757
}
5858

59-
_directoryInfo = CreateDirectoryInfo(_rawContent, _hasShortenedContent);
59+
SetDirectoryInfo(_rawContent, _hasShortenedContent);
6060
}
6161

6262
/// <summary>
@@ -85,14 +85,11 @@ public override void Clear()
8585
}
8686

8787
/// <summary>
88-
/// Creates and returns a <see cref="System.IO.DirectoryInfo"/> instance from the raw content.
88+
/// Creates and sets the <see cref="System.IO.DirectoryInfo"/> instance from the raw content.
8989
/// </summary>
9090
/// <param name="rawContent"><see cref="System.String"/> containing the raw data that should get parsed.</param>
9191
/// <param name="hasShortenedContent">Indcates if the information in the raw content is shortened.</param>
92-
/// <returns>
93-
/// The created <see cref="System.IO.DirectoryInfo"/> instance, or <see langword="null"/> if parsing the raw content failed.
94-
/// </returns>
95-
private DirectoryInfo? CreateDirectoryInfo(string rawContent, bool hasShortenedContent)
92+
private void SetDirectoryInfo(string rawContent, bool hasShortenedContent)
9693
{
9794
try
9895
{
@@ -112,15 +109,15 @@ public override void Clear()
112109

113110
if (!hasShortenedContent)
114111
{
115-
return new DirectoryInfo(path);
112+
_directoryInfo = new DirectoryInfo(path);
116113
}
117114

118115
// Fallback for an incomplete directory path.
119-
return new DirectoryInfo(TrimLastDirectory(path));
116+
_directoryInfo = new DirectoryInfo(TrimLastDirectory(path));
120117
}
121118
catch
122119
{
123-
return null;
120+
_directoryInfo = null;
124121
}
125122
}
126123

src/WGet.NET/Builder/WinGetLinkBuilder.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void AddRawContent(string rawContent)
5555
_rawContent = rawContent;
5656
}
5757

58-
_url = CreateUri(_rawContent, _hasShortenedContent);
58+
SetUri(_rawContent, _hasShortenedContent);
5959
}
6060

6161
/// <summary>
@@ -84,24 +84,21 @@ public override void Clear()
8484
}
8585

8686
/// <summary>
87-
/// Creates and returns a <see cref="System.Uri"/> instance from the raw content.
87+
/// Creates and sets the <see cref="System.Uri"/> instance from the raw content.
8888
/// </summary>
8989
/// <param name="rawContent"><see cref="System.String"/> containing the raw data that should get parsed.</param>
9090
/// <param name="hasShortenedContent">Indcates if the information in the raw content is shortened.</param>
91-
/// <returns>
92-
/// The created <see cref="System.Uri"/> instance.
93-
/// </returns>
94-
private Uri? CreateUri(string rawContent, bool hasShortenedContent)
91+
private void SetUri(string rawContent, bool hasShortenedContent)
9592
{
9693
if (!hasShortenedContent)
9794
{
9895
Uri.TryCreate(rawContent, UriKind.Absolute, out Uri? uri);
99-
return uri;
96+
_url = uri;
10097
}
10198

10299
// Fallback for an incomplete uri.
103100
Uri.TryCreate(TrimLastUriPart(rawContent), UriKind.Absolute, out Uri? shortenedUri);
104-
return shortenedUri;
101+
_url = shortenedUri;
105102
}
106103

107104
/// <summary>

src/WGet.NET/Components/Internal/ProcessManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5+
using System;
56
using System.IO;
67
using System.Text;
78
using System.Threading;
@@ -184,7 +185,7 @@ private async Task<ProcessResult> RunProcessAsync(ProcessStartInfo processStartI
184185
/// </returns>
185186
private string[] ReadSreamOutput(StreamReader output)
186187
{
187-
string[] outputArray = new string[0];
188+
string[] outputArray = Array.Empty<string>();
188189

189190
//Read output to list
190191
while (!output.EndOfStream)
@@ -216,7 +217,7 @@ private string[] ReadSreamOutput(StreamReader output)
216217
/// </returns>
217218
private async Task<string[]> ReadSreamOutputAsync(StreamReader output, CancellationToken cancellationToken = default)
218219
{
219-
string[] outputArray = new string[0];
220+
string[] outputArray = Array.Empty<string>();
220221

221222
//Read output to list
222223
while (!output.EndOfStream)

0 commit comments

Comments
 (0)