This repository was archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_delete_from_device_test.go
More file actions
85 lines (70 loc) · 1.73 KB
/
example_delete_from_device_test.go
File metadata and controls
85 lines (70 loc) · 1.73 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
package gowpd_test
import (
"github.com/rlj1202/go-wpd"
"log"
)
func Example_deleteFromDevice() {
gowpd.Initialize()
mng, err := gowpd.CreatePortableDeviceManager()
if err != nil {
panic(err)
}
devices, err := mng.GetDevices()
if err != nil {
panic(err)
}
clientInfo, err := gowpd.CreatePortableDeviceValues()
if err != nil {
panic(err)
}
clientInfo.SetStringValue(gowpd.WPD_CLIENT_NAME, "libgowpd")
clientInfo.SetUnsignedIntegerValue(gowpd.WPD_CLIENT_MAJOR_VERSION, 1)
clientInfo.SetUnsignedIntegerValue(gowpd.WPD_CLIENT_MINOR_VERSION, 0)
clientInfo.SetUnsignedIntegerValue(gowpd.WPD_CLIENT_REVISION, 2)
// objectID which will be deleted from the device.
targetObjectID := "F:\\test.txt"
for _, id := range devices {
portableDevice, err := gowpd.CreatePortableDevice()
if err != nil {
panic(err)
}
err = portableDevice.Open(id, clientInfo)
if err != nil {
panic(err)
}
content, err := portableDevice.Content()
if err != nil {
panic(err)
}
pObjectsToDelete, err := gowpd.CreatePortableDevicePropVariantCollection()
pv := new(gowpd.PropVariant)
pv.Init()
pv.Set(targetObjectID)
err = pObjectsToDelete.Add(pv)
if err != nil {
panic(err)
}
results, err := content.Delete(gowpd.PORTABLE_DEVICE_DELETE_NO_RECURSION, pObjectsToDelete)
if err != nil {
count, err := results.GetCount()
if err != nil {
panic(err)
}
log.Printf("Count: %d\n", count)
result, err := results.GetAt(0)
if err != nil {
panic(err)
}
log.Printf("Type: %d\n", result.GetType())
if result.GetType() == gowpd.VT_ERROR {
log.Printf("error: %#x\n", result.GetError())
}
panic(err)
}
pv.Clear()
gowpd.FreeDeviceID(id)
}
mng.Release()
gowpd.Uninitialize()
// Output:
}