Esempio n. 1
0
  private static void memmove(byte[] dest, int src, int size) {
    switch (memmove_type) {
      case 0:
        try {
          OSXAccess.memmove(dest, src, size);
          memmove_type = 0;
          return;
        } catch (Throwable e) {
        }
        // FALL THROUGH

      case 1:
        try {
          Class<?> cMemMove = Class.forName("org.eclipse.swt.internal.carbon.OS");

          Method method =
              cMemMove.getMethod("memmove", new Class[] {byte[].class, Integer.TYPE, Integer.TYPE});

          method.invoke(null, new Object[] {dest, new Integer(src), new Integer(size)});
          memmove_type = 1;
          return;
        } catch (Throwable e) {
        }

        // FALL THROUGH
      case 2:
        try {
          Class<?> cMemMove = Class.forName("org.eclipse.swt.internal.carbon.OS");

          Method method =
              cMemMove.getMethod("memcpy", new Class[] {byte[].class, Integer.TYPE, Integer.TYPE});

          method.invoke(null, new Object[] {dest, new Integer(src), new Integer(size)});

          memmove_type = 2;
          return;
        } catch (Throwable e) {
        }

        // FALL THROUGH

      default:
        break;
    }

    memmove_type = 3;
  }
Esempio n. 2
0
  static final int openDocProc(int theAppleEvent, int reply, int handlerRefcon) {
    try {
      Object aeDesc = claAEDesc.newInstance();
      Object eventRecord = claEventRecord.newInstance();
      invoke(
          claOS,
          null,
          "ConvertEventRefToEventRecord",
          new Class[] {int.class, claEventRecord},
          new Object[] {theAppleEvent, eventRecord});
      try {
        int result =
            OSXAccess.AEGetParamDesc(theAppleEvent, kEventParamDirectObject, typeAEList, aeDesc);
        if (result != noErr) {
          Debug.out("OSX: Could call AEGetParamDesc. Error: " + result);
          return noErr;
        }
      } catch (java.lang.UnsatisfiedLinkError e) {
        Debug.out("OSX: AEGetParamDesc not available.  Can't open sent file");
        return noErr;
      }

      int[] count = new int[1];
      invoke(
          claOS,
          null,
          "AECountItems",
          new Class[] {claAEDesc, int[].class},
          new Object[] {aeDesc, count});
      // System.out.println("COUNT: " + count[0]);
      if (count[0] > 0) {
        final String[] fileNames = new String[count[0]];
        int maximumSize = 80; // size of FSRef
        int dataPtr =
            ((Number) invoke(claOS, null, "NewPtr", new Object[] {maximumSize})).intValue();
        int[] aeKeyword = new int[1];
        int[] typeCode = new int[1];
        int[] actualSize = new int[1];
        for (int i = 0; i < count[0]; i++) {
          try {
            // int AEGetNthPtr(AEDesc theAEDescList, int index, int desiredType,
            // int[] theAEKeyword, int[] typeCode, int dataPtr, int maximumSize, int[] actualSize);
            Class<?>[] sigAEGetNthPtr =
                new Class[] {
                  claAEDesc,
                  int.class,
                  int.class,
                  int[].class,
                  int[].class,
                  int.class,
                  int.class,
                  int[].class
                };
            int ret =
                ((Number)
                        invoke(
                            claOS,
                            null,
                            "AEGetNthPtr",
                            sigAEGetNthPtr,
                            new Object[] {
                              aeDesc,
                              i + 1,
                              typeFSRef,
                              aeKeyword,
                              typeCode,
                              dataPtr,
                              maximumSize,
                              actualSize
                            }))
                    .intValue();
            if (ret == noErr) {
              byte[] fsRef = new byte[actualSize[0]];
              memmove(fsRef, dataPtr, actualSize[0]);
              int dirUrl =
                  ((Number)
                          invoke(
                              claOS,
                              null,
                              "CFURLCreateFromFSRef",
                              new Object[] {kCFAllocatorDefault, fsRef}))
                      .intValue();
              int dirString =
                  ((Number)
                          invoke(
                              claOS,
                              null,
                              "CFURLCopyFileSystemPath",
                              new Object[] {dirUrl, kCFURLPOSIXPathStyle}))
                      .intValue();
              int length =
                  ((Number) invoke(claOS, null, "CFStringGetLength", new Object[] {dirString}))
                      .intValue();
              char[] buffer = new char[length];
              Object range = claCFRange.newInstance();
              claCFRange.getField("length").setInt(range, length);
              invoke(
                  claOS,
                  null,
                  "CFStringGetCharacters",
                  new Class[] {int.class, claCFRange, char[].class},
                  new Object[] {dirString, range, buffer});
              fileNames[i] = new String(buffer);
              invoke(claOS, null, "CFRelease", new Object[] {dirString});
              invoke(claOS, null, "CFRelease", new Object[] {dirUrl});
            } else {
              ret =
                  ((Number)
                          invoke(
                              claOS,
                              null,
                              "AEGetNthPtr",
                              sigAEGetNthPtr,
                              new Object[] {
                                aeDesc,
                                i + 1,
                                typeText,
                                aeKeyword,
                                typeCode,
                                dataPtr,
                                2048,
                                actualSize
                              }))
                      .intValue();

              if (ret == noErr) {
                byte[] urlRef = new byte[actualSize[0]];
                memmove(urlRef, dataPtr, actualSize[0]);
                fileNames[i] = new String(urlRef);
              }
            }
          } catch (Throwable t) {
            Debug.out(t);
          }
          // System.out.println(fileNames[i]);
        }

        AzureusCoreFactory.addCoreRunningListener(
            new AzureusCoreRunningListener() {
              public void azureusCoreRunning(AzureusCore core) {
                TorrentOpener.openTorrents(fileNames);
              }
            });
      }

      return noErr;
    } catch (Throwable e) {
      Debug.out(e);
    }
    return eventNotHandledErr;
  }