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

View File

@ -17,6 +17,8 @@
#include <Path.h>
#include <String.h>
#include <stdio.h>
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;
}