]> git.r.bdr.sh - rbdr/mobius/blob - hotline/file_transfer.go
Add support for server banner
[rbdr/mobius] / hotline / file_transfer.go
1 package hotline
2
3 import (
4 "encoding/binary"
5 "fmt"
6 "path/filepath"
7 )
8
9 // File transfer types
10 const (
11 FileDownload = 0
12 FileUpload = 1
13 FolderDownload = 2
14 FolderUpload = 3
15 bannerDownload = 4
16 )
17
18 type FileTransfer struct {
19 FileName []byte
20 FilePath []byte
21 ReferenceNumber []byte
22 Type int
23 TransferSize []byte // total size of all items in the folder. Only used in FolderUpload action
24 FolderItemCount []byte
25 BytesSent int
26 clientID uint16
27 fileResumeData *FileResumeData
28 options []byte
29 }
30
31 func (ft *FileTransfer) String() string {
32 percentComplete := 10
33 out := fmt.Sprintf("%s\t %v", ft.FileName, percentComplete)
34
35 return out
36 }
37
38 func (ft *FileTransfer) ItemCount() int {
39 return int(binary.BigEndian.Uint16(ft.FolderItemCount))
40 }
41
42 type folderUpload struct {
43 DataSize [2]byte
44 IsFolder [2]byte
45 PathItemCount [2]byte
46 FileNamePath []byte
47 }
48
49 func (fu *folderUpload) FormattedPath() string {
50 pathItemLen := binary.BigEndian.Uint16(fu.PathItemCount[:])
51
52 var pathSegments []string
53 pathData := fu.FileNamePath
54
55 // TODO: implement scanner interface instead?
56 for i := uint16(0); i < pathItemLen; i++ {
57 segLen := pathData[2]
58 pathSegments = append(pathSegments, string(pathData[3:3+segLen]))
59 pathData = pathData[3+segLen:]
60 }
61
62 return filepath.Join(pathSegments...)
63 }