home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / terminal / term / extras / source / term-source.lha / termVerify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-26  |  14.8 KB  |  835 lines

  1. /*
  2. **    termVerify.c
  3. **
  4. **    Check if files/drawers/programs are where they should be
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14. struct Path
  15. {
  16.     BPTR    path_Next,
  17.             path_Lock;
  18. };
  19.  
  20.     /* FindPath(struct Window *Parent,STRPTR Path,BOOLEAN CanCreate,LONG *Error):
  21.      *
  22.      *    For the complete path of a file, this checks if the
  23.      *    path leading to the file actually exists. This is
  24.      *    primarily for files the program should create. Thus,
  25.      *    the file in question may not yet exist.
  26.      */
  27.  
  28. BOOLEAN __regargs
  29. FindPath(struct Window *Parent,STRPTR Path,BOOLEAN CanCreate,LONG *Error)
  30. {
  31.     UBYTE    LocalBuffer[MAX_FILENAME_LENGTH];
  32.     STRPTR    Index;
  33.  
  34.     strcpy(LocalBuffer,Path);
  35.  
  36.     Index = PathPart(LocalBuffer);
  37.  
  38.     *Index = 0;
  39.  
  40.     return(FindDrawer(Parent,LocalBuffer,CanCreate,Error));
  41. }
  42.  
  43.     /* FindDrawer(struct Window *Parent,STRPTR Drawer,BOOLEAN CanCreate,LONG *Error):
  44.      *
  45.      *    Check if a given drawer exists and give
  46.      *    the user the choice to create it if necessary.
  47.      */
  48.  
  49. BOOLEAN __regargs
  50. FindDrawer(struct Window *Parent,STRPTR Drawer,BOOLEAN CanCreate,LONG *Error)
  51. {
  52.     APTR    OldPtr = ThisProcess -> pr_WindowPtr;
  53.     BPTR    FileLock;
  54.     BOOLEAN    Result = FALSE;
  55.     LONG    LocalError;
  56.  
  57.     if(!Config -> MiscConfig -> ProtectiveMode)
  58.         return(TRUE);
  59.  
  60.     if(!Error)
  61.         Error = &LocalError;
  62.  
  63.         // Lock out DOS requesters
  64.  
  65.     ThisProcess -> pr_WindowPtr = (APTR)-1;
  66.  
  67.         // Does the drawer exist?
  68.  
  69.     if(FileLock = Lock(Drawer,ACCESS_READ))
  70.     {
  71.         struct FileInfoBlock __aligned FileInfo;
  72.  
  73.             // Take a closer look
  74.  
  75.         if(Examine(FileLock,&FileInfo))
  76.         {
  77.                 // Is this actually a file?
  78.  
  79.             if(FileInfo . fib_DirEntryType < 0)
  80.                 *Error = ERR_NOT_A_DRAWER;
  81.             else
  82.             {
  83.                 *Error = 0;
  84.  
  85.                 Result = TRUE;
  86.             }
  87.         }
  88.         else
  89.             *Error = IoErr();
  90.  
  91.         UnLock(FileLock);
  92.     }
  93.     else
  94.     {
  95.         LONG Result2 = IoErr();
  96.  
  97.             // If it doesn't exist, see if we should ask the user to create it
  98.  
  99.         if(Result2 == ERROR_OBJECT_NOT_FOUND && Parent && CanCreate)
  100.         {
  101.             UBYTE    LocalBuffer[MAX_FILENAME_LENGTH];
  102.             STRPTR    Index;
  103.             BOOLEAN    CanCreate = FALSE;
  104.  
  105.                 // Chop off the last path part
  106.  
  107.             strcpy(LocalBuffer,Drawer);
  108.  
  109.             Index = PathPart(LocalBuffer);
  110.  
  111.             *Index = 0;
  112.  
  113.                 // Get a lock on the parent drawer
  114.  
  115.             if(FileLock = Lock(LocalBuffer,ACCESS_READ))
  116.             {
  117.                 struct InfoData __aligned InfoData;
  118.  
  119.                     // Inquire volume information
  120.  
  121.                 if(Info(FileLock,&InfoData))
  122.                 {
  123.                         // Can we write to this volume?
  124.  
  125.                     if(InfoData . id_DiskState == ID_VALIDATED)
  126.                         CanCreate = TRUE;
  127.                 }
  128.  
  129.                 UnLock(FileLock);
  130.             }
  131.  
  132.                 // Give it a try?
  133.  
  134.             if(CanCreate)
  135.             {
  136.                 LT_LockWindow(Parent);
  137.  
  138.                     // Ask if we should create it
  139.  
  140.                 if(MyEasyRequest(Parent,LocaleString(MSG_VERIFY_NO_DRAWER_TXT),LocaleString(MSG_GLOBAL_YES_NO_TXT),Drawer))
  141.                 {
  142.                     if(FileLock = CreateDir(Drawer))
  143.                     {
  144.                         Result2 = 0;
  145.  
  146.                         Result = TRUE;
  147.  
  148.                         UnLock(FileLock);
  149.                     }
  150.                     else
  151.                         Result2 = IoErr();
  152.                 }
  153.                 else
  154.                 {
  155.                     Result2 = 0;
  156.                     Result = TRUE;
  157.                 }
  158.  
  159.                 LT_UnlockWindow(Parent);
  160.             }
  161.         }
  162.  
  163.         *Error = Result2;
  164.     }
  165.  
  166.     ThisProcess -> pr_WindowPtr = OldPtr;
  167.  
  168.     if(Window && !Result && *Error)
  169.     {
  170.         LT_LockWindow(Parent);
  171.  
  172.         if(*Error == ERR_NOT_A_DRAWER)
  173.             ShowError(Parent,*Error,NULL,Drawer);
  174.         else
  175.             ShowError(Parent,ERR_DRAWER_NOT_FOUND,*Error,Drawer);
  176.  
  177.         LT_UnlockWindow(Parent);
  178.     }
  179.  
  180.     return(Result);
  181. }
  182.  
  183.     /* FindFile(struct Window *Parent,STRPTR File,LONG *Error):
  184.      *
  185.      *    Try to locate a file.
  186.      */
  187.  
  188. BOOLEAN __regargs
  189. FindFile(struct Window *Parent,STRPTR File,LONG *Error)
  190. {
  191.     APTR    OldPtr = ThisProcess -> pr_WindowPtr;
  192.     BPTR    FileLock;
  193.     BOOLEAN    Result = FALSE;
  194.     LONG    LocalError;
  195.  
  196.     if(!Config -> MiscConfig -> ProtectiveMode)
  197.         return(TRUE);
  198.  
  199.     if(!Error)
  200.         Error = &LocalError;
  201.  
  202.         // Lock out DOS requesters
  203.  
  204.     ThisProcess -> pr_WindowPtr = (APTR)-1;
  205.  
  206.         // Try to get a lock on the file
  207.  
  208.     if(FileLock = Lock(File,ACCESS_READ))
  209.     {
  210.         struct FileInfoBlock __aligned FileInfo;
  211.  
  212.             // Take a closer look
  213.  
  214.         if(Examine(FileLock,&FileInfo))
  215.         {
  216.                 // Is it actually a drawer?
  217.  
  218.             if(FileInfo . fib_DirEntryType > 0)
  219.                 *Error = ERR_NOT_A_FILE;
  220.             else
  221.             {
  222.                 *Error = 0;
  223.  
  224.                 Result = TRUE;
  225.             }
  226.         }
  227.         else
  228.             *Error = IoErr();
  229.  
  230.         UnLock(FileLock);
  231.     }
  232.     else
  233.         *Error = IoErr();
  234.  
  235.     ThisProcess -> pr_WindowPtr = OldPtr;
  236.  
  237.     if(Window && !Result && *Error)
  238.     {
  239.         LT_LockWindow(Parent);
  240.  
  241.         if(*Error == ERR_NOT_A_FILE)
  242.             ShowError(Parent,*Error,NULL,File);
  243.         else
  244.             ShowError(Parent,ERR_FILE_NOT_FOUND,*Error,File);
  245.  
  246.         LT_UnlockWindow(Parent);
  247.     }
  248.  
  249.     return(Result);
  250. }
  251.  
  252.     /* FindARexxComment(STRPTR LocalBuffer,LONG Len):
  253.      *
  254.      *    Check for a valid ARexx file comment.
  255.      */
  256.  
  257. STATIC BOOLEAN __regargs
  258. FindARexxComment(STRPTR LocalBuffer,LONG Len)
  259. {
  260.     register WORD    i;
  261.     register UBYTE    c;
  262.  
  263.     for(i = 0 ; i < Len - 1 ; i++)
  264.     {
  265.         c = LocalBuffer[i];
  266.  
  267.             // Stop on invalid characters.
  268.  
  269.         if((c < ' ' && c != '\r' && c != '\n' && c != '\a') || (c >= 127 && c < 160))
  270.             break;
  271.         else
  272.         {
  273.                 // Looks like the typical
  274.                 // introductory comment line.
  275.  
  276.             if(c == '/' && LocalBuffer[i + 1] == '*')
  277.                 return(TRUE);
  278.         }
  279.     }
  280.  
  281.     return(FALSE);
  282. }
  283.  
  284.     /* FindProgram(struct Window *Parent,STRPTR Program,LONG *Error):
  285.      *
  286.      *    Try to find a program given by name. Firstly, try to access the
  287.      *    file by its name. If unsuccessful, search the Shell path list.
  288.      *    As a last resort, search the global AmigaDOS resident program
  289.      *    list. Note that while this routine may fail program execution
  290.      *    may still work. WShell for example maintains its own internal
  291.      *    resident list.
  292.      */
  293.  
  294. BOOLEAN __regargs
  295. FindProgram(struct Window *Parent,STRPTR Program,LONG *Error)
  296. {
  297.     UBYTE    LocalBuffer[MAX_FILENAME_LENGTH];
  298.     APTR    OldPtr = ThisProcess -> pr_WindowPtr;
  299.     BPTR    FileLock;
  300.     WORD    i;
  301.     BOOLEAN    Result        = FALSE,
  302.             CanExecute    = FALSE;
  303.     LONG    LocalError;
  304.  
  305.     if(!Config -> MiscConfig -> ProtectiveMode)
  306.         return(TRUE);
  307.  
  308.     if(!Error)
  309.         Error = &LocalError;
  310.  
  311.         // Chop off the program arguments
  312.  
  313.     while(*Program == ' ')
  314.         Program++;
  315.  
  316.     strcpy(LocalBuffer,Program);
  317.  
  318.     for(i = 0 ; i < strlen(LocalBuffer) ; i++)
  319.     {
  320.         if(LocalBuffer[i] == ' ')
  321.         {
  322.             LocalBuffer[i] = 0;
  323.  
  324.             break;
  325.         }
  326.     }
  327.  
  328.     Program = LocalBuffer;
  329.  
  330.         // Lock out DOS requesters
  331.  
  332.     ThisProcess -> pr_WindowPtr = (APTR)-1;
  333.  
  334.         // Try to lock the program
  335.  
  336.     if(FileLock = Lock(Program,ACCESS_READ))
  337.     {
  338.         struct FileInfoBlock __aligned FileInfo;
  339.  
  340.             // Take a closer look
  341.  
  342.         if(Examine(FileLock,&FileInfo))
  343.         {
  344.                 // Is it actually a drawer?
  345.  
  346.             if(FileInfo . fib_DirEntryType > 0)
  347.                 *Error = ERR_NOT_A_FILE;
  348.             else
  349.             {
  350.                 BOOLEAN GotIt = FALSE;
  351.  
  352.                     // So far, so good
  353.  
  354.                 *Error = 0;
  355.  
  356.                 Result = TRUE;
  357.  
  358.                     // Is it marked as being executable?
  359.  
  360.                 if(!(FileInfo . fib_Protection & FIBF_EXECUTE))
  361.                 {
  362.                     BPTR    FileHandle;
  363.                     ULONG    Value;
  364.  
  365.                         // Look at the contents
  366.  
  367.                     if(FileHandle = Open(Program,MODE_OLDFILE))
  368.                     {
  369.                         if(Read(FileHandle,&Value,sizeof(ULONG)) == sizeof(ULONG))
  370.                         {
  371.                                 // Not a failproof check, but better than nothing
  372.  
  373.                             if(Value == HUNK_HEADER)
  374.                             {
  375.                                 CanExecute = TRUE;
  376.                                 GotIt = TRUE;
  377.                             }
  378.                         }
  379.  
  380.                         Close(FileHandle);
  381.                     }
  382.                 }
  383.  
  384.                 if(!GotIt)
  385.                 {
  386.                         // Does it have the script bit set? */
  387.  
  388.                     if(FileInfo . fib_Protection & FIBF_SCRIPT)
  389.                         CanExecute = TRUE;
  390.                     else
  391.                     {
  392.                         BPTR FileHandle;
  393.  
  394.                             // Now check if it's an ARexx script.
  395.  
  396.                         if(FileHandle = Open(Program,MODE_OLDFILE))
  397.                         {
  398.                             UBYTE    LocalBuffer[256];
  399.                             LONG    Len;
  400.  
  401.                             if((Len = Read(FileHandle,LocalBuffer,256)) > 0)
  402.                             {
  403.                                 if(CanExecute = FindARexxComment(LocalBuffer,Len))
  404.                                     Result = TRUE;
  405.                             }
  406.  
  407.                             Close(FileHandle);
  408.                         }
  409.                     }
  410.                 }
  411.             }
  412.         }
  413.  
  414.         UnLock(FileLock);
  415.     }
  416.     else
  417.     {
  418.         LONG Result2 = IoErr();
  419.  
  420.         if(Result2 == ERROR_DEVICE_NOT_MOUNTED)
  421.             *Error = ERROR_OBJECT_NOT_FOUND;
  422.         else
  423.             *Error = Result2;
  424.     }
  425.  
  426.         // Give it another try
  427.  
  428.     if(!Result || !CanExecute)
  429.     {
  430.             // Take care
  431.  
  432.         if(ThisProcess -> pr_CLI)
  433.         {
  434.             struct CommandLineInterface    *CLI = BADDR(ThisProcess -> pr_CLI);
  435.             BPTR                         StartCD,
  436.                                          Drawer;
  437.             struct Path                    *Path;
  438.             BOOLEAN                         InitialCD    = TRUE,
  439.                                          GotIt        = FALSE;
  440.  
  441.                 // Run down the Shell path search list
  442.  
  443.             for(Path = BADDR(CLI -> cli_CommandDir) ; Path && !GotIt ; Path = BADDR(Path -> path_Next))
  444.             {
  445.                 Drawer = CurrentDir(Path -> path_Lock);
  446.  
  447.                 if(InitialCD)
  448.                 {
  449.                     StartCD        = Drawer;
  450.                     InitialCD    = FALSE;
  451.                 }
  452.  
  453.                     // Try to lock the program
  454.  
  455.                 if(FileLock = Lock(Program,ACCESS_READ))
  456.                 {
  457.                     struct FileInfoBlock __aligned FileInfo;
  458.  
  459.                         // Take a closer look
  460.  
  461.                     if(Examine(FileLock,&FileInfo))
  462.                     {
  463.                             // Is this a file marked as being executable?
  464.  
  465.                         if(FileInfo . fib_DirEntryType < 0)
  466.                         {
  467.                             if(!(FileInfo . fib_Protection & FIBF_EXECUTE))
  468.                             {
  469.                                 BPTR    FileHandle;
  470.                                 ULONG    Value;
  471.  
  472.                                     // Look at the contents
  473.  
  474.                                 if(FileHandle = Open(Program,MODE_OLDFILE))
  475.                                 {
  476.                                     if(Read(FileHandle,&Value,sizeof(ULONG)) == sizeof(ULONG))
  477.                                     {
  478.                                             // Not a failproof check, but better than nothing
  479.  
  480.                                         if(Value == HUNK_HEADER)
  481.                                             GotIt = TRUE;
  482.                                     }
  483.  
  484.                                     Close(FileHandle);
  485.                                 }
  486.                             }
  487.  
  488.                             if(!GotIt)
  489.                             {
  490.                                     // Does it look like a script?
  491.  
  492.                                 if(FileInfo . fib_Protection & FIBF_SCRIPT)
  493.                                     GotIt = TRUE;
  494.                                 else
  495.                                 {
  496.                                     BPTR FileHandle;
  497.  
  498.                                         // Now check if it's an ARexx script.
  499.  
  500.                                     if(FileHandle = Open(Program,MODE_OLDFILE))
  501.                                     {
  502.                                         UBYTE    LocalBuffer[256];
  503.                                         LONG    Len;
  504.  
  505.                                         if((Len = Read(FileHandle,LocalBuffer,256)) > 0)
  506.                                         {
  507.                                             if(CanExecute = FindARexxComment(LocalBuffer,Len))
  508.                                                 GotIt = TRUE;
  509.                                         }
  510.  
  511.                                         Close(FileHandle);
  512.                                     }
  513.                                 }
  514.                             }
  515.                         }
  516.                     }
  517.  
  518.                     UnLock(FileLock);
  519.                 }
  520.             }
  521.  
  522.             if(!GotIt)
  523.             {
  524.                 BPTR CommandDir = Lock("C:",ACCESS_READ);
  525.  
  526.                 Drawer = CurrentDir(CommandDir);
  527.  
  528.                 if(InitialCD)
  529.                 {
  530.                     StartCD        = Drawer;
  531.                     InitialCD    = FALSE;
  532.                 }
  533.  
  534.                     // Try to lock the program
  535.  
  536.                 if(FileLock = Lock(Program,ACCESS_READ))
  537.                 {
  538.                     struct FileInfoBlock __aligned FileInfo;
  539.  
  540.                         // Take a closer look
  541.  
  542.                     if(Examine(FileLock,&FileInfo))
  543.                     {
  544.                             // Is this a file marked as being executable?
  545.  
  546.                         if(FileInfo . fib_DirEntryType < 0)
  547.                         {
  548.                             if(!(FileInfo . fib_Protection & FIBF_EXECUTE))
  549.                             {
  550.                                 BPTR    FileHandle;
  551.                                 ULONG    Value;
  552.  
  553.                                     // Look at the contents
  554.  
  555.                                 if(FileHandle = Open(Program,MODE_OLDFILE))
  556.                                 {
  557.                                     if(Read(FileHandle,&Value,sizeof(ULONG)) == sizeof(ULONG))
  558.                                     {
  559.                                             // Not a failproof check, but better than nothing
  560.  
  561.                                         if(Value == HUNK_HEADER)
  562.                                             GotIt = TRUE;
  563.                                     }
  564.  
  565.                                     Close(FileHandle);
  566.                                 }
  567.                             }
  568.  
  569.                             if(!GotIt)
  570.                             {
  571.                                     // Does it look like a script?
  572.  
  573.                                 if(FileInfo . fib_Protection & FIBF_SCRIPT)
  574.                                     GotIt = TRUE;
  575.                                 else
  576.                                 {
  577.                                     BPTR FileHandle;
  578.  
  579.                                         // Now check if it's an ARexx script.
  580.  
  581.                                     if(FileHandle = Open(Program,MODE_OLDFILE))
  582.                                     {
  583.                                         UBYTE    LocalBuffer[256];
  584.                                         LONG    Len;
  585.  
  586.                                         if((Len = Read(FileHandle,LocalBuffer,256)) > 0)
  587.                                         {
  588.                                             if(CanExecute = FindARexxComment(LocalBuffer,Len))
  589.                                                 GotIt = TRUE;
  590.                                         }
  591.  
  592.                                         Close(FileHandle);
  593.                                     }
  594.                                 }
  595.                             }
  596.                         }
  597.                     }
  598.  
  599.                     UnLock(FileLock);
  600.                 }
  601.  
  602.                 UnLock(CommandDir);
  603.             }
  604.  
  605.             if(!InitialCD)
  606.                 CurrentDir(StartCD);
  607.  
  608.             if(GotIt)
  609.             {
  610.                 CanExecute = TRUE;
  611.  
  612.                 *Error = 0;
  613.  
  614.                 Result = TRUE;
  615.             }
  616.         }
  617.     }
  618.  
  619.         // As a last resort, scan the resident program list
  620.  
  621.     if(!Result)
  622.     {
  623.         Forbid();
  624.  
  625.         if(FindSegment(Program,NULL,DOSFALSE) || FindSegment(Program,NULL,DOSTRUE))
  626.         {
  627.             CanExecute = TRUE;
  628.  
  629.             *Error = 0;
  630.  
  631.             Result = TRUE;
  632.         }
  633.  
  634.         Permit();
  635.     }
  636.  
  637.         // Last check for ARexx script.
  638.  
  639.     if(!Result)
  640.     {
  641.         UBYTE RexxName[MAX_FILENAME_LENGTH];
  642.  
  643.         strcpy(RexxName,"REXX:");
  644.  
  645.         if(AddPart(RexxName,Program,MAX_FILENAME_LENGTH))
  646.         {
  647.             BPTR FileHandle;
  648.  
  649.                 // Now check if it's an ARexx script.
  650.  
  651.             if(FileHandle = Open(RexxName,MODE_OLDFILE))
  652.             {
  653.                 UBYTE    LocalBuffer[256];
  654.                 LONG    Len;
  655.  
  656.                 if((Len = Read(FileHandle,LocalBuffer,256)) > 0)
  657.                 {
  658.                     if(CanExecute = FindARexxComment(LocalBuffer,Len))
  659.                         Result = TRUE;
  660.                 }
  661.  
  662.                 Close(FileHandle);
  663.             }
  664.         }
  665.     }
  666.  
  667.         // Last check for AmigaDOS script
  668.  
  669.     if(!Result)
  670.     {
  671.         UBYTE ScriptName[MAX_FILENAME_LENGTH];
  672.  
  673.         strcpy(ScriptName,"S:");
  674.  
  675.         if(AddPart(ScriptName,Program,MAX_FILENAME_LENGTH))
  676.         {
  677.             BPTR FileLock;
  678.  
  679.             if(FileLock = Lock(ScriptName,ACCESS_READ))
  680.             {
  681.                 struct FileInfoBlock __aligned FileInfo;
  682.  
  683.                 if(Examine(FileLock,&FileInfo))
  684.                 {
  685.                     if(FileInfo . fib_DirEntryType < 0 && (FileInfo . fib_Protection & FIBF_SCRIPT) && FileInfo . fib_Size > 0)
  686.                         CanExecute = Result = TRUE;
  687.                 }
  688.  
  689.                 UnLock(FileLock);
  690.             }
  691.         }
  692.     }
  693.  
  694.     if(!CanExecute && Result)
  695.     {
  696.         *Error = ERROR_NOT_EXECUTABLE;
  697.  
  698.         Result = FALSE;
  699.     }
  700.  
  701.     ThisProcess -> pr_WindowPtr = OldPtr;
  702.  
  703.     if(Window && !Result && *Error)
  704.     {
  705.         LT_LockWindow(Parent);
  706.  
  707.         if(*Error == ERR_NOT_A_FILE)
  708.             ShowError(Parent,*Error,NULL,Program);
  709.         else
  710.             ShowError(Parent,ERR_PROGRAM_NOT_FOUND,*Error,Program);
  711.  
  712.         LT_UnlockWindow(Parent);
  713.     }
  714.  
  715.     return(Result);
  716. }
  717.  
  718.     /* FindLibDev(struct Window *Parent,STRPTR File,LONG Type,LONG *Error):
  719.      *
  720.      *    Try to locate a file.
  721.      */
  722.  
  723. BOOLEAN __regargs
  724. FindLibDev(struct Window *Parent,STRPTR File,LONG Type,LONG *Error)
  725. {
  726.     UBYTE         LocalBuffer[MAX_FILENAME_LENGTH];
  727.     STRPTR         OriginalFile;
  728.     APTR         OldPtr = ThisProcess -> pr_WindowPtr;
  729.     BPTR         FileLock;
  730.     BOOLEAN         Result        = FALSE,
  731.                  Replaced    = FALSE;
  732.     LONG         LocalError;
  733.     struct Node    *Node;
  734.  
  735.     if(!Config -> MiscConfig -> ProtectiveMode)
  736.         return(TRUE);
  737.  
  738.     if(!Error)
  739.         Error = &LocalError;
  740.  
  741.     Forbid();
  742.  
  743.     if(Type == NT_LIBRARY)
  744.         Node = FindName(&SysBase -> LibList,PathPart(File));
  745.     else
  746.         Node = FindName(&SysBase -> DeviceList,PathPart(File));
  747.  
  748.     Permit();
  749.  
  750.     if(Node)
  751.     {
  752.         *Error = 0;
  753.  
  754.         return(TRUE);
  755.     }
  756.  
  757.         // Lock out DOS requesters
  758.  
  759.     ThisProcess -> pr_WindowPtr = (APTR)-1;
  760.  
  761.         // Try to get a lock on the file
  762.  
  763. Look:
  764.  
  765.     if(FileLock = Lock(File,ACCESS_READ))
  766.     {
  767.         struct FileInfoBlock __aligned FileInfo;
  768.  
  769.             // Take a closer look
  770.  
  771.         if(Examine(FileLock,&FileInfo))
  772.         {
  773.                 // Is it actually a drawer?
  774.  
  775.             if(FileInfo . fib_DirEntryType > 0)
  776.                 *Error = ERR_NOT_A_FILE;
  777.             else
  778.             {
  779.                 if(ValidateFile(File,Type,NULL))
  780.                 {
  781.                     *Error = 0;
  782.  
  783.                     Result = TRUE;
  784.                 }
  785.                 else
  786.                     *Error = ERROR_OBJECT_WRONG_TYPE;
  787.             }
  788.         }
  789.         else
  790.             *Error = IoErr();
  791.  
  792.         UnLock(FileLock);
  793.     }
  794.     else
  795.         *Error = IoErr();
  796.  
  797.     if(!Result && !Replaced)
  798.     {
  799.         Replaced = TRUE;
  800.  
  801.         if(Type == NT_LIBRARY)
  802.             strcpy(LocalBuffer,"Libs:");
  803.         else
  804.             strcpy(LocalBuffer,"Devs:");
  805.  
  806.         OriginalFile = File;
  807.  
  808.         if(AddPart(LocalBuffer,File,MAX_FILENAME_LENGTH))
  809.         {
  810.             File = LocalBuffer;
  811.  
  812.             goto Look;
  813.         }
  814.     }
  815.  
  816.     if(Replaced)
  817.         File = OriginalFile;
  818.  
  819.     ThisProcess -> pr_WindowPtr = OldPtr;
  820.  
  821.     if(Window && !Result && *Error)
  822.     {
  823.         LT_LockWindow(Parent);
  824.  
  825.         if(*Error == ERR_NOT_A_FILE)
  826.             ShowError(Parent,*Error,NULL,File);
  827.         else
  828.             ShowError(Parent,ERR_FILE_NOT_FOUND,*Error,File);
  829.  
  830.         LT_UnlockWindow(Parent);
  831.     }
  832.  
  833.     return(Result);
  834. }
  835.