-
Notifications
You must be signed in to change notification settings - Fork 22
/
types_download_item.go
313 lines (273 loc) · 7.25 KB
/
types_download_item.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/common/imports"
"github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl/api"
"time"
"unsafe"
)
// DownloadItemRef -> ICefDownloadItem
var DownloadItemRef downloadItem
// downloadItem
type downloadItem uintptr
func (*downloadItem) UnWrap(data *ICefDownloadItem) *ICefDownloadItem {
var result uintptr
imports.Proc(def.CefDownloadItemRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
if result == 0 {
return nil
}
data.base.Free(data.Instance())
data.instance = getInstance(result)
return data
}
func (m *ICefDownloadItem) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ICefDownloadItem) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsValid).Call(m.Instance())
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsInProgress() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsInProgress).Call(m.Instance())
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsComplete() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsComplete).Call(m.Instance())
return api.GoBool(r1)
}
func (m *ICefDownloadItem) IsCanceled() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsCanceled).Call(m.Instance())
return api.GoBool(r1)
}
// IsInterrupted
// CEF 114 ~
func (m *ICefDownloadItem) IsInterrupted() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CefDownloadItem_IsInterrupted).Call(m.Instance())
return api.GoBool(r1)
}
// GetInterruptReason
// CEF 114 ~
func (m *ICefDownloadItem) GetInterruptReason() consts.TCefDownloadInterruptReason {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_GetInterruptReason).Call(m.Instance())
return consts.TCefDownloadInterruptReason(r1)
}
func (m *ICefDownloadItem) CurrentSpeed() int64 {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_CurrentSpeed).Call(m.Instance())
return int64(r1)
}
func (m *ICefDownloadItem) PercentComplete() int32 {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_PercentComplete).Call(m.Instance())
return int32(r1)
}
func (m *ICefDownloadItem) TotalBytes() int64 {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_TotalBytes).Call(m.Instance())
return int64(r1)
}
func (m *ICefDownloadItem) ReceivedBytes() int64 {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_ReceivedBytes).Call(m.Instance())
return int64(r1)
}
func (m *ICefDownloadItem) StartTime() time.Time {
if !m.IsValid() {
return time.Time{}
}
var result uintptr
imports.Proc(def.CefDownloadItem_StartTime).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return common.DDateTimeToGoDateTime(*(*float64)(unsafe.Pointer(result)))
}
func (m *ICefDownloadItem) EndTime() time.Time {
if !m.IsValid() {
return time.Time{}
}
var result uintptr
imports.Proc(def.CefDownloadItem_EndTime).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return common.DDateTimeToGoDateTime(*(*float64)(unsafe.Pointer(result)))
}
func (m *ICefDownloadItem) FullPath() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_FullPath).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefDownloadItem) Id() uint32 {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CefDownloadItem_Id).Call(m.Instance())
return uint32(r1)
}
func (m *ICefDownloadItem) Url() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_Url).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefDownloadItem) OriginalUrl() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_OriginalUrl).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefDownloadItem) SuggestedFileName() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_SuggestedFileName).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefDownloadItem) ContentDisposition() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_ContentDisposition).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefDownloadItem) MimeType() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CefDownloadItem_MimeType).Call(m.Instance())
return api.GoStr(r1)
}
//State 下载状态 -1:下载之前 0:下载中 1:下载取消 2:下载完成
func (m *ICefDownloadItem) State() int32 {
if !m.IsValid() {
return 0
}
if m.IsComplete() {
return 2
} else if m.IsCanceled() {
return 1
} else if m.IsInProgress() {
return 0
} else {
return -1
}
}
func (m *ICefDownloadItem) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
// DownloadItemCallbackRef => ICefDownloadItemCallback
var DownloadItemCallbackRef downloadItemCallback
type downloadItemCallback uintptr
func (*downloadItemCallback) UnWrap(data *ICefDownloadItemCallback) *ICefDownloadItemCallback {
var result uintptr
imports.Proc(def.CefDownloadItemCallbackRef_Pause).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefDownloadItemCallback{instance: unsafe.Pointer(result)}
}
func (m *ICefDownloadItemCallback) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ICefDownloadItemCallback) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
/*
Cancel 取消下载 仅在回调函数中使用
*/
func (m *ICefDownloadItemCallback) Cancel() {
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Cancel).Call(m.Instance())
}
/*
Pause 暂停 仅在回调函数中使用
*/
func (m *ICefDownloadItemCallback) Pause() {
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Pause).Call(m.Instance())
}
/*
Resume 恢复下载 仅在回调函数中使用
*/
func (m *ICefDownloadItemCallback) Resume() {
if !m.IsValid() {
return
}
imports.Proc(def.CefDownloadItemCallback_Resume).Call(m.Instance())
}
func (m *ICefDownloadItemCallback) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
func (m *ICefBeforeDownloadCallback) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ICefBeforeDownloadCallback) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
// Cont
// 设置下载目录 仅在回调函数中使用
//
// downloadPath 设置完整的下载目录, 包含文件名
//
// showDialog 弹出保存目录窗口
func (m *ICefBeforeDownloadCallback) Cont(downloadPath string, showDialog bool) {
if !m.IsValid() {
return
}
imports.Proc(def.CefBeforeDownloadCallback_Cont).Call(m.Instance(), api.PascalStr(downloadPath), api.PascalBool(showDialog))
}
func (m *ICefBeforeDownloadCallback) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}