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