Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Mime.h>
- #include <string.h>
- #include <stdio.h>
- #include <Path.h>
- #include <Entry.h>
- #include <Message.h>
- using namespace std;
- void ShowUsage()
- {
- cout <<
- "# setmime:" << endl <<
- "# usage: setmime ((-dump | -dumpSniffRule | -dumpIcon | -dumpAll) [ <signatureString> ] )" << endl <<
- "# | (-remove <signatureString> )" << endl <<
- "# | ( (-set | -force | -add) <signatureString>" << endl <<
- "# [ -short <short description> ] [ -long <long description> ]" << endl <<
- "# [ -preferredApp <preferred app path> ]" << endl <<
- "# [ -preferredAppSig <preferred app signature> ]" << endl <<
- "# [ -sniffRule <sniffRule> ]" << endl <<
- "# [ -extension <file suffix> ]" << endl <<
- "# [ -attribute <internal name>" << endl <<
- "# [ -attrName <public name> ] [ -attrType <type code> ]" << endl <<
- "# [ -attrWidth <display width> ] [ -attrAlignment <position> ]" << endl <<
- "# [ -attrViewable <bool flag> ] [ -attrEditable <bool flag> ]" << endl <<
- "# [ -attrExtra <bool flag> ] ]" << endl <<
- "# [ -miniIcon <256 hex bytes> ]" << endl <<
- "# [ -largeIcon <1024 hex bytes> ] ... )" << endl <<
- "# | (-checkSniffRule <sniffRule>" << endl <<
- "# | -includeApps)" << endl;
- }
- void ShowHelp()
- {
- cout <<
- "# -dump prints a specified metamime" << endl <<
- "# -remove removes specified metamime" << endl <<
- "# -add adds specified metamime and specified metamime attributes" << endl <<
- "# that have not yet been defined" << endl <<
- "# -set adds specified metamime and specified metamime attributes," << endl <<
- "# overwrites the existing values of specified metamime attributes" << endl <<
- "# -force adds specified metamime and specified metamime attributes" << endl <<
- "# after first erasing all the existing attributes" << endl <<
- "# -dumpSniffRule prints just the MIME sniffer rule of a specified metamime" << endl <<
- "# -dumpIcon prints just the icon information of a specified metamime" << endl <<
- "# -dumpAll prints all the information, including icons of a specified metamime" << endl <<
- "# -checkSniffRule parses a MIME sniffer rule and reports any errors" << endl <<
- "# -includeApps will include applications" << endl;
- }
- int dump(const char* mimetype, const char* runpath)
- {
- BMimeType mime;
- mime.SetType(mimetype);
- if(!mime.IsInstalled() || !mime.IsValid() )
- {
- cout << runpath << ": incorrect signature" << endl;
- ShowUsage();
- return -1;
- }
- char temp[B_MIME_TYPE_LENGTH]={0};
- cout << runpath << " -set " << mimetype;
- if (mime.GetShortDescription(temp) == B_OK)
- cout << " -short \"" << temp << "\"";
- if (mime.GetLongDescription(temp) == B_OK)
- cout << " -long \"" << temp << "\"";
- entry_ref prefappref;
- if (mime.GetAppHint(&prefappref) == B_OK)
- {
- BPath prefapppath(&prefappref);
- cout << " -preferredApp " << prefapppath.Path();
- }
- if (mime.GetPreferredApp(temp, B_OPEN) == B_OK)
- cout << " -preferredAppSig " << temp;
- BMessage msg ; uint32 i=0; const char* ptr;
- if (mime.GetFileExtensions( &msg) == B_OK)
- while(msg.FindString("extensions", i++, &ptr) == B_OK)
- cout << " -extension " << ptr;
- cout << endl;
- return 0;
- }
- void dumpEverything(const char* runpath)
- {
- BMessage msg; uint32 i=0; const char* ptr;
- if (BMimeType::GetInstalledTypes(&msg) == B_OK)
- while(msg.FindString("types", i++, &ptr) == B_OK)
- dump(ptr, runpath);
- }
- int remove(const char* mimetype, const char* runpath)
- {
- BMimeType mime;
- mime.SetType(mimetype);
- if(!mime.IsInstalled() || !mime.IsValid() )
- {
- cout << runpath << ": incorrect signature" << endl;
- ShowUsage();
- return -1;
- }
- mime.Delete();
- return 0;
- }
- int set(const int argc, char** argv)
- {
- const char* runpath = argv[0]; const char* mimetype = argv[2];
- BMimeType mime;
- mime.SetType(mimetype);
- if(!mime.IsInstalled() || !mime.IsValid() )
- {
- cout << runpath << ": incorrect signature" << endl;
- ShowUsage();
- return -1;
- }
- return 0;
- }
- int main(int argc, char** argv)
- {
- if (argc==1)
- ShowUsage();
- if (argc>1)
- {
- if (strcmp(argv[1], "--help")==0)
- ShowHelp();
- if (strcmp(argv[1], "-dump")==0)
- if (argc==2)
- dumpEverything(argv[0]);
- else
- if (argc==3)
- dump(argv[2], argv[0]);
- else
- {cout << argv[0] << ": signature already specified" << endl; ShowUsage();}
- if (strcmp(argv[1], "-remove")==0)
- if(argc==3)
- remove(argv[2], argv[0]);
- else
- if (argc==2) {cout << argv[0] << ": no signature specified" << endl; ShowUsage();}
- else
- {cout << argv[0] << ": signature already specified" << endl; ShowUsage();}
- if (strcmp(argv[1], "-set")==0)
- if (argc==2) {cout << argv[0] << ": no signature specified" << endl; ShowUsage();}
- else
- set(argc, argv);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement