Skip to content

Commit 6e405a2

Browse files
committed
Moved the ResultToHash function to the ProcessOutputReader class
1 parent bbf86b3 commit 6e405a2

3 files changed

Lines changed: 41 additions & 39 deletions

File tree

‎src/WGet.NET/Components/WinGetPackageManager.cs‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ public string Hash(string file)
13171317
return string.Empty;
13181318
}
13191319

1320-
return HashResultToHash(result);
1320+
return ProcessOutputReader.ResultToHash(result);
13211321
}
13221322
catch (Win32Exception)
13231323
{
@@ -1372,7 +1372,7 @@ public string Hash(FileInfo file)
13721372
return string.Empty;
13731373
}
13741374

1375-
return HashResultToHash(result);
1375+
return ProcessOutputReader.ResultToHash(result);
13761376
}
13771377
catch (Win32Exception)
13781378
{
@@ -1428,7 +1428,7 @@ public async Task<string> HashAsync(string file)
14281428
return string.Empty;
14291429
}
14301430

1431-
return HashResultToHash(result);
1431+
return ProcessOutputReader.ResultToHash(result);
14321432
}
14331433
catch (Win32Exception)
14341434
{
@@ -1484,7 +1484,7 @@ public async Task<string> HashAsync(FileInfo file)
14841484
return string.Empty;
14851485
}
14861486

1487-
return HashResultToHash(result);
1487+
return ProcessOutputReader.ResultToHash(result);
14881488
}
14891489
catch (Win32Exception)
14901490
{
@@ -1495,30 +1495,6 @@ public async Task<string> HashAsync(FileInfo file)
14951495
throw new WinGetActionFailedException("Hashing failed.", cmd, e);
14961496
}
14971497
}
1498-
1499-
/// <summary>
1500-
/// Reads the hash from the WinGet hash action result.
1501-
/// </summary>
1502-
/// <param name="result">
1503-
/// The <see cref="WGetNET.Models.ProcessResult"/> object of the action.
1504-
/// </param>
1505-
/// <returns>
1506-
/// A <see cref="System.String"/> containing the hash value.
1507-
/// </returns>
1508-
private string HashResultToHash(ProcessResult result)
1509-
{
1510-
string hash = "";
1511-
if (result.Output.Length > 0 && result.Output[0].Contains(":"))
1512-
{
1513-
string[] splitOutput = result.Output[0].Split(':');
1514-
if (splitOutput.Length >= 2)
1515-
{
1516-
hash = splitOutput[1].Trim();
1517-
}
1518-
}
1519-
1520-
return hash;
1521-
}
15221498
//---------------------------------------------------------------------------------------------
15231499

15241500
//---Download----------------------------------------------------------------------------------

‎src/WGet.NET/HelperClasses/ProcessOutputReader.cs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,32 @@ private static List<WinGetAdminOption> ReadAdminSettings(string[] output)
785785
}
786786
//------------------------------------------------------------------------------------------------------------
787787

788+
//---To Hash--------------------------------------------------------------------------------------------------
789+
/// <summary>
790+
/// Reads the hash from the winget hash action result.
791+
/// </summary>
792+
/// <param name="result">
793+
/// The <see cref="WGetNET.Models.ProcessResult"/> object of the action.
794+
/// </param>
795+
/// <returns>
796+
/// A <see cref="System.String"/> containing the hash value.
797+
/// </returns>
798+
public static string ResultToHash(ProcessResult result)
799+
{
800+
string hash = "";
801+
if (result.Output.Length > 0 && result.Output[0].Contains(":"))
802+
{
803+
string[] splitOutput = result.Output[0].Split(':');
804+
if (splitOutput.Length >= 2)
805+
{
806+
hash = splitOutput[1].Trim();
807+
}
808+
}
809+
810+
return hash;
811+
}
812+
//------------------------------------------------------------------------------------------------------------
813+
788814
//---Other----------------------------------------------------------------------------------------------------
789815
/// <summary>
790816
/// Writes the export result to a <see cref="System.String"/>.

‎src/WGet.NET/XmlDocumentation/WGet.NET.xml‎

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)