-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsUpdates.xaml.cs
147 lines (113 loc) · 4.5 KB
/
WindowsUpdates.xaml.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.TextFormatting;
using System.Windows.Shapes;
using WUApiLib;
namespace Computer_Support_Info
{
public partial class WindowsUpdates : Window, INotifyPropertyChanged
{
public ObservableCollection<WindowsUpdatesElement> WindowsUpdatesData
{
get; set;
} = new ObservableCollection<WindowsUpdatesElement>();
BackgroundWorker worker = null;
bool isBusy;
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string name = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public bool IsBusy
{
get => isBusy;
set
{
isBusy = value;
OnPropertyChanged();
}
}
public WindowsUpdates()
{
InitializeComponent();
DataContext = this;
//WindowsUpdatesGrid.ItemsSource = WindowsUpdatesData;
IsBusy = true;
worker = new BackgroundWorker();
worker.DoWork += Worker_DoWork;
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
worker.RunWorkerAsync();
this.Title += " (" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ") - Installierte Updates";
Rect workArea = SystemParameters.WorkArea;
this.Height = workArea.Height / 1.25;
this.Width = workArea.Width / 1.75;
this.Left = (workArea.Width - this.Width) / 2 + workArea.Left;
this.Top = (workArea.Height - this.Height) / 2 + workArea.Top;
this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFD8E8E5"));
}
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
IsBusy = false;
this.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFD8E8E5"));
//TextOut.Text = string.Empty;
//TextOut.Text = e.Result.ToString();
//BtnStart.IsEnabled = true;
//BtnExit.IsEnabled = true;
}
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
List<string> categoriesToExclude = Properties.Settings.Default.update_categories_to_exclude.Cast<string>().ToList().ConvertAll(x => x.ToLower().Trim());
UpdateSession session = new UpdateSession();
IUpdateSearcher searcher = session.CreateUpdateSearcher();
searcher.Online = false;
var count = searcher.GetTotalHistoryCount();
if (count == 0) return;
var history = searcher.QueryHistory(0, count);
for (int i = 0; i < count; i++)
{
IUpdateHistoryEntry2 uhe = (IUpdateHistoryEntry2)history[i];
var category = "n/a";
ICategoryCollection categories = uhe.Categories;
foreach (ICategory oc in categories)
{
category = oc.Name;
break;
}
// check for excluded catgory
if (categoriesToExclude.Contains(category.ToLower().Trim())) continue;
var title = history[i].Title;
IUpdateIdentity ident = history[i].UpdateIdentity;
var id = ident.UpdateID;
Application.Current.Dispatcher.Invoke(
new Action(() => {
WindowsUpdatesData.Add(new WindowsUpdatesElement()
{
Kb = id,
Title = title,
Date = history[i].Date.ToString(),
Result = history[i].ResultCode.ToString().Replace("orc", string.Empty),
Category = category
});
})
);
}
}
private void BtnExit_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}