From: Jeff Halter Date: Sun, 5 Jun 2022 23:43:51 +0000 (-0700) Subject: Implement some special case file descriptions X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/2d52424e94e617627e4438fd207ee94949409328?ds=inline;hp=--cc Implement some special case file descriptions --- 2d52424e94e617627e4438fd207ee94949409328 diff --git a/hotline/file_types.go b/hotline/file_types.go index ae4bd36..e9f45bb 100644 --- a/hotline/file_types.go +++ b/hotline/file_types.go @@ -1,10 +1,8 @@ package hotline type fileType struct { - TypeCode string // 4 byte type code used in file transfers - CreatorCode string // 4 byte creator code used in file transfers - CreatorString string // variable length string used in file get info - FileTypeString string // variable length string used in file get info + TypeCode string // 4 byte type code used in file transfers + CreatorCode string // 4 byte creator code used in file transfers } var defaultFileType = fileType{ @@ -62,3 +60,12 @@ var fileTypes = map[string]fileType{ CreatorCode: "HTLC", }, } + +// A small number of type codes are displayed in the GetInfo window with a friendly name instead of the 4 letter code +var friendlyCreatorNames = map[string]string{ + "fldr": "Folder", + "flda": "Folder Alias", + "HTft": "Incomplete File", + "SIT!": "StuffIt Archive", + "TEXT": "Text File", +} diff --git a/hotline/files.go b/hotline/files.go index 478041b..7c2cd1a 100644 --- a/hotline/files.go +++ b/hotline/files.go @@ -27,6 +27,17 @@ func fileTypeFromFilename(fn string) fileType { return defaultFileType } +func fileTypeFromInfo(info os.FileInfo) (ft fileType, err error) { + if info.IsDir() { + ft.CreatorCode = "n/a " + ft.TypeCode = "fldr" + } else { + ft = fileTypeFromFilename(info.Name()) + } + + return ft, nil +} + func getFileNameList(filePath string) (fields []Field, err error) { files, err := ioutil.ReadDir(filePath) if err != nil { diff --git a/hotline/flattened_file_object.go b/hotline/flattened_file_object.go index a43677b..6b8d3d9 100644 --- a/hotline/flattened_file_object.go +++ b/hotline/flattened_file_object.go @@ -55,15 +55,15 @@ type FlatFileInformationFork struct { Comment []byte // File comment } -func NewFlatFileInformationFork(fileName string, modifyTime []byte) FlatFileInformationFork { +func NewFlatFileInformationFork(fileName string, modifyTime []byte, typeSignature string, creatorSignature string) FlatFileInformationFork { return FlatFileInformationFork{ - Platform: []byte("AMAC"), // TODO: Remove hardcode to support "AWIN" Platform (maybe?) - TypeSignature: []byte(fileTypeFromFilename(fileName).TypeCode), // TODO: Don't infer types from filename - CreatorSignature: []byte(fileTypeFromFilename(fileName).CreatorCode), // TODO: Don't infer types from filename - Flags: []byte{0, 0, 0, 0}, // TODO: What is this? - PlatformFlags: []byte{0, 0, 1, 0}, // TODO: What is this? - RSVD: make([]byte, 32), // Unimplemented in Hotline Protocol - CreateDate: modifyTime, // some filesystems don't support createTime + Platform: []byte("AMAC"), // TODO: Remove hardcode to support "AWIN" Platform (maybe?) + TypeSignature: []byte(typeSignature), // TODO: Don't infer types from filename + CreatorSignature: []byte(creatorSignature), // TODO: Don't infer types from filename + Flags: []byte{0, 0, 0, 0}, // TODO: What is this? + PlatformFlags: []byte{0, 0, 1, 0}, // TODO: What is this? + RSVD: make([]byte, 32), // Unimplemented in Hotline Protocol + CreateDate: modifyTime, // some filesystems don't support createTime ModifyDate: modifyTime, NameScript: make([]byte, 2), // TODO: What is this? Name: []byte(fileName), @@ -72,6 +72,14 @@ func NewFlatFileInformationFork(fileName string, modifyTime []byte) FlatFileInfo } } +func (ffif *FlatFileInformationFork) friendlyType() []byte { + + if name, ok := friendlyCreatorNames[string(ffif.TypeSignature)]; ok { + return []byte(name) + } + return ffif.CreatorSignature +} + // DataSize calculates the size of the flat file information fork, which is // 72 bytes for the fixed length fields plus the length of the Name + Comment func (ffif *FlatFileInformationFork) DataSize() []byte { @@ -195,9 +203,11 @@ func NewFlattenedFileObject(fileRoot string, filePath, fileName []byte, dataOffs mTime := toHotlineTime(fileInfo.ModTime()) + ft, _ := fileTypeFromInfo(fileInfo) + return &flattenedFileObject{ FlatFileHeader: NewFlatFileHeader(), - FlatFileInformationFork: NewFlatFileInformationFork(string(fileName), mTime), + FlatFileInformationFork: NewFlatFileInformationFork(string(fileName), mTime, ft.TypeCode, ft.CreatorCode), FlatFileDataForkHeader: FlatFileDataForkHeader{ ForkType: [4]byte{0x44, 0x41, 0x54, 0x41}, // "DATA" CompressionType: [4]byte{}, diff --git a/hotline/flattened_file_object_test.go b/hotline/flattened_file_object_test.go index 1d43818..656af68 100644 --- a/hotline/flattened_file_object_test.go +++ b/hotline/flattened_file_object_test.go @@ -30,7 +30,7 @@ func TestNewFlattenedFileObject(t *testing.T) { want: &flattenedFileObject{ FlatFileHeader: NewFlatFileHeader(), FlatFileInformationForkHeader: FlatFileInformationForkHeader{}, - FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8)), + FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8), "", ""), FlatFileDataForkHeader: FlatFileDataForkHeader{ ForkType: [4]byte{0x4d, 0x41, 0x43, 0x52}, // DATA CompressionType: [4]byte{0, 0, 0, 0}, diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index abe2c54..5dc2be5 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -419,7 +419,7 @@ func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e res = append(res, cc.NewReply(t, NewField(fieldFileName, fileName), - NewField(fieldFileTypeString, ffo.FlatFileInformationFork.TypeSignature), + NewField(fieldFileTypeString, ffo.FlatFileInformationFork.friendlyType()), NewField(fieldFileCreatorString, ffo.FlatFileInformationFork.CreatorSignature), NewField(fieldFileComment, ffo.FlatFileInformationFork.Comment), NewField(fieldFileType, ffo.FlatFileInformationFork.TypeSignature), diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 9165a66..6ff8cf1 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -649,7 +649,7 @@ func TestHandleGetFileInfo(t *testing.T) { ErrorCode: []byte{0, 0, 0, 0}, Fields: []Field{ NewField(fieldFileName, []byte("testfile.txt")), - NewField(fieldFileTypeString, []byte("TEXT")), + NewField(fieldFileTypeString, []byte("Text File")), NewField(fieldFileCreatorString, []byte("ttxt")), NewField(fieldFileComment, []byte{}), NewField(fieldFileType, []byte("TEXT")), diff --git a/hotline/transfer_test.go b/hotline/transfer_test.go index 23b30ef..255d914 100644 --- a/hotline/transfer_test.go +++ b/hotline/transfer_test.go @@ -121,7 +121,7 @@ func Test_receiveFile(t *testing.T) { testFile := flattenedFileObject{ FlatFileHeader: NewFlatFileHeader(), FlatFileInformationForkHeader: FlatFileInformationForkHeader{}, - FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8)), + FlatFileInformationFork: NewFlatFileInformationFork("testfile.txt", make([]byte, 8), "TEXT", "TEXT"), FlatFileDataForkHeader: FlatFileDataForkHeader{ ForkType: [4]byte{0x4d, 0x41, 0x43, 0x52}, // DATA CompressionType: [4]byte{0, 0, 0, 0},