diff --git a/sources/RuleRunner.cpp b/sources/RuleRunner.cpp index 616cc4f..81cf0f0 100644 --- a/sources/RuleRunner.cpp +++ b/sources/RuleRunner.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include @@ -248,6 +247,7 @@ const NamePair sActions[] = { }; const unsigned nActions = sizeof(sActions) / sizeof(sActions[0]); +const char* const genericMime = "application/octet-stream"; const char* const archiveMime = "application/zip"; const char* const scriptMime = "text/plain application/x-vnd.Be-elfexecutable"; @@ -1432,36 +1432,30 @@ GetDirectoryPath(BString& str, const entry_ref& ref) static bool GetPathForRef(BString& str, const entry_ref& ref, const char* mime) { - // The code below checks if the MIME type matches. Skipped for now because - // Haiku doesn't recognize some file types (zip, script, etc.) from other - // file systems. -#if 0 + BPath path(&ref); + if (path.InitCheck() != B_OK) + return false; + BEntry entry(&ref, true); if (entry.InitCheck() != B_OK) return false; if (!entry.IsDirectory()) { - entry_ref target; - if (entry.GetRef(&target) != B_OK) - return false; - - BNode node(&target); + BNode node(&entry); if (node.InitCheck() != B_OK) return false; - BNodeInfo nodeInfo(&node); - if (nodeInfo.InitCheck() != B_OK) - return false; - - char type[B_MIME_TYPE_LENGTH]; - if (nodeInfo.GetType(type) != B_OK || strstr(mime, type) == NULL) - return false; + attr_info info; + if (node.GetAttrInfo("BEOS:TYPE", &info) == B_OK + || update_mime_info(path.Path(), NULL, 1, + B_UPDATE_MIME_INFO_NO_FORCE) == B_OK) { + BString mimeType; + if (node.ReadAttrString("BEOS:TYPE", &mimeType) == B_OK + && strstr(mime, mimeType) == NULL + && strcmp(mimeType, genericMime)) + return false; + } } -#endif - - BPath path(&ref); - if (path.InitCheck() != B_OK) - return false; str = path.Path(); return true; @@ -1490,22 +1484,22 @@ SetTextForType(BString& text, int8 type, const entry_ref& ref, bool isTest) default: return false; } - else - switch (type) { - case ACTION_MOVE: - case ACTION_COPY: - return GetDirectoryPath(text, target); - case ACTION_RENAME: - text = ref.name; - return true; - case ACTION_COMMAND: - return !entry.IsFile() ? false - : GetPathForRef(text, ref, scriptMime); - case ACTION_ARCHIVE: - return GetPathForRef(text, target, archiveMime); - default: - return false; - } + + switch (type) { + case ACTION_MOVE: + case ACTION_COPY: + return GetDirectoryPath(text, target); + case ACTION_RENAME: + text = ref.name; + return true; + case ACTION_COMMAND: + return !entry.IsFile() ? false + : GetPathForRef(text, ref, scriptMime); + case ACTION_ARCHIVE: + return GetPathForRef(text, target, archiveMime); + default: + return false; + } } @@ -1516,12 +1510,17 @@ SetTextForMime(BString& text, const entry_ref& ref) if (node.InitCheck() != B_OK) return false; - BNodeInfo nodeInfo(&node); - if (nodeInfo.InitCheck() != B_OK) - return false; + attr_info info; + if (node.GetAttrInfo("BEOS:TYPE", &info) != B_OK) { + BPath path(&ref); + if (path.InitCheck() != B_OK + || update_mime_info(path.Path(), NULL, 1, + B_UPDATE_MIME_INFO_NO_FORCE) != B_OK) + return false; + } - char mimeType[B_MIME_TYPE_LENGTH]; - if (nodeInfo.GetType(mimeType) != B_OK) + BString mimeType; + if (node.ReadAttrString("BEOS:TYPE", &mimeType) != B_OK) return false; text = mimeType; diff --git a/sources/RuleRunner.h b/sources/RuleRunner.h index 9003e46..44612f0 100644 --- a/sources/RuleRunner.h +++ b/sources/RuleRunner.h @@ -31,6 +31,7 @@ extern const unsigned nActions; extern const char* const sSizeUnits[]; extern const unsigned nSizeUnits; +extern const char* const genericMime; extern const char* const archiveMime; extern const char* const scriptMime; diff --git a/sources/RuleTab.cpp b/sources/RuleTab.cpp index a843fdf..460624f 100644 --- a/sources/RuleTab.cpp +++ b/sources/RuleTab.cpp @@ -103,8 +103,8 @@ RuleTab::_BuildLayout() fAddRemoveButtons = new AddRemoveButtons(MSG_SHOW_ADD_WINDOW, MSG_REMOVE_RULE, this, height, B_USE_DEFAULT_SPACING, - B_TRANSLATE_MARK_ALL("Add rule", ADD_REMVOE_BUTTONS_CONTEXT, NULL), - B_TRANSLATE_MARK_ALL("Remove rule", ADD_REMVOE_BUTTONS_CONTEXT, NULL)); + B_TRANSLATE_MARK_CONTEXT("Add rule", ADD_REMVOE_BUTTONS_CONTEXT), + B_TRANSLATE_MARK_CONTEXT("Remove rule", ADD_REMVOE_BUTTONS_CONTEXT)); fAddRemoveButtons->SetRemoveEnabled(false); fMoveUpButton = new BButton("moveupbutton", B_TRANSLATE("Move up"), diff --git a/sources/TypedRefFilter.cpp b/sources/TypedRefFilter.cpp index 092e9a8..b5ad4dc 100644 --- a/sources/TypedRefFilter.cpp +++ b/sources/TypedRefFilter.cpp @@ -1,6 +1,11 @@ #include "TypedRefFilter.h" -#include +#include + +#include +#include + +#include "RuleRunner.h" TypedRefFilter::TypedRefFilter() : @@ -56,7 +61,7 @@ TypedRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, const char* filetype) { struct stat targetStat; - char targetType[B_MIME_TYPE_LENGTH]; + BString targetType; bool isLink = S_ISLNK(st->st_mode); if (isLink) { @@ -67,9 +72,14 @@ TypedRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, BNode target(&entry); if (target.InitCheck() == B_OK) { - BNodeInfo nodeInfo(&target); - if (nodeInfo.InitCheck() == B_OK - && nodeInfo.GetType(targetType) == B_OK) + attr_info info; + BPath path(ref); + + if ((target.GetAttrInfo("BEOS:TYPE", &info) == B_OK + || path.InitCheck() == B_OK + && update_mime_info(path.Path(), NULL, 1, + B_UPDATE_MIME_INFO_NO_FORCE) == B_OK) + && target.ReadAttrString("BEOS:TYPE", &targetType) == B_OK) filetype = targetType; } } @@ -88,5 +98,5 @@ TypedRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, return true; return isDir || fFileType.FindFirst(filetype) != B_ERROR - || strcmp(filetype, "application/octet-stream") == 0; + || strcmp(filetype, genericMime) == 0; } diff --git a/sources/main.cpp b/sources/main.cpp index 47149ed..59aed2f 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -223,6 +223,7 @@ App::FileRef(entry_ref ref) } +#if 0 void App::SetupTypeMenu() { @@ -276,6 +277,7 @@ App::SetupTypeMenu() menu->Archive(&gArchivedTypeMenu); delete menu; } +#endif void diff --git a/sources/main.h b/sources/main.h index 8fba007..4359dc3 100644 --- a/sources/main.h +++ b/sources/main.h @@ -30,7 +30,7 @@ class App : public BApplication void ArgvReceived(int32 argc, char** argv); void ReadyToRun(); - void SetupTypeMenu(); +// void SetupTypeMenu(); void ShowHTML(const char* docfile); void FileRef(entry_ref ref); char GetDecimalMark() { return fDecimalMark; }