Advertisement
Guest User

Untitled

a guest
Nov 26th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.99 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <Mime.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <Path.h>
  7. #include <Entry.h>
  8. #include <Message.h>
  9. using namespace std;
  10.  
  11. void ShowUsage()
  12. {
  13.     cout <<
  14.         "# setmime:" << endl <<
  15.         "# usage: setmime ((-dump | -dumpSniffRule | -dumpIcon | -dumpAll) [ <signatureString> ] )" << endl <<
  16.         "#      | (-remove <signatureString> )" << endl <<
  17.         "#      | ( (-set | -force | -add)  <signatureString>" << endl <<
  18.         "#          [ -short <short description> ] [ -long <long description> ]" << endl <<
  19.         "#          [ -preferredApp <preferred app path> ]" << endl <<
  20.         "#          [ -preferredAppSig <preferred app signature> ]" << endl <<
  21.         "#          [ -sniffRule <sniffRule> ]" << endl <<
  22.         "#          [ -extension <file suffix> ]" << endl <<
  23.         "#          [ -attribute <internal name>" << endl <<
  24.         "#             [ -attrName <public name> ] [ -attrType <type code> ]" << endl <<
  25.         "#             [ -attrWidth <display width> ] [ -attrAlignment <position> ]" << endl <<
  26.         "#             [ -attrViewable <bool flag> ] [ -attrEditable <bool flag> ]" << endl <<
  27.         "#             [ -attrExtra <bool flag> ] ]" << endl <<
  28.         "#          [ -miniIcon <256 hex bytes> ]" << endl <<
  29.         "#          [ -largeIcon <1024 hex bytes> ] ... )" << endl <<
  30.         "#      | (-checkSniffRule <sniffRule>" << endl <<
  31.         "#      | -includeApps)" << endl;
  32. }
  33.  
  34. void ShowHelp()
  35. {
  36.     cout <<
  37.         "#  -dump prints a specified metamime" << endl <<
  38.         "#  -remove removes specified metamime" << endl <<
  39.         "#  -add adds specified metamime and specified metamime attributes" << endl <<
  40.         "#      that have not yet been defined" << endl <<
  41.         "#  -set adds specified metamime and specified metamime attributes," << endl <<
  42.         "#      overwrites the existing values of specified metamime attributes" << endl <<
  43.         "#  -force adds specified metamime and specified metamime attributes" << endl <<
  44.         "#      after first erasing all the existing attributes" << endl <<
  45.         "#  -dumpSniffRule prints just the MIME sniffer rule of a specified metamime" << endl <<
  46.         "#     -dumpIcon prints just the icon information of a specified metamime" << endl <<
  47.         "#  -dumpAll prints all the information, including icons of a specified metamime" << endl <<
  48.         "#  -checkSniffRule parses a MIME sniffer rule and reports any errors" << endl <<
  49.         "#  -includeApps will include applications"  << endl;
  50. }
  51.  
  52. int dump(const char* mimetype, const char* runpath)
  53. {
  54.     BMimeType mime;
  55.     mime.SetType(mimetype);    
  56.     if(!mime.IsInstalled() || !mime.IsValid() )
  57.     {
  58.         cout << runpath << ": incorrect signature" << endl;
  59.         return -1;
  60.     }  
  61.     char temp[B_MIME_TYPE_LENGTH]={0};
  62.     cout << runpath << " -set " << mimetype;    
  63.     if (mime.GetShortDescription(temp) == B_OK)  
  64.         cout << " -short \"" << temp << "\"";  
  65.     if (mime.GetLongDescription(temp) == B_OK)
  66.         cout << " -long \"" << temp << "\"";
  67.     entry_ref prefappref;
  68.     if (mime.GetAppHint(&prefappref) == B_OK)
  69.     {
  70.         BPath prefapppath(&prefappref);
  71.         cout << " -preferredApp " << prefapppath.Path();
  72.     }    
  73.     if (mime.GetPreferredApp(temp, B_OPEN) == B_OK)
  74.         cout << " -preferredAppSig " << temp;
  75.    
  76.     BMessage msg(); uint32 i=0; char *ptr;
  77.     if (mime.GetFileExtensions(&msg) == B_OK)
  78.         while(msg.FindString("extensions", i++, &ptr) == B_OK)
  79.             cout << " -extension " << ptr;
  80.     cout << endl;
  81.     return 0;
  82. }
  83.  
  84. void dumpEverything(const char* runpath)
  85. {
  86.        
  87. }
  88.  
  89. int remove(const char* mimetype, const char* runpath)
  90. {
  91.     BMimeType mime;
  92.     mime.SetType(mimetype);    
  93.     if(!mime.IsInstalled() || !mime.IsValid() )
  94.     {
  95.         cout << runpath << ": incorrect signature" << endl;
  96.         return -1;
  97.     }
  98.     mime.Delete();
  99.     return 0;
  100. }
  101.  
  102. int main(int argc, char** argv)
  103. {  
  104.     if (argc==1)
  105.         ShowUsage();
  106.        
  107.     if (argc>1)
  108.     {
  109.         if (strcmp(argv[1], "--help")==0)  
  110.             ShowHelp();
  111.         if (strcmp(argv[1], "-dump")==0)
  112.             if (argc==2)
  113.                 dumpEverything(argv[0]);
  114.             else
  115.                 dump(argv[2], argv[0]);
  116.         if (strcmp(argv[1], "-remove")==0 && argc==3)
  117.             remove(argv[2], argv[0]);
  118.     }
  119.  
  120.  
  121.     return 0;
  122. }
  123.  
  124.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement