Ignore:
Timestamp:
Dec 17, 2014, 1:36:21 PM (11 years ago)
Author:
Alex Taylor
Message:

Updates for v0.50:
Moved much of the PPD-import logic into a shared function.
Automatically reimport previously-imported PPDs when updating to a new version of a known PostScript driver.
Ask if the user wants to update the active copy of a driver when the repository version is updated.
Fixed error in locating cupswiz.exe when the desktop object doesn't exist.
Fixed broken update of PRDESC.LST when upgrading to a new version of a known PostScript driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/shared/PrManUtl.VRS

    r45 r49  
    275275    copyfile = drv_dir'\AUXPRINT.PAK'
    276276    IF STREAM( copyfile, 'C', 'QUERY EXISTS') <> '' THEN DO
    277         ok = VRCopyFile( copyfile, newdrvdir'\AUXPRINT.PAK'
     277        ok = VRCopyFile( copyfile, newdrvdir'\AUXPRINT.PAK')
    278278        CALL LINEOUT globals.!log1, ' -' copyfile ':' ok
    279279    END
     
    760760
    761761
     762/*:VRX         PinWrapper
     763*/
     764/*  Wrapper for PIN, which performs the following tasks:
     765 *  - Create a temporary working directory & copy the PrinterPak files there.
     766 *  - Pre-process the PPD file to make it ready for import, and saves it in
     767 *    a driver-specific 'saved PPDs' directory for future use.
     768 *  - Uses PIN to import the PPD into our temporary working copy of the driver.
     769 *  - Copy the updated driver back to our installable copy.
     770 *  - If update_all is 1 then also do the following:
     771 *      - If the driver is actually installed, copy the updated driver back
     772 *        over the installed version as well.
     773 *      - If this is a 'shipped' driver (i.e. one listed in PRDRV.LST) then
     774 *        add the newly-defined printer to PRDESC.LST.
     775 */
     776PinWrapper: PROCEDURE EXPOSE globals. driver_path driver_repo
     777    ARG update_all, driver, ppdfile
     778
     779    CALL LINEOUT globals.!log1, 'Driver source:          ' driver_path
     780
     781    workdir = SysTempFileName( globals.!tmpdir'\PPD_????')
     782    ok = VRMkDir( workdir )
     783    IF ok == 1 THEN ok = VrMkDir( workdir'\OUT')
     784    IF ok <> 1 THEN
     785        RETURN 5                        /** RC=5 failed to create directory */
     786
     787    CALL LINEOUT globals.!log1, 'Temporary directory:    ' workdir
     788
     789    SELECT
     790        WHEN driver == 'ECUPS'    THEN ppddir = globals.!repository'\PPD_E'
     791        WHEN driver == 'ECUPS-HP' THEN ppddir = globals.!repository'\PPD_EHP'
     792        WHEN driver == 'PSPRINT'  THEN ppddir = globals.!repository'\PPD_PS'
     793        WHEN driver == 'PSPRINT2' THEN ppddir = globals.!repository'\PPD_PS2'
     794        WHEN driver == 'PSCRIPT2' THEN ppddir = globals.!repository'\PPD2'
     795        WHEN driver == 'GUTENPRT' THEN ppddir = globals.!repository'\PPD_GP'
     796        OTHERWISE                      ppddir = globals.!repository'\PPD'
     797    END
     798
     799    /* Make sure ppddir (for keeping PPD files) exists */
     800    CALL SysFileTree ppddir, 'dirs.', 'DO'
     801    IF dirs.0 == 0 THEN DO
     802        ok = VRMkDir( ppddir )
     803        IF ok <> 1 THEN
     804            RETURN 5                    /** RC=5 failed to create directory */
     805    END
     806
     807    CALL LINEOUT globals.!log1, 'Directory for PPD files:' ppddir
     808
     809    /***
     810     *** Now do the actual work.
     811     ***/
     812
     813    /* Copy the needed driver files to our working directories.
     814     */
     815    drvr_dir = VRParseFileName( driver_path, 'DP')
     816    drv_out  = workdir'\OUT\'driver'.DRV'
     817    pin_exe  = workdir'\PIN.EXE'
     818    ppd_exe  = workdir'\PPDENC.EXE'
     819    ok = VRCopyFile( driver_path, drv_out )
     820    IF ok == 1 THEN ok = VRCopyFile( drvr_dir'\PIN.EXE', pin_exe )
     821    IF ok == 1 THEN ok = VRCopyFile( drvr_dir'\PPDENC.EXE', ppd_exe )
     822    IF ok == 0 THEN DO
     823        RETURN 4                        /*** RC=4  Failed to copy driver files ***/
     824    END
     825
     826    /* Set up the output redirection.
     827     */
     828    nq = RXQUEUE('CREATE')
     829    oq = RXQUEUE('SET', nq )
     830
     831    /* If we are importing a new PPD file, prep it first.
     832     * (If ppdfile is undefined, it means we are reimporting a directory of
     833     * previously-imported PPDs, and we can assume they are already prepped.)
     834     */
     835    IF ppdfile <> '' THEN DO
     836
     837        /* If the PPD file is compressed, uncompress it.
     838         */
     839        IF VRParseFilePath( ppdfile, 'E') == 'GZ' THEN DO
     840            decppd = workdir'\' || VRParseFilePath( ppdfile, 'N')
     841            CALL LINEOUT globals.!log1, 'Decompressing' ppdfile 'to' decppd
     842            ADDRESS CMD '@'globals.!programs.!gzip '-c -d' ppdfile '| RXQUEUE' nq
     843            DO QUEUED()
     844                PARSE PULL line
     845                CALL LINEOUT decppd, line
     846            END
     847            CALL LINEOUT decppd
     848            ppdfile = decppd
     849        END
     850
     851        IF VRFileExists( ppdfile ) == 0 THEN DO
     852            CALL LINEOUT globals.!log1, 'PPD file' ppdfile 'could not be found.'
     853            RETURN 6                        /** RC=6  PPD import failed **/
     854        END
     855
     856        ppd_use = ppddir'\' || VRParseFileName( ppdfile, 'NE')
     857
     858        /* Now we have to clean up and validate the PPD file so PIN can use it.
     859         * First, PPDENC converts the codepage if necessary, and copies the results
     860         * to our working directory.
     861         */
     862        CALL LINEOUT globals.!log1, 'Converting PPD with:' ppd_exe ppdfile ppd_use
     863        ADDRESS CMD '@'ppd_exe ppdfile ppd_use '2>NUL | RXQUEUE' nq
     864        DO QUEUED()
     865            PULL output
     866            CALL LINEOUT globals.!log2, output
     867        END
     868        CALL LINEOUT globals.!log2, ''
     869        CALL LINEOUT globals.!log2
     870
     871        IF VRFileExists( ppd_use ) == 0 THEN DO
     872            CALL LINEOUT globals.!log1, 'Hmm,' ppd_use 'was not created.  Copying manually.'
     873            CALL VRCopyFile ppdfile, ppd_use
     874        END
     875
     876        /* Next we strip out some problematic PPD statements which are often
     877         * encountered in (for example) CUPS-based PPD files.
     878         */
     879        CALL CleanPPD ppd_use, globals.!log1
     880
     881    END
     882
     883    /* Preparation complete.  Now do the import.
     884     */
     885    count = 0
     886    ADDRESS CMD '@'pin_exe 'ppd' ppddir drv_out '2>NUL | RXQUEUE' nq
     887    DO QUEUED()
     888        PARSE PULL output
     889        CALL LINEOUT globals.!log2, output
     890        PARSE VAR output . 'OK (' nickname
     891        IF nickname <> '' THEN DO
     892            count = count + 1
     893            newprinters.count = STRIP( nickname, 'T', ')')
     894        END
     895    END
     896    newprinters.0 = count
     897    CALL LINEOUT globals.!log2, ''
     898    CALL LINEOUT globals.!log2
     899
     900    /* End the output redirection.
     901     */
     902    CALL RXQUEUE 'SET',    oq
     903    CALL RXQUEUE 'DELETE', nq
     904
     905    IF newprinters.0 == 0 THEN DO
     906        RETURN 6                        /** RC=6  PPD import failed **/
     907    END
     908
     909    /***
     910     *** Post-import processing.
     911     ***/
     912
     913    IF ( driver_repo == 1 ) & ( update_all <> 0 ) THEN DO
     914        /* If we're working out of the repository, we need to update the
     915         * driver table in PRDESC.LST to add the new driver(s).
     916         */
     917
     918        CALL LINEOUT globals.!log1, 'Updating' globals.!prdesc 'with new entries from' drv_out
     919
     920/* -- This causes a SYS3175 in the .DRV for some reason...
     921        ok = UpdatePrDesc( driver'.DRV', drv_out )
     922        IF ok <> 0 THEN
     923            CALL LINEOUT globals.!log1, 'Failed to update' globals.!prdesc '(are EAs on' drv_out ' valid?)'
     924*/
     925
     926        count = 0
     927
     928        /* First, copy all lines that don't refer to the driver just updated */
     929        CALL LINEIN globals.!prdesc, 1, 0
     930        DO WHILE LINES( globals.!prdesc )
     931            _next = LINEIN( globals.!prdesc )
     932            PARSE UPPER VAR _next . ':' _rest
     933            _tail = SUBSTR( _rest, LASTPOS('(', _rest ))
     934            PARSE VAR _tail '('_prdrv')' .
     935            IF _prdrv == driver'.DRV' THEN ITERATE
     936            count = count + 1
     937            defs.count = _next
     938        END
     939        CALL STREAM globals.!prdesc, 'C', 'CLOSE'
     940
     941        /* Next, create a new list for the updated driver and merge that in */
     942        newlist = workdir'\'driver'.LST'
     943        CALL CreateDriverList drv_out, newlist
     944        DO WHILE LINES( newlist )
     945            _line = LINEIN( newlist )
     946            count = count + 1
     947            defs.count = _line
     948        END
     949        CALL STREAM newlist, 'C', 'CLOSE'
     950        defs.0 = count
     951
     952        /* Now sort the list and recreate PRDESC.LST */
     953        CALL SysStemSort 'defs.',, 'I'
     954        prdesc_tmp = workdir'\PRDESC.LST'
     955        IF STREAM( prdesc_tmp, 'C', 'QUERY EXISTS') <> '' THEN
     956            CALL VRDeleteFile prdesc_tmp
     957        DO i = 1 TO defs.0
     958            CALL LINEOUT prdesc_tmp, defs.i
     959        END
     960        CALL LINEOUT prdesc_tmp
     961        ok = VRCopyFile( prdesc_tmp, globals.!prdesc )
     962        IF ok == 0 THEN DO
     963            RETURN 7                    /** RC=7  Error updating PRDESC.LST **/
     964        END
     965        CALL VRDeleteFile prdesc_tmp
     966
     967    END
     968
     969    /* Finally, copy the updated driver files.
     970     */
     971    target = VRParseFilePath( driver_path, 'DP')
     972    CALL LINEOUT globals.!log1, 'Copying files from' workdir'\OUT to' target
     973    CALL PRReplaceModule target'\'driver'.DRV', '', ''
     974    ok = VRCopyFile( workdir'\OUT\'driver'.DRV', target'\'driver'.DRV')
     975    IF ok == 1 THEN
     976        ok = VRCopyFile( workdir'\OUT\AUXPRINT.PAK', target'\AUXPRINT.PAK')
     977
     978    IF ( ok == 1 ) & ( update_all <> 0 ) THEN DO
     979        /* Copy the updated files to \OS2\DLL\<driver>, replacing any
     980         * existing copies.  (This prevents problems if the OS/2 driver
     981         * installation fails to copy them, which can happen under some
     982         * circumstances.)
     983         */
     984        IF VRFileExists( globals.!os2dir'\DLL\'driver'\'driver'.DRV') THEN DO
     985            CALL VRCopyFile workdir'\OUT\AUXPRINT.PAK',,
     986                            globals.!os2dir'\DLL\'driver'\AUXPRINT.PAK'
     987            CALL PRReplaceModule globals.!os2dir'\DLL\'driver'\'driver'.DRV', '', ''
     988            CALL VRCopyFile workdir'\OUT\'driver'.DRV', globals.!os2dir'\DLL\'driver'\'driver'.DRV'
     989        END
     990    END
     991    IF ok == 0 THEN DO
     992        CALL LINEOUT globals.!log1, VRError()
     993        RETURN 4                        /*** RC=4  Failed to copy driver files ***/
     994    END
     995
     996    CALL LINEOUT globals.!log1, newprinters.0 'printers imported successfully.'
     997    DO i = 1 TO newprinters.0
     998        CALL LINEOUT globals.!log1, ' ->' newprinters.i
     999    END
     1000    CALL LINEOUT globals.!log1, ''
     1001    CALL LINEOUT globals.!log1
     1002
     1003    /* Clean up our work directories.
     1004     */
     1005    CALL VRDeleteFile workdir'\OUT\*'
     1006    CALL VRDeleteFile workdir'\*'
     1007    CALL VRRmDir( workdir'\OUT')
     1008    CALL VRRmDir( workdir )
     1009
     1010RETURN 0
     1011
     1012
    7621013/*:VRX         UpdatePrDesc
    7631014*/
     
    7811032    CALL STREAM globals.!prdesc, 'C', 'CLOSE'
    7821033
    783     DO i = 1 TO devs.0
     1034    DO i = 1 TO newdevs.0
    7841035        _count = _count + 1
    7851036        prdefs._count = newdevs.i':' newdevs.i '('driver')'
Note: See TracChangeset for help on using the changeset viewer.