diff --git a/src/kits/storage/mime/CreateAppMetaMimeThread.cpp b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp index c7f441ec85..79696e9976 100644 --- a/src/kits/storage/mime/CreateAppMetaMimeThread.cpp +++ b/src/kits/storage/mime/CreateAppMetaMimeThread.cpp @@ -67,9 +67,6 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir) if (status < B_OK) return B_BAD_TYPE; - signature.ToLower(); - // Signatures and MIME types are case insensitive - // Init our various objects BMimeType mime; @@ -80,6 +77,9 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir) if (!mime.IsInstalled()) mime.Install(); + signature.ToLower(); + // Signatures and MIME types are case insensitive + char metaMimePath[B_PATH_NAME_LENGTH]; sprintf(metaMimePath, "%s/%s", kDatabaseDir.c_str(), signature.String()); diff --git a/src/kits/storage/mime/SupportingApps.cpp b/src/kits/storage/mime/SupportingApps.cpp index cce6a7f21d..b9609b7450 100644 --- a/src/kits/storage/mime/SupportingApps.cpp +++ b/src/kits/storage/mime/SupportingApps.cpp @@ -101,7 +101,7 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps) if (!err) err = superMime.InitCheck(); if (!err) { - std::set &superApps = fSupportingApps[type]; + std::set &superApps = fSupportingApps[superMime.Type()]; count = 0; for (i = superApps.begin(); i != superApps.end() && !err; i++) { if (subApps.find(*i) == subApps.end()) { @@ -263,54 +263,54 @@ SupportingApps::BuildSupportingAppsTable() fStrandedTypes.clear(); BDirectory dir; - status_t err = dir.SetTo(kApplicationDatabaseDir.c_str()); + status_t status = dir.SetTo(kApplicationDatabaseDir.c_str()); // Build the supporting apps table based on the mime database - if (!err) { + if (status == B_OK) { dir.Rewind(); // Handle each application type while (true) { entry_ref ref; - err = dir.GetNextRef(&ref); - if (err) { + status = dir.GetNextRef(&ref); + if (status < B_OK) { // If we've come to the end of list, it's not an error - if (err == B_ENTRY_NOT_FOUND) - err = B_OK; + if (status == B_ENTRY_NOT_FOUND) + status = B_OK; break; - } else { - BPath path; - BMessage msg; - char appSig[B_PATH_NAME_LENGTH]; - err = path.SetTo(&ref); - if (!err) { - // Construct a mime type string - const char *appName = path.Leaf(); - sprintf(appSig, "application/%s", appName); - - // Read in the list of supported types - if (read_mime_attr_message(appSig, kSupportedTypesAttr, &msg) == B_OK) { - // Iterate through the supported types, adding them to the list of - // supported types for the application and adding the application's - // signature to the list of supporting apps for each type - BString type; - std::set &supportedTypes = fSupportedTypes[appName]; - for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) { - type.ToLower(); - // MIME types are case insensitive, so we lowercase everything - supportedTypes.insert(type.String()); - AddSupportingApp(type.String(), appSig); - } - } - } } - } + + // read application signature from file + BString appSignature; + BNode node(&ref); + if (node.InitCheck() == B_OK && node.ReadAttrString(kTypeAttr, + &appSignature) >= B_OK) { + // Read in the list of supported types + BMessage msg; + if (read_mime_attr_message(appSignature.String(), kSupportedTypesAttr, + &msg) == B_OK) { + // Iterate through the supported types, adding them to the list of + // supported types for the application and adding the application's + // signature to the list of supporting apps for each type + BString type; + std::set &supportedTypes = fSupportedTypes[appSignature.String()]; + for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) { + type.ToLower(); + // MIME types are case insensitive, so we lowercase everything + supportedTypes.insert(type.String()); + AddSupportingApp(type.String(), appSignature.String()); + } + } + } + } } - if (err) - DBG(OUT("Mime::SupportingApps::BuildSupportingAppsTable() failed, error code == 0x%lx\n", err)); - else + + if (status == B_OK) fHaveDoneFullBuild = true; - return err; + else + DBG(OUT("SupportingApps::BuildSupportingAppsTable() failed: %s\n", strerror(status))); + + return status; } } // namespace Mime diff --git a/src/kits/storage/mime/database_support.cpp b/src/kits/storage/mime/database_support.cpp index 881682e840..20caaf74b9 100644 --- a/src/kits/storage/mime/database_support.cpp +++ b/src/kits/storage/mime/database_support.cpp @@ -136,10 +136,23 @@ type_to_filename(const char *type) status_t open_type(const char *type, BNode *result) { - status_t err = (type && result ? B_OK : B_BAD_VALUE); - if (!err) - err = result->SetTo(type_to_filename(type).c_str()); - return err; + if (type == NULL || result == NULL) + return B_BAD_VALUE; + + status_t status = result->SetTo(type_to_filename(type).c_str()); + + // TODO: this can be removed again later - we just didn't write this + // attribute is before at all... +#if 1 + if (status == B_OK) { + // check if the MIME:TYPE attribute exist, and create it if not + attr_info info; + if (result->GetAttrInfo(kTypeAttr, &info) != B_OK) + result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1); + } +#endif + + return status; } // open_or_create_type @@ -184,9 +197,14 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate) err = parent.CreateFile(sub.c_str(), NULL); } // Now try opening again - err = result->SetTo(filename.c_str()); - if (!err && didCreate) + if (err == B_OK) + err = result->SetTo(filename.c_str()); + if (err == B_OK && didCreate) *didCreate = true; + if (err == B_OK) { + // write META:TYPE attribute + result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1); + } } return err; }