処理“ドキュメントを開く” (odoc)Snow Leopardのイベント

StackOverflow https://stackoverflow.com/questions/1446835

  •  22-07-2019
  •  | 
  •  

質問

「ドキュメントを開く」に応答するコードがアプリケーションにあります。 (odoc)イベント。 Mac OS X TigerおよびLeopardでは、このコードは正常に機能します。

- (void) handleOpenDocumentEvent:
    (NSAppleEventDescriptor*)event
    withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
    NSAppleEventDescriptor const *const dirObj =
        [event descriptorForKeyword:keyDirectObject];
    DescType const dirObjType = [dirObj descriptorType];

    if ( dirObjType == 'alis' ) {
        //
        // Open a single file.
        //
        NSData const *const data = [dirObj data];
        AliasHandle const fileHandle =
            reinterpret_cast<AliasHandle>( ::NewHandle( [data length] ) );
        if ( fileHandle ) {
            [data getBytes:*fileHandle];
            err = [self queueFile:fileHandle fromSender:senderSig];
        }
    } else if ( dirObjType == 'list' ) {
        //
        // Open multiple files.
        //
        AliasHandle fileHandle =
            reinterpret_cast<AliasHandle>( ::NewHandle( 0 ) );
        if ( fileHandle ) {
            int const numItems = [dirObj numberOfItems];
            for ( int i = 1; i <= numItems; ++i ) {
                NSData const *const data = [[dirObj descriptorAtIndex:i] data];
                ::SetHandleSize( reinterpret_cast<Handle>( fileHandle ), [data length] );
                if ( (err = ::MemError()) != noErr )
                    break;
                [data getBytes:*fileHandle];
                err = [self queueFile:fileHandle fromSender:senderSig];
                if ( err != noErr )
                    break;
            }
        }
    }
}

ただし、Mac OS X Snow Leopardでは、このコードは機能しません。 LeopardシステムからのAppleEventのダンプは次のとおりです。

{ 1 } 'aevt':  aevt/odoc (i386){
          return id: 1012269061 (0x3c560005)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
             remote: 0 (0x0)
      for recording: 0 (0x0)
         reply port: 150031 (0x24a0f)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0x655655 } (iPhoto)
    }
  fEventSourcePSN: { 0x0,0x655655 } (iPhoto)
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' -
        { 1 } 'list':  - 1 elements {
          { 1 } 'alis':  326 bytes {
            /Users/pjl/Pictures/IMG_8501.JPG
          }
        }
    }
}

Snow LeopardシステムからのAppleEventのダンプは次のとおりです。

{ 1 } 'aevt':  aevt/odoc (i386){
          return id: 5173 (0x1435)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
             remote: 0 (0x0)
      for recording: 0 (0x0)
         reply port: 81695 (0x13f1f)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0x17c17c } (iPhoto)
    }
  fEventSourcePSN: { 0x0,0x17c17c } (iPhoto)
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' - 
        { 1 } 'list':  - 1 elements {
          { 1 } 'bmrk':  944 bytes {
                  000: 626f 6f6b  b003 0000  0000 0110  1000 0000     book............
                  001: c002 0000  0500 0000  0101 0000  5573 6572     ............User
                  002: 7300 0000  0300 0000  0101 0000  706a 6c00     s...........pjl.
                  003: 0800 0000  0101 0000  5069 6374  7572 6573     ........Pictures
                  004: 0e00 0000  0101 0000  6950 686f  746f 204c     ........iPhoto L
                  005: 6962 7261  7279 0000  0800 0000  0101 0000     ibrary..........
                  006: 4d6f 6469  6669 6564  0400 0000  0101 0000     Modified........
                  007: 3230 3037  0b00 0000  0101 0000  4a75 6e20     2007........Jun 
                  008: 392c 2032  3030 3700  0c00 0000  0101 0000     9, 2007.........
                  009: 494d 475f  3633 3837  2e6a 7067  2000 0000     IMG_6387.jpg ...
                  ....
                  058: 0000 0000  30f0 0000  3002 0000  0000 0000     ....0...0.......
          }
        }
    }
}

「alis」タイプは、新しいSnow Leopardの「ブックマーク」に置き換えられました。タイプ。このコードを次のように変更するにはどうすればよいですか:

a)新しい「bmrk」タイプをテストして処理します。つまり、ファイルの絶対パスを取得します
b)TigerとLeopardでの作業を継続

または、「alis」構造を含むodocイベントが引き続き必要であることをOSに伝える方法はありますか?

役に立ちましたか?

解決

「ブックマークデータ」ここに含まれるのは、Snow Leopardで導入された新しいCFURLおよび/またはNSURL APIを使用して処理できます。 + [NSURL URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error] は、イベント記述子に含まれるブックマークデータの解決に使用できるNSURL APIです。

coerceToDescriptorType:メソッドを使用して記述子をエイリアスに強制し、そのように処理することもできます。SnowLeopardに組み込みの強制ハンドラが含まれているかどうかは文書化されていませんこれ(ただし、そうする必要があるようです)。

Tiger / Leopardの互換性に関しては、これらのシステムのいずれでもブックマークデータが渡されることはないため、新しいNSURLメソッドを呼び出しても問題はありません。古いシステム。

ところで、ヘッダーファイル&quot; AEDataModel.h&quot;使用している4つの文字コードの記号定数が含まれているため、 'alis' の代わりに typeAlias を使用でき、 typebookmark > 'bmrk' など。これにより、コードがもう少し読みやすくなり、タイプミスなどからコンパイラが保護されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top