home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 43 / Mac Magazin and MacEasy Magazine CD - Issue 43.iso / Software / Multimedia / Sound / PlayerPRO 4.6 Dev.Kit / MADH Library 4.6 / MADLibrary Source / PlugImport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-23  |  14.2 KB  |  628 lines  |  [TEXT/CWIE]

  1. /********************                        ***********************/
  2. //
  3. //    Player PRO 4.6 - DRIVER SOURCE CODE -
  4. //
  5. //    Library Version 4.6
  6. //
  7. //    To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
  8. //
  9. //    Antoine ROSSET
  10. //    16 Tranchees
  11. //    1206 GENEVA
  12. //    SWITZERLAND
  13. //
  14. //    COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
  15. //
  16. //    Thank you for your interest in PlayerPRO !
  17. //
  18. //    FAX:            (+41 22) 346 11 97
  19. //    PHONE:             (+41 79) 203 74 62
  20. //    Internet:         rosset@dial.eunet.ch or RossetAntoine@bluewin.ch
  21. //
  22. /********************                        ***********************/
  23.  
  24. #include "mixedmode.h"
  25.  
  26. #include "RDriver.h"
  27. #include "RDriverInt.h"
  28. #include "Aliases.h"
  29. #include "FileUtils.h"
  30. #include "Files.h"
  31. #include <string.h>
  32.  
  33. #define MAXPLUG    40
  34. #define RSRCNAME "\pRsrc Plug Sys##"
  35.  
  36. static MADLibrary*    inMADDriver;
  37.  
  38. void pStrCpy( unsigned char *s1, unsigned char *s2)
  39. {
  40.     register short len, i;
  41.     
  42.     if (*s2 <= 220) 
  43.     {
  44.         len = *s2;
  45.         for ( i = 0; i <= len; i++)
  46.         {
  47.             s1[ i] = s2[ i];
  48.         }
  49.     }
  50.     else DebugStr("\pString to biiig !");
  51. }
  52.  
  53. Handle MADGet1Resource( OSType type, short id, MADLibrary* init)
  54. {
  55.     if( init->sysMemory)
  56.     {
  57.         Handle    tH, dH;
  58.         
  59.         tH = Get1Resource( type, id);
  60.         if( tH == 0L) return 0L;
  61.         
  62.         DetachResource( tH);
  63.         dH = NewHandleSys( GetHandleSize( tH));
  64.         if( dH == 0L) Debugger();
  65.         if( MemError() != noErr) Debugger();
  66.         
  67.         HLock( dH);
  68.         HLock( tH);
  69.         
  70.         BlockMove( *tH, *dH, GetHandleSize( tH));
  71.         
  72.         HUnlock( dH);
  73.         HUnlock( tH);
  74.         
  75.         DisposeHandle( tH);
  76.         tH = 0L;
  77.         
  78.         return dH;
  79.     }
  80.     else
  81.     {
  82.         Handle dH = Get1Resource( type, id);
  83.         if( dH == 0L) return 0L;
  84.         
  85.         DetachResource( dH);
  86.         
  87.         return dH;
  88.     }
  89. }
  90.  
  91. typedef OSErr (*MyProcPtr) ( OSType, char*, MADMusic*, PPInfoRec*, MADDriverSettings *);
  92.  
  93. OSErr CallImportPlug(         short                    PlugNo,            // CODE du plug
  94.                                                     OSType                order,
  95.                                                     char                    *AlienFile,
  96.                                                     MADMusic            *theNewMAD,
  97.                                                     PPInfoRec            *info)
  98. {
  99. OSErr                            myErr;
  100. short                            fileID;
  101. UniversalProcPtr     thecall;
  102. MADDriverSettings driverSettings;
  103.  
  104.     driverSettings.sysMemory = inMADDriver->sysMemory;
  105.  
  106.     if( inMADDriver->ThePlug[ PlugNo].IOPlug == 0L) return -1;
  107.     HLock( inMADDriver->ThePlug[ PlugNo].IOPlug);
  108.     if( *inMADDriver->ThePlug[ PlugNo].IOPlug == 0L) return -1;
  109.     
  110.     if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false))
  111.     {
  112.         fileID = FSpOpenResFile( &inMADDriver->ThePlug[ PlugNo].file, fsCurPerm);
  113.         UseResFile( fileID);
  114.     }
  115.     
  116.     #define         MyCallMode ( kCStackBased|\
  117.                             RESULT_SIZE( SIZE_CODE( sizeof(OSErr) ))|\
  118.                             STACK_ROUTINE_PARAMETER( 1, SIZE_CODE( sizeof( OSType)))|\
  119.                             STACK_ROUTINE_PARAMETER( 2, SIZE_CODE( sizeof( char*)))|\
  120.                             STACK_ROUTINE_PARAMETER( 3, SIZE_CODE( sizeof( MADMusic*)))|\
  121.                             STACK_ROUTINE_PARAMETER( 4, SIZE_CODE( sizeof( PPInfoRec*)))|\
  122.                             STACK_ROUTINE_PARAMETER( 5, SIZE_CODE( sizeof( MADDriverSettings*))))
  123.     
  124.  
  125.     #if defined(powerc) || defined (__powerc)
  126.     if( inMADDriver->ThePlug[ PlugNo].hasPPCCode)
  127.     {
  128.         thecall = (UniversalProcPtr) *inMADDriver->ThePlug[ PlugNo].IOPlug;
  129.         myErr = CallUniversalProc( thecall, MyCallMode, order, AlienFile, theNewMAD, info, &driverSettings);
  130.     }
  131.     else
  132.     {
  133.         thecall = NewRoutineDescriptor( (ProcPtr) *inMADDriver->ThePlug[ PlugNo].IOPlug, MyCallMode, kM68kISA);
  134.         myErr = CallUniversalProc( thecall, MyCallMode, order, AlienFile, theNewMAD, info, &driverSettings);
  135.         DisposeRoutineDescriptor( thecall);
  136.     }
  137.     #else
  138.         myErr = (* (MyProcPtr) (*inMADDriver->ThePlug[ PlugNo].IOPlug)) ( order, AlienFile, theNewMAD, info, &driverSettings);
  139.     #endif
  140.  
  141. //    myErr = TESTmain( order, AlienFile, theNewMAD, info, &driverSettings);
  142.     
  143.     HUnlock( inMADDriver->ThePlug[ PlugNo].IOPlug);
  144.     
  145.     if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false))
  146.         CloseResFile( fileID);    
  147.     
  148. //    theNewMAD->currentDriver = 0L;
  149.     
  150.     return( myErr);
  151. }
  152.  
  153. OSErr    PPTestFile( char    *kindFile, char    *AlienFile)
  154. {
  155.     short            i;
  156.     MADMusic    aMAD;
  157.     PPInfoRec        InfoRec;
  158.     
  159.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  160.     {
  161.         if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
  162.         {
  163.             return( CallImportPlug( i, 'TEST', AlienFile, &aMAD, &InfoRec));
  164.         }
  165.     }
  166.     return MADCannotFindPlug;
  167. }
  168.  
  169. OSErr PPMADHInfoFile( char    *AlienFile, PPInfoRec    *InfoRec)
  170. {
  171.     MADSpec        *theMAD;
  172.     long            fileSize, temp;
  173.     short            fileID, i;
  174.     
  175.         theMAD = (MADSpec*) NewPtr( sizeof( MADSpec) + 200L);
  176.         
  177.         fileID = iFileOpen( AlienFile);
  178.         if( !fileID)
  179.         {
  180.             DisposePtr( (Ptr) theMAD);
  181.             return -1;
  182.         }
  183.         fileSize = iGetEOF( fileID);
  184.         
  185.         iRead( sizeof( MADSpec), (Ptr) theMAD, fileID);
  186.         iClose( fileID);
  187.         
  188.         strcpy( InfoRec->internalFileName, theMAD->name);
  189.         
  190.         InfoRec->totalPatterns = theMAD->numPat;
  191.         InfoRec->partitionLength = theMAD->numPointers;
  192.         InfoRec->totalTracks = theMAD->numChn;
  193.         InfoRec->signature = 'MADH';
  194.         strcpy( InfoRec->formatDescription, "MADH");
  195.         
  196.         temp = 0;
  197.         for( i = 0; i < MAXINSTRU ; i++)
  198.         {
  199.             temp += theMAD->fid[ i].numSamples;
  200.         }
  201.         InfoRec->totalInstruments = temp;
  202.         InfoRec->fileSize = fileSize;
  203.         
  204.         DisposePtr( (Ptr) theMAD);    
  205.         theMAD = 0L;
  206.         
  207.         return noErr;
  208. }
  209.  
  210. OSErr    PPInfoFile( char    *kindFile, char    *AlienFile, PPInfoRec    *InfoRec)
  211. {
  212.     short            i;
  213.     MADMusic    aMAD;
  214.     
  215.     if( !MADstrcmp( kindFile, "MADH"))
  216.     {
  217.         PPMADHInfoFile( AlienFile, InfoRec);
  218.         
  219.         return noErr;
  220.     }
  221.     
  222.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  223.     {
  224.         if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
  225.         {
  226.             return( CallImportPlug( i, 'INFO', AlienFile, &aMAD, InfoRec));
  227.         }
  228.     }
  229.     return MADCannotFindPlug;
  230. }
  231.  
  232. OSErr    PPExportFile( char    *kindFile, char    *AlienFile, MADMusic    *theNewMAD)
  233. {
  234.     short        i;
  235.     PPInfoRec    InfoRec;
  236.     
  237.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  238.     {
  239.         if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
  240.         {
  241.             return( CallImportPlug( i, 'EXPL', AlienFile, theNewMAD, &InfoRec));
  242.         }
  243.     }
  244.     return MADCannotFindPlug;
  245. }
  246.  
  247. OSErr    PPImportFile( char    *kindFile, char *AlienFile, MADMusic    **theNewMAD)
  248. {
  249.     short        i;
  250.     PPInfoRec    InfoRec;
  251.     
  252.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  253.     {
  254.         if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
  255.         {
  256.             *theNewMAD = (MADMusic*) MADNewPtrClear( sizeof( MADMusic), inMADDriver);
  257.             if( !*theNewMAD) return -1L;
  258. //            (*theNewMAD)->currentDriver = 0L;
  259.             
  260.             return( CallImportPlug( i, 'IMPL', AlienFile, *theNewMAD, &InfoRec));
  261.         }
  262.     }
  263.     return MADCannotFindPlug;
  264. }
  265.  
  266. OSErr CheckMADFile( Ptr name)
  267. {
  268.     UNFILE            refNum;
  269.     char                charl[ 10];
  270.     OSErr                err;
  271.     
  272.     refNum = iFileOpen( name);
  273.     if( !refNum) return -1;
  274.     else
  275.     {
  276.         iRead( 10, charl, refNum);
  277.         
  278.         if( charl[ 0] == 'M' &&
  279.                 charl[ 1] == 'A' &&
  280.                 charl[ 2] == 'D' &&
  281.                 charl[ 3] == 'H') err = noErr;
  282.         else err = -1;
  283.         
  284.         iClose( refNum);
  285.     }
  286.     
  287.     return err;
  288. }
  289.  
  290. OSErr    PPIdentifyFile( char *type, char *AlienFile)
  291. {
  292.     UNFILE            refNum;
  293.     short                i;
  294.     PPInfoRec        InfoRec;
  295.     OSErr                iErr = noErr;
  296.     
  297.     MADstrcpy( type, "!!!!");
  298.     
  299.     // Check if we have access to this file
  300.     refNum = iFileOpen( AlienFile);
  301.     if( !refNum) return -1;
  302.     else
  303.     {
  304.         if( iGetEOF( refNum) < 100) iErr = -36;
  305.         iClose( refNum);
  306.         if( iErr) return iErr;
  307.     }
  308.     
  309.     // Is it a MAD file?
  310.     iErr = CheckMADFile( AlienFile);
  311.     if( iErr == noErr)
  312.     {
  313.         MADstrcpy( type, "MADH");
  314.         return noErr;
  315.     }
  316.     
  317.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  318.     {
  319.         if( CallImportPlug( i, 'TEST', AlienFile, 0L, &InfoRec) == noErr)
  320.         {
  321.             MADstrcpy( type, inMADDriver->ThePlug[ i].type);
  322.             
  323.             return noErr;
  324.         }
  325.     }
  326.     
  327.     MADstrcpy( type, "!!!!");
  328.     return MADCannotFindPlug;
  329. }
  330.  
  331. OSType    GetPPPlugType( short ID, OSType mode)
  332. {
  333.     short    i, x;
  334.  
  335.     if( ID >= inMADDriver->TotalPlug) DebugStr("\pPP-Plug ERROR. ");
  336.  
  337.     for( i = 0, x = 0; i < inMADDriver->TotalPlug; i++)
  338.     {
  339.         if( inMADDriver->ThePlug[ i].mode == mode || inMADDriver->ThePlug[ i].mode == 'EXIM')
  340.         {
  341.             if( ID == x)
  342.             {
  343.                 short     xx;
  344.                 OSType    type;
  345.                 
  346.                 xx = strlen( inMADDriver->ThePlug[ i].type);
  347.                 if( xx > 4) xx = 4;
  348.                 type = '    ';
  349.                 BlockMove( inMADDriver->ThePlug[ i].type, &type, xx);
  350.  
  351.                 return type;
  352.             }
  353.             x++;
  354.         }
  355.     }
  356.  
  357.     DebugStr("\pPP-Plug ERROR II.");
  358.     
  359.     return noErr;
  360. }
  361.  
  362. Boolean    MADPlugAvailable( char    *kindFile)
  363. {
  364.     short        i;
  365.  
  366.     if( !MADstrcmp( kindFile, "MADH")) return true;
  367.     
  368.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  369.     {
  370.         if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type)) return true;
  371.     }
  372.     return false;
  373. }
  374.  
  375. void LoadImportPLUG( short    No, FSSpec    *theSpec)
  376. {
  377. Handle        theRes;
  378. short        fileID;
  379. Str255        tStr;
  380.  
  381.     inMADDriver->ThePlug[ No].file = *theSpec;
  382.     
  383.     fileID = FSpOpenResFile( theSpec, fsCurPerm);
  384.     
  385.     /** CODE du Plug-in **/
  386.     
  387.     #if defined(powerc) || defined (__powerc)
  388.         theRes = MADGet1Resource('PPCC', 1000, inMADDriver);
  389.         if( theRes != 0L)
  390.         {
  391.             inMADDriver->ThePlug[ No].hasPPCCode = true;
  392.         }
  393.         else
  394.         {
  395.             inMADDriver->ThePlug[ No].hasPPCCode = false;
  396.             theRes = MADGet1Resource('CODE', 1000, inMADDriver);
  397.         }
  398.         if( theRes == 0L) DebugStr( "\pErr Plug");
  399.         if( *theRes == 0L) DebugStr( "\pErr Plug Rsrc Second Level");
  400.         
  401.         inMADDriver->ThePlug[ No].IOPlug        = theRes;
  402.     #else
  403.         theRes = MADGet1Resource('CODE', 1000, inMADDriver);
  404.         if( theRes == 0L) DebugStr( "\pErr Plug");
  405.         if( *theRes == 0L) DebugStr( "\pErr Plug Rsrc Second Level");
  406.         
  407.         inMADDriver->ThePlug[ No].IOPlug        = theRes;
  408.     #endif
  409.     
  410.     GetIndString( tStr, 1000, 1);
  411.     BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].type, 4);
  412.     inMADDriver->ThePlug[ No].type[ 4] = 0;
  413.     
  414.     GetIndString( tStr, 1000, 2);
  415.     BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4);
  416.     
  417.     GetIndString( inMADDriver->ThePlug[ No].MenuName, 1000, 3);
  418.     GetIndString( inMADDriver->ThePlug[ No].AuthorString, 1000, 4);
  419.     
  420.     CloseResFile( fileID);
  421. }
  422.  
  423. void NScanDirImportPlug( long dirID, short VRefNum, Str255    Fname)
  424. {
  425.         CInfoPBRec        info;
  426.         Str255            tempStr;
  427.         short            i;
  428.         Boolean            targetIsFolder, wasAliased;
  429.         FSSpec            theSpec;
  430.         FInfo            fndrInfo;
  431.  
  432.     info.hFileInfo.ioNamePtr = tempStr;
  433.     info.hFileInfo.ioVRefNum = VRefNum;
  434.     
  435.     for (i = 1; true; i ++)
  436.     {
  437.         info.hFileInfo.ioDirID            = dirID;
  438.         info.hFileInfo.ioFDirIndex        = i;
  439.         
  440.         if (PBGetCatInfoSync( &info) != noErr) break;
  441.         
  442.         FSMakeFSSpec( info.hFileInfo.ioVRefNum, dirID, info.hFileInfo.ioNamePtr, &theSpec);
  443.         ResolveAliasFile( &theSpec, true, &targetIsFolder, &wasAliased);
  444.         FSpGetFInfo( &theSpec, &fndrInfo);
  445.         
  446.         if( targetIsFolder)            //if((info.hFileInfo.ioFlAttrib & 16))
  447.         {
  448.             if( Fname[ 0] > 0)
  449.             {
  450.                 if( EqualString( info.hFileInfo.ioNamePtr, Fname, false, false))    // == true ||
  451.                 //    EqualString( theSpec.name, Fname, false, false) == true)
  452.                 {
  453.                     CInfoPBRec        ci;
  454.  
  455.                     ci.hFileInfo.ioNamePtr         = theSpec.name;
  456.                     ci.hFileInfo.ioVRefNum         = theSpec.vRefNum;
  457.                     ci.hFileInfo.ioDirID          = theSpec.parID;
  458.                     ci.hFileInfo.ioFDirIndex    = 0;
  459.                     
  460.                     PBGetCatInfoSync( &ci);
  461.                     
  462.                     NScanDirImportPlug( ci.hFileInfo.ioDirID, ci.hFileInfo.ioVRefNum, Fname);
  463.                 }
  464.             }
  465.         }
  466.         else if( fndrInfo.fdType == 'IMPL')            //if( info.hFileInfo.ioFlFndrInfo.fdType == 'IMPL')
  467.         {
  468.         //    HGetVol( 0L, &vRefNum, &dirIDCopy);
  469.         ////    
  470.         //    iErr = HSetVol( 0L, theSpec.vRefNum, theSpec.parID);
  471.             
  472.             if( inMADDriver->TotalPlug < MAXPLUG)
  473.             {
  474.                 LoadImportPLUG( inMADDriver->TotalPlug, &theSpec);
  475.                 inMADDriver->TotalPlug++;
  476.             }
  477.             
  478.         //    iErr = HSetVol( 0L, vRefNum, dirIDCopy);
  479.         //    if( iErr != noErr) DebugStr("\pHSetVol error...");
  480.         }
  481.     }
  482. }
  483.  
  484. /*void InitImportMenu(void)
  485. {
  486. short    i;
  487.  
  488.     ImportMenu    = GetMenu( 138);
  489.     ExportMenu    = GetMenu( 139);
  490.  
  491.  
  492.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  493.     {
  494.         switch( inMADDriver->ThePlug[ i].mode)
  495.         {
  496.             case 'EXIM':
  497.                 AppendMenu( ImportMenu, inMADDriver->ThePlug[ i].MenuName);
  498.                 AppendMenu( ExportMenu, inMADDriver->ThePlug[ i].MenuName);
  499.             break;
  500.             
  501.             case 'EXPL':
  502.                 AppendMenu( ExportMenu, inMADDriver->ThePlug[ i].MenuName);
  503.             break;
  504.             
  505.             case 'IMPL':
  506.                 AppendMenu( ImportMenu, inMADDriver->ThePlug[ i].MenuName);
  507.             break;
  508.         }
  509.     }
  510.  
  511.     InsertMenu( ImportMenu, hierMenu);
  512.     InsertMenu( ExportMenu, hierMenu);
  513. }*/
  514.  
  515. void NScanResource()
  516. {
  517.     short    i;
  518.     
  519.     #define BASERES    5000
  520.     
  521.     for( i = 0; i < MAXPLUG; i++)
  522.     {
  523.         Boolean ResourceOK;
  524.         Handle    aRes, bRes;
  525.         
  526.         ResourceOK = true;
  527.         
  528.         aRes = MADGet1Resource( 'CODE', BASERES + i, inMADDriver);
  529.         if( aRes == 0L) ResourceOK = false;
  530.         else
  531.         {
  532.             DisposeHandle( aRes);
  533.             aRes = 0L;
  534.         }
  535.         
  536.         bRes = MADGet1Resource( 'STR#', BASERES + i, inMADDriver);
  537.         if( bRes == 0L) ResourceOK = false;
  538.         else
  539.         {
  540.             DisposeHandle( bRes);
  541.             bRes = 0L;
  542.         }
  543.         
  544.         if( inMADDriver->TotalPlug < MAXPLUG && ResourceOK == true)
  545.         {
  546.             short        No = inMADDriver->TotalPlug;
  547.             Handle        theRes;
  548.             Str255        tStr;
  549.             
  550.         //    theName = LMGetCurApName();
  551.             
  552.             HGetVol( 0L, &inMADDriver->ThePlug[ No].file.vRefNum, &inMADDriver->ThePlug[ No].file.parID);
  553.             pStrCpy( inMADDriver->ThePlug[ No].file.name, RSRCNAME);
  554.             
  555.             /** CODE du Plug-in **/
  556.             
  557.             #if defined(powerc) || defined (__powerc)
  558.                 theRes = MADGet1Resource('PPCC', BASERES+i, inMADDriver);
  559.                 if( theRes != 0L)
  560.                 {
  561.                     inMADDriver->ThePlug[ No].hasPPCCode = true;
  562.                 }
  563.                 else
  564.                 {
  565.                     inMADDriver->ThePlug[ No].hasPPCCode = false;
  566.                     theRes = MADGet1Resource('CODE', BASERES+i, inMADDriver);
  567.                 }
  568.                 if( theRes == 0L) DebugStr( "\pErr Plug Rsrc");
  569.                 if( *theRes == 0L) DebugStr( "\pErr Plug Rsrc Second Level");
  570.                 
  571.                 inMADDriver->ThePlug[ No].IOPlug        = theRes;
  572.             #else
  573.                 theRes = MADGet1Resource('CODE', BASERES+i, inMADDriver);
  574.                 if( theRes == 0L) DebugStr( "\pErr Plug Rsrc");
  575.                 if( *theRes == 0L) DebugStr( "\pErr Plug Rsrc Second Level");
  576.                 inMADDriver->ThePlug[ No].IOPlug        = theRes;
  577.             #endif
  578.             
  579.             GetIndString( tStr, BASERES+i, 1);
  580.             BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].type, 4);
  581.             inMADDriver->ThePlug[ No].type[ 4] = 0;
  582.             
  583.             GetIndString( tStr, BASERES+i, 2);
  584.             BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4);
  585.             
  586.             GetIndString( inMADDriver->ThePlug[ No].MenuName, BASERES+i, 3);
  587.             GetIndString( inMADDriver->ThePlug[ No].AuthorString, BASERES+i, 4);
  588.             
  589.             inMADDriver->TotalPlug++;
  590.         }
  591.     }
  592. }
  593.  
  594. void MInitImportPlug( Ptr PlugsFolderName)
  595. {
  596.     short        vRefNum;
  597.     long        dirID;
  598.     
  599.     inMADDriver = MADGetMADLibraryPtr();
  600.     
  601.     HGetVol( 0L, &vRefNum, &dirID);
  602.     
  603.     inMADDriver->ThePlug = (PlugInfo*) MADNewPtr( MAXPLUG * sizeof( PlugInfo), inMADDriver);
  604.     inMADDriver->TotalPlug = 0;
  605.     
  606.     c2pstr( PlugsFolderName);
  607.     NScanDirImportPlug( dirID, vRefNum, (unsigned char*) PlugsFolderName);
  608.     p2cstr( (unsigned char*) PlugsFolderName);
  609.     
  610.     HSetVol( 0L, vRefNum, dirID);
  611.     
  612.     NScanResource();
  613. }
  614.  
  615. void CloseImportPlug()
  616. {
  617. short    i;
  618.  
  619.     for( i = 0; i < inMADDriver->TotalPlug; i++)
  620.     {
  621.         if( inMADDriver->ThePlug[ i].IOPlug != 0L)
  622.             DisposeHandle( inMADDriver->ThePlug[ i].IOPlug);
  623.         
  624.         inMADDriver->ThePlug[ i].IOPlug = 0L;
  625.     }
  626.  
  627.     DisposePtr( (Ptr) inMADDriver->ThePlug);        inMADDriver->ThePlug = 0L;
  628. }