blob: 90dbbe669a2c9391afbb481f81f5c27bcded0eaa (
plain)
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
|
package hotline
import (
"encoding/binary"
"fmt"
"path/filepath"
)
// File transfer types
const (
FileDownload = 0
FileUpload = 1
FolderDownload = 2
FolderUpload = 3
)
type FileTransfer struct {
FileName []byte
FilePath []byte
ReferenceNumber []byte
Type int
TransferSize []byte // total size of all items in the folder. Only used in FolderUpload action
FolderItemCount []byte
BytesSent int
clientID uint16
fileResumeData *FileResumeData
options []byte
}
func (ft *FileTransfer) String() string {
percentComplete := 10
out := fmt.Sprintf("%s\t %v", ft.FileName, percentComplete)
return out
}
func (ft *FileTransfer) ItemCount() int {
return int(binary.BigEndian.Uint16(ft.FolderItemCount))
}
type folderUpload struct {
DataSize [2]byte
IsFolder [2]byte
PathItemCount [2]byte
FileNamePath []byte
}
func (fu *folderUpload) FormattedPath() string {
pathItemLen := binary.BigEndian.Uint16(fu.PathItemCount[:])
var pathSegments []string
pathData := fu.FileNamePath
// TODO: implement scanner interface instead?
for i := uint16(0); i < pathItemLen; i++ {
segLen := pathData[2]
pathSegments = append(pathSegments, string(pathData[3:3+segLen]))
pathData = pathData[3+segLen:]
}
return filepath.Join(pathSegments...)
}
|