-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstruct.go
92 lines (71 loc) · 1.55 KB
/
struct.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
// struct.go
package main
import (
"fmt"
"path/filepath"
"strconv"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
type MyPage struct {
local location
remote location
page TabPage
}
type location struct {
Tv *walk.TableView
Tl *walk.LineEdit
Model *FileModel
}
func (l location) Refresh() {
l.Model.SetDirPath(l.Tl.Text())
}
func (l location) Hidden() {
l.SetHidden(true)
l.Refresh()
}
func (l location) Show() {
l.SetHidden(false)
l.Refresh()
}
func (l location) SetHidden(hidden bool) {
l.Model.hidden = hidden
}
func (p MyPage) Send() error {
fmt.Println("Link:", p.remote.Model.remote.IP)
p.remote.Model.remote.Link()
info := p.local.Model.items[p.local.Tv.CurrentIndex()]
var localPath = filepath.Join(p.local.Tl.Text(), info.Name)
var remotePath = p.remote.Tl.Text()
return p.remote.Model.remote.Upload(localPath, remotePath)
}
func (p MyPage) Recv() error {
fmt.Println("Link:", p.remote.Model.remote.IP)
p.remote.Model.remote.Link()
info := p.remote.Model.items[p.remote.Tv.CurrentIndex()]
var localPath = p.local.Tl.Text()
var remotePath = p.remote.Tl.Text() + "/" + info.Name
p.remote.Model.remote.Download(remotePath, localPath)
fmt.Println("recv file from remote server finished!")
return nil
}
func formatSize(size int64) string {
if size < 1024 {
return strconv.FormatInt(size, 10) + " B"
}
s := float64(size)
d := "B"
if s >= 1024 {
s = s / 1024.0
d = "K"
}
if s >= 1024 {
s = s / 1024.0
d = "M"
}
if s >= 1024 {
s = s / 1024.0
d = "G"
}
return fmt.Sprintf("%.1f %s", s, d)
}