}
d := map[string]interface{}{
"Name": info.Name,
+ "Name.Utf8": info.NameUtf8,
"NumPieces": info.NumPieces(),
"PieceLength": info.PieceLength,
"InfoHash": metainfo.HashInfoBytes().HexString(),
type FileInfo struct {
Length int64 `bencode:"length"` // BEP3
Path []string `bencode:"path"` // BEP3
- PathUTF8 []string `bencode:"path.utf-8,omitempty"`
+ PathUtf8 []string `bencode:"path.utf-8,omitempty"`
}
func (fi *FileInfo) DisplayPath(info *Info) string {
if info.IsDir() {
- return strings.Join(fi.Path, "/")
+ return strings.Join(fi.BestPath(), "/")
} else {
- return info.Name
+ return info.BestName()
}
}
}
panic("not found")
}
+
+func (fi FileInfo) BestPath() []string {
+ if len(fi.PathUtf8) != 0 {
+ return fi.PathUtf8
+ }
+ return fi.Path
+}
func (info *Info) Piece(index int) Piece {
return Piece{info, pieceIndex(index)}
}
+
+func (info Info) BestName() string {
+ if info.NameUtf8 != "" {
+ return info.NameUtf8
+ }
+ return info.Name
+}
var offset int64
t.files = new([]*File)
for _, fi := range t.info.UpvertedFiles() {
- var path []string
- if len(fi.PathUTF8) != 0 {
- path = fi.PathUTF8
- } else {
- path = fi.Path
- }
- dp := t.info.Name
- if len(fi.Path) != 0 {
- dp = strings.Join(fi.Path, "/")
- }
*t.files = append(*t.files, &File{
t,
- strings.Join(append([]string{t.info.Name}, path...), "/"),
+ strings.Join(append([]string{t.info.BestName()}, fi.BestPath()...), "/"),
offset,
fi.Length,
fi,
- dp,
+ fi.DisplayPath(t.info),
PiecePriorityNone,
})
offset += fi.Length