From b7aa23f1635e3ed2af529eb17e8eba8111167c25 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 26 Dec 2014 16:31:03 -0500 Subject: [PATCH] SetFinderInfo for filetype/creator --- toolbox/os_highlevel.cpp | 19 +------------------ toolbox/os_internal.cpp | 18 ++++++++++++++++++ toolbox/os_internal.h | 2 ++ toolbox/rm.cpp | 16 +--------------- 4 files changed, 22 insertions(+), 33 deletions(-) diff --git a/toolbox/os_highlevel.cpp b/toolbox/os_highlevel.cpp index c80e5fd..74738b2 100644 --- a/toolbox/os_highlevel.cpp +++ b/toolbox/os_highlevel.cpp @@ -278,24 +278,7 @@ namespace OS { ::close(fd); } - { - char buffer[32]; - std::memset(buffer, 0, sizeof(buffer)); - buffer[0] = fileType >> 24; - buffer[1] = fileType >> 16; - buffer[2] = fileType >> 8; - buffer[3] = fileType >> 0; - - buffer[4] = creator >> 24; - buffer[5] = creator >> 16; - buffer[6] = creator >> 8; - buffer[7] = creator >> 0; - - std::memcpy(buffer+4, &creator, 4); - // since this is a new file, set the entire finder info. - d0 = OS::Internal::SetFinderInfo(sname, buffer, true); - } - + d0 = OS::Internal::SetFinderInfo(sname, fileType, creator); return d0; } diff --git a/toolbox/os_internal.cpp b/toolbox/os_internal.cpp index af624eb..94786cc 100644 --- a/toolbox/os_internal.cpp +++ b/toolbox/os_internal.cpp @@ -220,6 +220,24 @@ namespace OS { namespace Internal { return 0; } + uint16_t SetFinderInfo(const std::string &pathName, uint32_t fileType, uint32_t creator) + { + uint8_t buffer[32]; + std::memset(buffer, 0, sizeof(buffer)); + + buffer[0] = fileType >> 24; + buffer[1] = fileType >> 16; + buffer[2] = fileType >> 8; + buffer[3] = fileType >> 0; + + buffer[4] = creator >> 24; + buffer[5] = creator >> 16; + buffer[6] = creator >> 8; + buffer[7] = creator >> 0; + + return SetFinderInfo(pathName, buffer, true); + } + uint16_t SetFinderInfo(const std::string &pathName, void *info, bool extended) { uint8_t buffer[32]; diff --git a/toolbox/os_internal.h b/toolbox/os_internal.h index c9dbef3..9ae43d0 100644 --- a/toolbox/os_internal.h +++ b/toolbox/os_internal.h @@ -9,6 +9,8 @@ namespace OS { namespace Internal { uint16_t GetFinderInfo(const std::string &pathname, void *info, bool extended); uint16_t SetFinderInfo(const std::string &pathname, void *info, bool extended); + uint16_t SetFinderInfo(const std::string &pathName, uint32_t fileType, uint32_t creator); + uint16_t GetFileType(const std::string &pathname, uint16_t *fileType, uint32_t *auxType); int32_t mac_seek(uint16_t refNum, uint16_t mode, int32_t offset); diff --git a/toolbox/rm.cpp b/toolbox/rm.cpp index 25a1289..e327f90 100644 --- a/toolbox/rm.cpp +++ b/toolbox/rm.cpp @@ -537,21 +537,7 @@ namespace RM // therefore, if no error, set the ftype/ctype. if (rv.error() == 0) { - char buffer[32]; - std::memset(buffer, 0, sizeof(buffer)); - buffer[0] = fileType >> 24; - buffer[1] = fileType >> 16; - buffer[2] = fileType >> 8; - buffer[3] = fileType >> 0; - - buffer[4] = creator >> 24; - buffer[5] = creator >> 16; - buffer[6] = creator >> 8; - buffer[7] = creator >> 0; - - std::memcpy(buffer+4, &creator, 4); - // this is a new file, set the full finder info. - OS::Internal::SetFinderInfo(sname, buffer, true); + OS::Internal::SetFinderInfo(sname, fileType, creator); } return SetResError(rv.error() == errFSForkExists ? 0 : rv.error());