-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathiupdatehistoryentry.go
124 lines (101 loc) · 4.74 KB
/
iupdatehistoryentry.go
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
package windowsupdate
import (
"time"
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"github.com/kolide/launcher/pkg/windows/oleconv"
"github.com/pkg/errors"
)
// IUpdateHistoryEntry represents the recorded history of an update.
// https://docs.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iupdatehistoryentry
type IUpdateHistoryEntry struct {
disp *ole.IDispatch
ClientApplicationID string
Date *time.Time
Description string
HResult int32
Operation int32 // enum https://docs.microsoft.com/en-us/windows/win32/api/wuapi/ne-wuapi-updateoperation
ResultCode int32 // enum https://docs.microsoft.com/en-us/windows/win32/api/wuapi/ne-wuapi-operationresultcode
ServerSelection int32 // enum
ServiceID string
SupportUrl string
Title string
UninstallationNotes string
UninstallationSteps []string
UnmappedResultCode int32
UpdateIdentity *IUpdateIdentity
}
func toIUpdateHistoryEntries(updateHistoryEntriesDisp *ole.IDispatch) ([]*IUpdateHistoryEntry, error) {
count, err := oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntriesDisp, "Count"))
if err != nil {
return nil, errors.Wrap(err, "Count")
}
updateHistoryEntries := make([]*IUpdateHistoryEntry, count)
for i := 0; i < int(count); i++ {
updateHistoryEntryDisp, err := oleconv.ToIDispatchErr(oleutil.GetProperty(updateHistoryEntriesDisp, "Item", i))
if err != nil {
return nil, errors.Wrapf(err, "item %d", i)
}
updateHistoryEntry, err := toIUpdateHistoryEntry(updateHistoryEntryDisp)
if err != nil {
return nil, errors.Wrap(err, "toIUpdateHistoryEntry")
}
updateHistoryEntries[i] = updateHistoryEntry
}
return updateHistoryEntries, nil
}
func toIUpdateHistoryEntry(updateHistoryEntryDisp *ole.IDispatch) (*IUpdateHistoryEntry, error) {
var err error
iUpdateHistoryEntry := &IUpdateHistoryEntry{
disp: updateHistoryEntryDisp,
}
if iUpdateHistoryEntry.ClientApplicationID, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "ClientApplicationID")); err != nil {
return nil, errors.Wrap(err, "ClientApplicationID")
}
if iUpdateHistoryEntry.Date, err = oleconv.ToTimeErr(oleutil.GetProperty(updateHistoryEntryDisp, "Date")); err != nil {
return nil, errors.Wrap(err, "Date")
}
if iUpdateHistoryEntry.Description, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "Description")); err != nil {
return nil, errors.Wrap(err, "Description")
}
if iUpdateHistoryEntry.HResult, err = oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntryDisp, "HResult")); err != nil {
return nil, errors.Wrap(err, "HResult")
}
if iUpdateHistoryEntry.Operation, err = oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntryDisp, "Operation")); err != nil {
return nil, errors.Wrap(err, "Operation")
}
if iUpdateHistoryEntry.ResultCode, err = oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntryDisp, "ResultCode")); err != nil {
return nil, errors.Wrap(err, "ResultCode")
}
if iUpdateHistoryEntry.ServerSelection, err = oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntryDisp, "ServerSelection")); err != nil {
return nil, errors.Wrap(err, "ServerSelection")
}
if iUpdateHistoryEntry.ServiceID, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "ServiceID")); err != nil {
return nil, errors.Wrap(err, "ServiceID")
}
if iUpdateHistoryEntry.SupportUrl, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "SupportUrl")); err != nil {
return nil, errors.Wrap(err, "SupportUrl")
}
if iUpdateHistoryEntry.Title, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "Title")); err != nil {
return nil, errors.Wrap(err, "Title")
}
if iUpdateHistoryEntry.UninstallationNotes, err = oleconv.ToStringErr(oleutil.GetProperty(updateHistoryEntryDisp, "UninstallationNotes")); err != nil {
return nil, errors.Wrap(err, "UninstallationNotes")
}
if iUpdateHistoryEntry.UninstallationSteps, err = oleconv.ToStringSliceErr(oleutil.GetProperty(updateHistoryEntryDisp, "UninstallationSteps")); err != nil {
return nil, errors.Wrap(err, "UninstallationSteps")
}
if iUpdateHistoryEntry.UnmappedResultCode, err = oleconv.ToInt32Err(oleutil.GetProperty(updateHistoryEntryDisp, "UnmappedResultCode")); err != nil {
return nil, errors.Wrap(err, "UnmappedResultCode")
}
updateIdentityDisp, err := oleconv.ToIDispatchErr(oleutil.GetProperty(updateHistoryEntryDisp, "UpdateIdentity"))
if err != nil {
return nil, errors.Wrap(err, "UpdateIdentity")
}
if updateIdentityDisp != nil {
if iUpdateHistoryEntry.UpdateIdentity, err = toIUpdateIdentity(updateIdentityDisp); err != nil {
return nil, errors.Wrap(err, "toIUpdateIdentity")
}
}
return iUpdateHistoryEntry, nil
}