use path.utf8 first for some torrent (#350)

This commit is contained in:
Yates 2019-12-08 17:35:40 +08:00 committed by Matt Joiner
parent 6e95274413
commit 790ba6af3c
2 changed files with 10 additions and 3 deletions

View File

@ -4,8 +4,9 @@ import "strings"
// Information specific to a single file inside the MetaInfo structure. // Information specific to a single file inside the MetaInfo structure.
type FileInfo struct { type FileInfo struct {
Length int64 `bencode:"length"` Length int64 `bencode:"length"`
Path []string `bencode:"path"` Path []string `bencode:"path"`
PathUTF8 []string `bencode:"path.utf-8,omitempty"`
} }
func (fi *FileInfo) DisplayPath(info *Info) string { func (fi *FileInfo) DisplayPath(info *Info) string {

8
t.go
View File

@ -189,9 +189,15 @@ func (t *Torrent) initFiles() {
var offset int64 var offset int64
t.files = new([]*File) t.files = new([]*File)
for _, fi := range t.info.UpvertedFiles() { for _, fi := range t.info.UpvertedFiles() {
var path []string
if len(fi.PathUTF8) != 0 {
path = fi.PathUTF8
} else {
path = fi.Path
}
*t.files = append(*t.files, &File{ *t.files = append(*t.files, &File{
t, t,
strings.Join(append([]string{t.info.Name}, fi.Path...), "/"), strings.Join(append([]string{t.info.Name}, path...), "/"),
offset, offset,
fi.Length, fi.Length,
fi, fi,