diff --git a/headers/build/os/storage/AppFileInfo.h b/headers/build/os/storage/AppFileInfo.h index 7694ef97af..235be9bb1b 100644 --- a/headers/build/os/storage/AppFileInfo.h +++ b/headers/build/os/storage/AppFileInfo.h @@ -58,6 +58,9 @@ public: status_t GetSignature(char *signature) const; status_t SetSignature(const char *signature); + status_t GetCatalogEntry(char *catalogEntry) const; + status_t SetCatalogEntry(const char *catalogEntry); + status_t GetAppFlags(uint32 *flags) const; status_t SetAppFlags(uint32 flags); diff --git a/headers/os/storage/AppFileInfo.h b/headers/os/storage/AppFileInfo.h index 0473b9ec8e..146db54b4f 100644 --- a/headers/os/storage/AppFileInfo.h +++ b/headers/os/storage/AppFileInfo.h @@ -64,6 +64,9 @@ class BAppFileInfo: public BNodeInfo { status_t GetSignature(char *signature) const; status_t SetSignature(const char *signature); + + status_t GetCatalogEntry(char *catalogEntry) const; + status_t SetCatalogEntry(const char *catalogEntry); status_t GetAppFlags(uint32 *flags) const; status_t SetAppFlags(uint32 flags); diff --git a/src/build/libbe/storage/AppFileInfo.cpp b/src/build/libbe/storage/AppFileInfo.cpp index f9dc4d2495..6ea04f461c 100644 --- a/src/build/libbe/storage/AppFileInfo.cpp +++ b/src/build/libbe/storage/AppFileInfo.cpp @@ -32,6 +32,7 @@ static const char *kVersionInfoAttribute = "BEOS:APP_VERSION"; static const char *kMiniIconAttribute = "BEOS:M:"; static const char *kLargeIconAttribute = "BEOS:L:"; static const char *kStandardIconType = "STD_ICON"; +static const char *kCatalogEntryAttribute = "SYS:NAME"; // resource IDs static const int32 kTypeResourceID = 2; @@ -43,6 +44,7 @@ static const int32 kLargeIconResourceID = 101; static const int32 kVersionInfoResourceID = 1; static const int32 kMiniIconForTypeResourceID = 0; static const int32 kLargeIconForTypeResourceID = 0; +static const int32 kCatalogEntryResourceID = 1; // type codes enum { @@ -308,6 +310,81 @@ BAppFileInfo::SetSignature(const char *signature) return error; } + +// GetCatalogEntry +/*! \brief Gets the file's catalog entry. (localization) + + \param catalogEntry A pointer to a pre-allocated character buffer of size + \c B_MIME_TYPE_LENGTH * 3 or larger into which the catalog entry + of the file shall be written. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \c NULL \a catalogEntry or the entry stored in the + attribute/resources is longer than \c B_MIME_TYPE_LENGTH * 3. + - \c B_BAD_TYPE: The attribute/resources the entry is stored in have + the wrong type. + - \c B_ENTRY_NOT_FOUND: No catalog entry is set on the file. + - other error codes +*/ +status_t +BAppFileInfo::GetCatalogEntry(char *catalogEntry) const +{ + if (catalogEntry == NULL) + return B_BAD_VALUE; + + if (InitCheck() != B_OK) + return B_NO_INIT; + + size_t read = 0; + status_t error = _ReadData(kCatalogEntryAttribute, kCatalogEntryResourceID, + B_STRING_TYPE, catalogEntry, B_MIME_TYPE_LENGTH * 3, read); + + if (error != B_OK) + return error; + + if (read >= B_MIME_TYPE_LENGTH * 3) + return B_ERROR; + + catalogEntry[read] = '\0'; + + return B_OK; +} + + +// SetCatalogEntry +/*! \brief Sets the file's catalog entry. (localization) + + If \a catalogEntry is \c NULL the file's catalog entry is unset. + + \param catalogEntry The catalog entry to be assigned to the file. + Of the form "x-vnd.Haiku-app:context:name". + Must not be longer than \c B_MIME_TYPE_LENGTH * 3 + (including the terminating null). May be \c NULL. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \a catalogEntry is longer than \c B_MIME_TYPE_LENGTH * 3. + - other error codes +*/ +status_t +BAppFileInfo::SetCatalogEntry(const char *catalogEntry) +{ + if (InitCheck() != B_OK) + return B_NO_INIT; + + if (catalogEntry == NULL) + return _RemoveData(kCatalogEntryAttribute, B_STRING_TYPE); + + size_t nameLength = strlen(catalogEntry); + if (nameLength > B_MIME_TYPE_LENGTH * 3) + return B_BAD_VALUE; + + return _WriteData(kCatalogEntryAttribute, kCatalogEntryResourceID, + B_STRING_TYPE, catalogEntry, nameLength + 1); +} + + // GetAppFlags /*! \brief Gets the file's application flags. diff --git a/src/build/libbe/storage/mime/UpdateMimeInfoThread.cpp b/src/build/libbe/storage/mime/UpdateMimeInfoThread.cpp index 61b33c5d78..d399787de8 100644 --- a/src/build/libbe/storage/mime/UpdateMimeInfoThread.cpp +++ b/src/build/libbe/storage/mime/UpdateMimeInfoThread.cpp @@ -269,6 +269,19 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) if (err != B_OK) return err; +/* TODO: figure out why this doesn't compile here + when the same code works in src/servers/registrar/mime + + // catalog entry + char catalogEntry[B_MIME_TYPE_LENGTH * 3]; + err = appFileInfoRead.GetCatalogEntry(catalogEntry); + if (err == B_OK) + err = appFileInfoWrite.SetCatalogEntry(catalogEntry); + else if (err == B_ENTRY_NOT_FOUND) + err = appFileInfoWrite.SetCatalogEntry(NULL); + if (err != B_OK) + return err; +*/ // app flags uint32 appFlags; err = appFileInfoRead.GetAppFlags(&appFlags); diff --git a/src/kits/storage/AppFileInfo.cpp b/src/kits/storage/AppFileInfo.cpp index 98c1890b76..2d66912e19 100644 --- a/src/kits/storage/AppFileInfo.cpp +++ b/src/kits/storage/AppFileInfo.cpp @@ -36,6 +36,7 @@ static const char *kLargeIconAttribute = "BEOS:L:"; static const char *kIconAttribute = "BEOS:"; static const char *kStandardIconType = "STD_ICON"; static const char *kIconType = "ICON"; +static const char *kCatalogEntryAttribute = "SYS:NAME"; // resource IDs static const int32 kTypeResourceID = 2; @@ -49,6 +50,7 @@ static const int32 kVersionInfoResourceID = 1; static const int32 kMiniIconForTypeResourceID = 0; static const int32 kLargeIconForTypeResourceID = 0; static const int32 kIconForTypeResourceID = 0; +static const int32 kCatalogEntryResourceID = 1; // type codes enum { @@ -328,6 +330,81 @@ BAppFileInfo::SetSignature(const char *signature) return error; } + +// GetCatalogEntry +/*! \brief Gets the file's catalog entry. (localization) + + \param catalogEntry A pointer to a pre-allocated character buffer of size + \c B_MIME_TYPE_LENGTH * 3 or larger into which the catalog entry + of the file shall be written. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \c NULL \a catalogEntry or the entry stored in the + attribute/resources is longer than \c B_MIME_TYPE_LENGTH * 3. + - \c B_BAD_TYPE: The attribute/resources the entry is stored in have + the wrong type. + - \c B_ENTRY_NOT_FOUND: No catalog entry is set on the file. + - other error codes +*/ +status_t +BAppFileInfo::GetCatalogEntry(char *catalogEntry) const +{ + if (catalogEntry == NULL) + return B_BAD_VALUE; + + if (InitCheck() != B_OK) + return B_NO_INIT; + + size_t read = 0; + status_t error = _ReadData(kCatalogEntryAttribute, kCatalogEntryResourceID, + B_STRING_TYPE, catalogEntry, B_MIME_TYPE_LENGTH * 3, read); + + if (error != B_OK) + return error; + + if (read >= B_MIME_TYPE_LENGTH * 3) + return B_ERROR; + + catalogEntry[read] = '\0'; + + return B_OK; +} + + +// SetCatalogEntry +/*! \brief Sets the file's catalog entry. (localization) + + If \a catalogEntry is \c NULL the file's catalog entry is unset. + + \param catalogEntry The catalog entry to be assigned to the file. + Of the form "x-vnd.Haiku-app:context:name". + Must not be longer than \c B_MIME_TYPE_LENGTH * 3 + (including the terminating null). May be \c NULL. + \return + - \c B_OK: Everything went fine. + - \c B_NO_INIT: The object is not properly initialized. + - \c B_BAD_VALUE: \a catalogEntry is longer than \c B_MIME_TYPE_LENGTH * 3. + - other error codes +*/ +status_t +BAppFileInfo::SetCatalogEntry(const char *catalogEntry) +{ + if (InitCheck() != B_OK) + return B_NO_INIT; + + if (catalogEntry == NULL) + return _RemoveData(kCatalogEntryAttribute, B_STRING_TYPE); + + size_t nameLength = strlen(catalogEntry); + if (nameLength > B_MIME_TYPE_LENGTH * 3) + return B_BAD_VALUE; + + return _WriteData(kCatalogEntryAttribute, kCatalogEntryResourceID, + B_STRING_TYPE, catalogEntry, nameLength + 1); +} + + // GetAppFlags /*! \brief Gets the file's application flags. diff --git a/src/servers/registrar/mime/UpdateMimeInfoThread.cpp b/src/servers/registrar/mime/UpdateMimeInfoThread.cpp index f3c3bd463c..243a5582db 100644 --- a/src/servers/registrar/mime/UpdateMimeInfoThread.cpp +++ b/src/servers/registrar/mime/UpdateMimeInfoThread.cpp @@ -149,6 +149,16 @@ UpdateMimeInfoThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) if (err != B_OK) return err; + // catalog entry + char catalogEntry[B_MIME_TYPE_LENGTH * 3]; + err = appFileInfoRead.GetCatalogEntry(catalogEntry); + if (err == B_OK) + err = appFileInfoWrite.SetCatalogEntry(catalogEntry); + else if (err == B_ENTRY_NOT_FOUND) + err = appFileInfoWrite.SetCatalogEntry(NULL); + if (err != B_OK) + return err; + // app flags uint32 appFlags; err = appFileInfoRead.GetAppFlags(&appFlags);