Guest User

Untitled

a guest
Nov 26th, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 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.     char temp[B_MIME_TYPE_LENGTH]={0};
  56.     mime.SetType(mimetype);    
  57.     if(!mime.IsInstalled() || !mime.IsValid() )
  58.     {
  59.         cout << runpath << ": incorrect signature" << endl;
  60.         return -1;
  61.     }
  62.  
  63.     cout << runpath << " -set " << mimetype;    
  64.     if (mime.GetShortDescription(temp) == B_OK)  
  65.         cout << " -short \"" << temp << "\"";  
  66.     if (mime.GetLongDescription(temp) == B_OK)
  67.         cout << " -long \"" << temp << "\"";
  68.     entry_ref prefappref;
  69.     if (mime.GetAppHint(&prefappref) == B_OK)
  70.     {
  71.         BPath prefapppath(&prefappref);
  72.         cout << " -preferredApp " << prefapppath.Path();
  73.     }    
  74.     if (mime.GetPreferredApp(temp, B_OPEN) == B_OK)
  75.         cout << " -preferredAppSig " << temp;
  76.        
  77.     cout << endl;
  78.     return 0;
  79. }
  80.  
  81. void dumpEverything(const char* runpath)
  82. {
  83.        
  84. }
  85.  
  86. void remove()
  87. {
  88.    
  89. }
  90.  
  91. int main(int argc, char** argv)
  92. {  
  93.     if (argc==1)
  94.         ShowUsage();
  95.        
  96.     if (argc>1)
  97.     {
  98.         if (strcmp(argv[1], "--help")==0)  
  99.                 ShowHelp();
  100.         if (strcmp(argv[1], "-dump")==0)
  101.             if (argc==2)
  102.                 dumpEverything(argv[0]);
  103.             else
  104.                 dump(argv[2], argv[0]);
  105.     }
  106.  
  107.  
  108.     return 0;
  109. }
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment