Finished implementation

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1326 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-10-01 07:26:57 +00:00
parent 09dad369d7
commit 04c26f3c9b
@@ -17,6 +17,8 @@
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <stdio.h>
namespace BPrivate { namespace BPrivate {
namespace Storage { namespace Storage {
namespace Mime { namespace Mime {
@@ -31,43 +33,50 @@ status_t
CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir) CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
{ {
status_t err = entry ? B_OK : B_BAD_VALUE; status_t err = entry ? B_OK : B_BAD_VALUE;
bool doUpdate = false;
BNode node; BNode node;
BString sig; BString sig;
if (!err)
err = node.SetTo(entry);
// Read the app sig (which consequently keeps us from updating non-applications)
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; BMimeType mime;
BPath path; BPath path;
attr_info info; attr_info info;
BBitmap miniIcon(BRect(0,0,15,15), B_CMAP8); BBitmap miniIcon(BRect(0,0,15,15), B_CMAP8);
BNode typeNode;
if (!err)
err = node.SetTo(entry);
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) {
// Init our various objects // Init our various objects
err = mime.SetTo(sig.String()); err = mime.SetTo(sig.String());
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) if (!err)
err = path.SetTo(entry); err = path.SetTo(entry);
// Preferred App // Preferred App
if (!err) if (!err && (fForce || typeNode.GetAttrInfo(kPreferredAppAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetPreferredApp(sig.String()); err = mime.SetPreferredApp(sig.String());
}
// Short Description // Short Description
if (!err) if (!err && (fForce || typeNode.GetAttrInfo(kShortDescriptionAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetShortDescription(path.Leaf()); err = mime.SetShortDescription(path.Leaf());
}
// App Hint // App Hint
if (!err) if (!err && (fForce || typeNode.GetAttrInfo(kAppHintAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = mime.SetAppHint(entry); err = mime.SetAppHint(entry);
}
// Mini icon // Mini icon
if (!err) if (!err && (fForce || typeNode.GetAttrInfo(kMiniIconAttr, &info) == B_ENTRY_NOT_FOUND)) {
err = node.GetAttrInfo("BEOS:M:STD_ICON", &info); err = node.GetAttrInfo("BEOS:M:STD_ICON", &info);
if (!err) if (!err)
err = info.size == 16*16 ? B_OK : B_BAD_VALUE; err = info.size == 16*16 ? B_OK : B_BAD_VALUE;
@@ -78,8 +87,7 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref *entry, bool *entryIsDir)
if (!err) if (!err)
err = mime.SetIcon(&miniIcon, B_MINI_ICON); err = mime.SetIcon(&miniIcon, B_MINI_ICON);
} }
if (!err && entryIsDir) }
*entryIsDir = node.IsDirectory();
return err; return err;
} }