From 04c26f3c9bf2459fce6166915fd8722508c7028a Mon Sep 17 00:00:00 2001 From: Tyler Dauwalder Date: Tue, 1 Oct 2002 07:26:57 +0000 Subject: [PATCH] Finished implementation git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1326 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../storage/mime/CreateAppMetaMimeThread.cpp | 76 ++++++++++--------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/kits/storage/mime/CreateAppMetaMimeThread.cpp b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp index d84b5449c4..b67f23b8a3 100644 --- a/src/kits/storage/mime/CreateAppMetaMimeThread.cpp +++ b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp @@ -17,6 +17,8 @@ #include #include +#include + namespace BPrivate { namespace Storage { namespace Mime { @@ -31,55 +33,61 @@ status_t CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) { status_t err = entry ? B_OK : B_BAD_VALUE; - bool doUpdate = false; BNode node; BString sig; + BMimeType mime; + BPath path; + attr_info info; + BBitmap miniIcon(BRect(0,0,15,15), B_CMAP8); + BNode typeNode; if (!err) err = node.SetTo(entry); - // Read the app sig (which consequently keeps us from updating non-applications) + if (!err && entryIsDir) + *entryIsDir = node.IsDirectory(); + // Read the app sig (which consequently keeps us from updating + // non-applications, since we get an error if the file has no + // app sig) if (!err) err = node.ReadAttrString("BEOS:APP_SIG", &sig); - if (!err && !fForce) { - // If not forced, only update if the entry has no file type attribute -// attr_info info; -// if (!err) -// doUpdate = node.GetAttrInfo(kFileTypeAttr, &info) == B_ENTRY_NOT_FOUND; - } - if (!err && doUpdate) { - BMimeType mime; - BPath path; - attr_info info; - BBitmap miniIcon(BRect(0,0,15,15), B_CMAP8); - + if (!err) { // Init our various objects err = mime.SetTo(sig.String()); - if (!err) + if (!err && !mime.IsInstalled()) + mime.Install(); + if (!err) { + char metaMimePath[B_PATH_NAME_LENGTH]; + sprintf(metaMimePath, "%s/%s", kDatabaseDir.c_str(), sig.String()); + err = typeNode.SetTo(metaMimePath); + } + if (!err) err = path.SetTo(entry); // Preferred App - if (!err) + if (!err && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) == B_ENTRY_NOT_FOUND)) { err = mime.SetPreferredApp(sig.String()); - // Short Description - if (!err) - err = mime.SetShortDescription(path.Leaf()); - // App Hint - if (!err) - err = mime.SetAppHint(entry); - // Mini icon - if (!err) - err = node.GetAttrInfo("BEOS:M:STD_ICON", &info); - if (!err) - err = info.size == 16*16 ? B_OK : B_BAD_VALUE; - if (!err) { - ssize_t bytes = node.ReadAttr("BEOS:M:STD_ICON", kMiniIconType, 0, miniIcon.Bits(), 16*16); - err = bytes == 16*16 ? B_OK : B_FILE_ERROR; } - if (!err) - err = mime.SetIcon(&miniIcon, B_MINI_ICON); + // Short Description + if (!err && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) == B_ENTRY_NOT_FOUND)) { + err = mime.SetShortDescription(path.Leaf()); + } + // App Hint + if (!err && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) == B_ENTRY_NOT_FOUND)) { + err = mime.SetAppHint(entry); + } + // Mini icon + if (!err && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) == B_ENTRY_NOT_FOUND)) { + err = node.GetAttrInfo("BEOS:M:STD_ICON", &info); + if (!err) + err = info.size == 16*16 ? B_OK : B_BAD_VALUE; + if (!err) { + ssize_t bytes = node.ReadAttr("BEOS:M:STD_ICON", kMiniIconType, 0, miniIcon.Bits(), 16*16); + err = bytes == 16*16 ? B_OK : B_FILE_ERROR; + } + if (!err) + err = mime.SetIcon(&miniIcon, B_MINI_ICON); + } } - if (!err && entryIsDir) - *entryIsDir = node.IsDirectory(); return err; }