diff --git a/sources/ActionView.cpp b/sources/ActionView.cpp index 4a38c82..1699550 100644 --- a/sources/ActionView.cpp +++ b/sources/ActionView.cpp @@ -129,10 +129,10 @@ ActionView::MessageReceived(BMessage* msg) const char* fileType; switch (fType) { case ACTION_ARCHIVE: - fileType = archiveMime; + fileType = kArchiveMime; break; case ACTION_COMMAND: - fileType = scriptMime; + fileType = kScriptMime; break; default: fileType = ""; diff --git a/sources/RuleRunner.cpp b/sources/RuleRunner.cpp index 81cf0f0..67904aa 100644 --- a/sources/RuleRunner.cpp +++ b/sources/RuleRunner.cpp @@ -8,24 +8,23 @@ Owen Pan , 2017 */ +#include "RuleRunner.h" + +#include + #include #include -#include #include -#include +#include #include #include +#include "ConflictWindow.h" #include "CppSQLite3.h" #include "Database.h" -#include "ConflictWindow.h" #include "FSUtils.h" #include "main.h" #include "PatternProcessor.h" -#include "RuleRunner.h" - -#include -#include /* FilerAction message fields: @@ -247,9 +246,8 @@ 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"; +const char* const kArchiveMime = "application/zip"; +const char* const kScriptMime = "text/plain"; RuleRunner::RuleRunner() @@ -1432,31 +1430,25 @@ GetDirectoryPath(BString& str, const entry_ref& ref) static bool GetPathForRef(BString& str, const entry_ref& ref, const char* mime) { - BPath path(&ref); - if (path.InitCheck() != B_OK) - return false; - BEntry entry(&ref, true); if (entry.InitCheck() != B_OK) return false; if (!entry.IsDirectory()) { - BNode node(&entry); - if (node.InitCheck() != B_OK) + entry_ref target; + if (entry.GetRef(&target) != B_OK) 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; - } + BMimeType mimeType; + if (BMimeType::GuessMimeType(&target, &mimeType) != B_OK + || strcmp(mimeType.Type(), mime)) + return false; } + BPath path(&ref); + if (path.InitCheck() != B_OK) + return false; + str = path.Path(); return true; } @@ -1494,9 +1486,9 @@ SetTextForType(BString& text, int8 type, const entry_ref& ref, bool isTest) return true; case ACTION_COMMAND: return !entry.IsFile() ? false - : GetPathForRef(text, ref, scriptMime); + : GetPathForRef(text, ref, kScriptMime); case ACTION_ARCHIVE: - return GetPathForRef(text, target, archiveMime); + return GetPathForRef(text, target, kArchiveMime); default: return false; } @@ -1506,24 +1498,11 @@ SetTextForType(BString& text, int8 type, const entry_ref& ref, bool isTest) bool SetTextForMime(BString& text, const entry_ref& ref) { - BNode node(&ref); - if (node.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; - } - - BString mimeType; - if (node.ReadAttrString("BEOS:TYPE", &mimeType) != B_OK) + BMimeType mimeType; + if (BMimeType::GuessMimeType(&ref, &mimeType) != B_OK) return false; - text = mimeType; + text = mimeType.Type(); return true; } diff --git a/sources/RuleRunner.h b/sources/RuleRunner.h index 44612f0..f37f5d7 100644 --- a/sources/RuleRunner.h +++ b/sources/RuleRunner.h @@ -9,10 +9,6 @@ #define RULERUNNER_H #include "FilerRule.h" -#include "ObjectList.h" - -#include -#include struct NamePair { @@ -31,9 +27,8 @@ 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; +extern const char* const kArchiveMime; +extern const char* const kScriptMime; enum { TEST_TYPE_NULL = 0, diff --git a/sources/TypedRefFilter.cpp b/sources/TypedRefFilter.cpp index b5ad4dc..cdfd6d4 100644 --- a/sources/TypedRefFilter.cpp +++ b/sources/TypedRefFilter.cpp @@ -1,11 +1,9 @@ #include "TypedRefFilter.h" -#include +#include -#include -#include +#include -#include "RuleRunner.h" TypedRefFilter::TypedRefFilter() : @@ -61,27 +59,17 @@ TypedRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, const char* filetype) { struct stat targetStat; - BString targetType; - + entry_ref target(*ref); bool isLink = S_ISLNK(st->st_mode); + if (isLink) { BEntry entry(ref, true); if (entry.InitCheck() == B_OK) { if (entry.GetStat(&targetStat) == B_OK) st = (struct stat_beos*) (&targetStat); - BNode target(&entry); - if (target.InitCheck() == 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; - } + if (entry.GetRef(&target) != B_OK) + target = *ref; } } @@ -97,6 +85,8 @@ TypedRefFilter::Filter(const entry_ref* ref, BNode* node, struct stat_beos* st, if (fFileType.IsEmpty()) return true; - return isDir || fFileType.FindFirst(filetype) != B_ERROR - || strcmp(filetype, genericMime) == 0; + BMimeType mimeType; + + return isDir || fFileType == (BMimeType::GuessMimeType(&target, &mimeType) + == B_OK ? mimeType.Type() : filetype); } diff --git a/sources/TypedRefFilter.h b/sources/TypedRefFilter.h index 4722b47..f8cad99 100644 --- a/sources/TypedRefFilter.h +++ b/sources/TypedRefFilter.h @@ -4,8 +4,6 @@ #include #include -#include - /* This utility class is for filtering */