-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDataManager.cs
More file actions
88 lines (74 loc) · 2.5 KB
/
Copy pathDataManager.cs
File metadata and controls
88 lines (74 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace WinGetGui
{
static class DataManager
{
public static Task<List<ApplicationData>> FetchData()
{
return Task.Run(() =>
{
var apps = new List<ApplicationData>();
var lines = new List<string>();
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "winget",
Arguments = "show",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
var line = proc.StandardOutput.ReadLine();
lines.Add(line);
}
foreach (var line in lines.Skip(4))
{
if (line.Trim().Length < 74) continue;
var newAppData = new ApplicationData
{
Name = line.Substring(0, 30).Trim(),
Id = line.Substring(29, 44).Trim()
};
apps.Add(newAppData);
}
Parallel.ForEach(apps,
currentElement =>
{
currentElement.Versions = GetVersions(currentElement.Id);
});
return apps.OrderBy(x => x.Name).ToList();
});
}
private static List<string> GetVersions(string id)
{
var versions = new List<string>();
var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "winget",
Arguments = $"show {id} --versions --exact",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
var line = proc.StandardOutput.ReadLine();
versions.Add(line.Trim());
}
var output = versions.Skip(4).ToList();
return output;
}
}
}