-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathiinstallationjob.go
More file actions
86 lines (74 loc) · 2.9 KB
/
Copy pathiinstallationjob.go
File metadata and controls
86 lines (74 loc) · 2.9 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
/*
Copyright 2022 Zheng Dayu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package windowsupdate
import (
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
// IInstallationJob contains properties and methods that are available to an installation operation.
// https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nn-wuapi-iinstallationjob
type IInstallationJob struct {
disp *ole.IDispatch
AsyncState interface{}
IsCompleted bool
Updates []*IUpdate
}
func toIInstallationJob(disp *ole.IDispatch) (*IInstallationJob, error) {
if disp == nil {
return nil, nil
}
var err error
j := &IInstallationJob{disp: disp}
if j.IsCompleted, err = toBoolErr(oleutil.GetProperty(disp, "IsCompleted")); err != nil {
return nil, err
}
updatesDisp, err := toIDispatchErr(oleutil.GetProperty(disp, "Updates"))
if err != nil {
return nil, err
}
if updatesDisp != nil {
if j.Updates, err = toIUpdates(updatesDisp); err != nil {
return nil, err
}
}
return j, nil
}
// CleanUp releases the resources held by the installation job.
// https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-cleanup
func (j *IInstallationJob) CleanUp() error {
_, err := oleutil.CallMethod(j.disp, "CleanUp")
return err
}
// RequestAbort requests that the installation job be canceled.
// https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-requestabort
func (j *IInstallationJob) RequestAbort() error {
_, err := oleutil.CallMethod(j.disp, "RequestAbort")
return err
}
// GetIsCompleted reads the live IsCompleted property of the job. Unlike the
// IsCompleted struct field (captured once at construction time, hence always
// false right after BeginInstall), this reflects the current state and is the
// authoritative completion signal for the async installation.
// https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-get_iscompleted
func (j *IInstallationJob) GetIsCompleted() (bool, error) {
return toBoolErr(oleutil.GetProperty(j.disp, "IsCompleted"))
}
// GetProgress returns the current progress of the installation.
// https://learn.microsoft.com/en-us/windows/win32/api/wuapi/nf-wuapi-iinstallationjob-getprogress
func (j *IInstallationJob) GetProgress() (*IInstallationProgress, error) {
progressDisp, err := toIDispatchErr(oleutil.CallMethod(j.disp, "GetProgress"))
if err != nil {
return nil, err
}
return toIInstallationProgress(progressDisp)
}