home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------
- //
- // cat2prj.prg
- //
- // This utility can convert a Visual dBASE 5.x catalogs to
- // a Visual dBASE 7.0 project file. You can call it as a
- // function with 2 optional parameters. If you call it with
- // no parameters, a dialog opens for selecting the catalog
- // to convert. The function returns true if it creates a
- // project file without error.
- //
- // Syntax:
- //
- // cat2prj( [<expC: Catalog file name>] [,<expL: overwrite] )
- //
- // Example: To create equipmnt.prj from equipmnt.cat and
- // overwrite an existing equipmnt.prj without
- // confirmation.
- //
- //
- // cat2prj( "equipmnt.cat", true )
- //
- //
- // Visual dBASE Samples Group
- //
- // $Revision: 1.2 $
- //
- // Copyright (c) 1997, Borland International, Inc.
- // All rights reserved.
- //
- //---------------------------------------------------------------//
- //
-
- function cat2prj( sCat, bOverwrite )
- // Call create project function if catalog and
- // project file names are valid.
- local bOK, sPrj
- private prCat
- private prOverwrite
-
- bOK = false
- prCat = sCat
- prOverwrite = bOverwrite
- filePrj = new File()
-
- if ( PCOUNT() == 0 OR TYPE( "prCat" ) <> "C" )
- sCat = UPPER( GETFILE("*.CAT", ;
- "Convert Catalog to Project", ;
- true,false) )
- else
- sCat = UPPER( sCat )
- endif
-
- if ( PCOUNT() < 2 OR TYPE( "prOverwrite" ) <> "L" )
- bOverwrite = false
- endif
-
- if ( FILE( sCat ) AND ( RIGHT( sCat, 4 ) == ".CAT") )
- sPrj = SUBSTR( sCat, 1, LEN( sCat ) - 3 ) + "PRJ"
-
- if ( FILE( sPrj ) AND ( NOT bOverwrite ) )
- bOK = ( MSGBOX( sPrj + ;
- " already exists. Overwrite it?", ;
- "Already Exists", ;
- 4 + 32) == 6 )
- else
- bOK = true
- endif
-
- if ( bOK )
- bOK = createPrj( sCat, sPrj )
- endif
-
- endif
-
- return ( bOK )
-
- function createPrj( sCat, sPrj )
- // create a project file from a catalog table
- local qCat, fPrj, sDefault
-
- sDefault = getDefault( sCat )
- qCat = new Query()
- qCat.sql = "SELECT * FROM '" + sCat + "'"
- qCat.active = true
- fPrj = new File()
- fPrj.create( sPrj )
- fPrj.writeLn( "Project File - generated " + ;
- CMONTH( DATE() ) + " " + ;
- LTRIM( STR( DAY( DATE() ) ) ) + ", " + ;
- LTRIM( STR( YEAR( DATE() ) ) ) )
- fPrj.writeLn( "" )
- fPrj.writeLn( "[Project]" )
- fPrj.writeLn( "DefaultDir=" + sDefault )
- fPrj.writeLn( "MainProjectFileName=" )
- fPrj.writeLn( "MostRecentSelectedFileName=" )
- fPrj.writeLn( "" )
- fPrj.writeLn( "[Contents]" )
-
- do while ( NOT qCat.rowset.endOfSet )
- fPrj.writeLn( RTRIM( qCat.rowset.fields[1].value ) )
- qCat.rowset.next()
- enddo
-
- qCat.active = false
- fPrj.close()
-
- return FILE( sPrj )
-
- function getDefault( sCat )
- // get default project directory
- local bFullpath, sDefault
-
- CREATE SESSION
- bFullpath = SET("FULLPATH")=="ON"
- SET FULLPATH ON
- USE (sCat)
- sDefault = LOWER( DBF() )
- SET FULLPATH OFF
- sDefault = SUBSTR( sDefault, 1, ;
- LEN(sDefault) - ( LEN( DBF() ) - 1 ) )
-
- if ( bFullpath )
- SET FULLPATH ON
- endif
-
- CLOSE TABLES
-
- return ( sDefault )
-