X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/blobdiff_plain/43ecc0f42eaeface5f640479df7372bfb8021f23..d492c46d7e2087114d25f64823de9027592d5fc4:/hotline/files.go diff --git a/hotline/files.go b/hotline/files.go index 1db698b..0c23334 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -43,9 +43,7 @@ func fileCreatorFromFilename(fn string) string { return code } -func getFileNameList(filePath string) ([]Field, error) { - var fields []Field - +func getFileNameList(filePath string) (fields []Field, err error) { files, err := ioutil.ReadDir(filePath) if err != nil { return fields, nil @@ -53,13 +51,16 @@ func getFileNameList(filePath string) ([]Field, error) { for _, file := range files { var fileType []byte + var fnwi FileNameWithInfo fileCreator := make([]byte, 4) - fileSize := make([]byte, 4) + //fileSize := make([]byte, 4) if !file.IsDir() { fileType = []byte(fileTypeFromFilename(file.Name())) fileCreator = []byte(fileCreatorFromFilename(file.Name())) - binary.BigEndian.PutUint32(fileSize, uint32(file.Size())) + binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(file.Size())) + copy(fnwi.Type[:], fileType[:]) + copy(fnwi.Creator[:], fileCreator[:]) } else { fileType = []byte("fldr") @@ -67,19 +68,22 @@ func getFileNameList(filePath string) ([]Field, error) { if err != nil { return fields, err } - binary.BigEndian.PutUint32(fileSize, uint32(len(dir))) + binary.BigEndian.PutUint32(fnwi.FileSize[:], uint32(len(dir))) + copy(fnwi.Type[:], fileType[:]) + copy(fnwi.Creator[:], fileCreator[:]) } - fields = append(fields, NewField( - fieldFileNameWithInfo, - FileNameWithInfo{ - Type: fileType, - Creator: fileCreator, - FileSize: fileSize, - NameScript: []byte{0, 0}, - Name: []byte(file.Name()), - }.Payload(), - )) + nameSize := make([]byte, 2) + binary.BigEndian.PutUint16(nameSize, uint16(len(file.Name()))) + copy(fnwi.NameSize[:], nameSize[:]) + + fnwi.name = []byte(file.Name()) + + b, err := fnwi.MarshalBinary() + if err != nil { + return nil, err + } + fields = append(fields, NewField(fieldFileNameWithInfo, b)) } return fields, nil @@ -148,8 +152,3 @@ func EncodeFilePath(filePath string) []byte { return bytes } - -func ReadFilePath(filePathFieldData []byte) string { - fp := NewFilePath(filePathFieldData) - return fp.String() -}