📄 appstrt.prg
字号:
*------------------------------------------------------------------------
*-- This program starts a Codebook application. It first compares the
*-- date/time of the file in the Update subdirectory with the
*-- date/time of the equivalent file in the Production subdirectory.
*-- If the two are different then the file in the update
*-- subdirectory is copied into the production subdirectory and life
*-- is grand.
*--
*-- Goal: Automatically update every file on the C:\ drive in order
*-- to support distributed execution and update of a Codebook
*-- applications
*--
*------------------------------------------------------------------------
*-- Inputs: 1. Update Subdirectory
*-- 2. Production Subdirectory
*--
*-- Supporting Table:
*-- 1. Name: MNUMSTRT.DBF
*-- 2. Code: CREATE TABLE appstrt FREE ( cUpdSubDir C(70), ;
*-- cPrdSubDir C(70), ;
*-- cAppExe C(70) )
*-- 3. Example
*-- a. Update Subdirectory = "F:\VMNUM\UPDATE\"
*-- b. Production Subdirectory = "C:\VMNUM\"
*-- c. Application EXE File = "MNUM.EXE"
*------------------------------------------------------------------------
*-------------------------------------------
*-- Control Loop --*
*-------------------------------------------
LOCAL lcUpdateSubdirectory , ;
lcProductionSubdirectory , ;
lcProductionDrive
SET STATUS BAR ON
SET SAFETY OFF
IF GetUpdateAndProductionSubdirectories( @lcUpdateSubdirectory, @lcProductionSubdirectory )
=GetListOfUpdateFiles( lcUpdateSubdirectory )
=GetListOfProductionFiles( lcProductionSubdirectory, @lcProductionDrive )
=UpdateProductionFiles( lcProductionDrive, lcUpdateSubdirectory, lcProductionSubdirectory )
=LaunchApplication()
ENDIF
RETURN .T.
*-----------------------------------------------------------------------------------------------
FUNCTION GetUpdateAndProductionSubdirectories( tcUpdateSubdirectory , tcProductionSubdirectory )
*-----------------------------------------------------------------------------------------------
LOCAL llRetVal , ;
lcMissingDirectory
IF USED('mnumstrt')
SELECT appstrt
ELSE
SELECT 0
USE appstrt
ENDIF
tcUpdateSubdirectory = ALLTRIM( appstrt.cUpdSubDir )
tcProductionSubdirectory = ALLTRIM( appstrt.cPrdSubDir )
llRetVal = DIRECTORY( tcUpdateSubdirectory )
IF llRetVal
llRetVal = DIRECTORY( tcProductionSubdirectory )
IF .NOT. llRetVal
MD ( tcProductionSubdirectory )
llRetVal = DIRECTORY( tcProductionSubdirectory )
IF .NOT. llRetVal
lcMissingDirectory = tcProductionSubdirectory
ENDIF
ENDIF
ELSE
lcMissingDirectory = tcUpdateSubdirectory
ENDIF
IF .NOT. llRetVal
=MESSAGEBOX( "File updates cannot proceed, the directory " + ;
lcMissingDirectory + ;
" does not exist. The application you are using " + ;
"may be out of date. Contact your application " + ;
"administrator to determine if you are missing " + ;
"any critical changes." , ;
64 , ;
"Automatic Application Update Utility" )
ENDIF
IF USED('mnumstrt')
USE IN mnumstrt
ENDIF
RETURN llRetVal
ENDFUNC
*------------------------------
FUNCTION GetListOfUpdateFiles()
*------------------------------
LPARAMETERS tcUpdateSubdirectory
LOCAL laUpdate[1] , ;
lnNumFiles , ;
lcFileName , ;
llDirectory , ;
lnFile
lnNumFiles = ADIR( laUpdate, tcUpdateSubdirectory + "*.*", "SD" )
IF .NOT. USED('cUpdate')
CREATE CURSOR cUpdate ( cDirectory C(100), cFileName C(70), dFileDate D, cFiletime C(8) )
SELECT cUpdate
ENDIF
IF lnNumFiles > 0
FOR lnFile = 1 to lnNumFiles
lcFileName = laUpdate[lnFile,1]
llDirectory = "D" $ laUpdate[lnFile,5]
IF lcFileName == "." OR ;
lcFileName == ".."
*-----------------------------------------------
*-- Forget the current and parent subdirectories
*-----------------------------------------------
ELSE
IF llDirectory
=GetListOfUpdateFiles( tcUpdateSubdirectory + ALLTRIM(laUpdate[lnFile,1]) + "\" )
ELSE
INSERT INTO cUpdate ( cDirectory , ;
cFileName , ;
dFileDate , ;
cFileTime ) ;
VALUES ( tcUpdateSubdirectory , ;
ALLTRIM(laUpdate[ lnFile, 1 ]) , ;
laUpdate[ lnFile, 3 ] , ;
laUpdate[ lnFile, 4 ] )
ENDIF
ENDIF
ENDFOR
ENDIF
ENDFUNC
*----------------------------------
FUNCTION GetListOfProductionFiles()
*----------------------------------
LPARAMETERS tcProductionSubdirectory, tcProductionDrive
tcProductionDrive = ""
LOCAL laProduction[1] , ;
lnNumFiles , ;
lcFileName , ;
llDirectory , ;
lnFile
lnNumFiles = ADIR( laProduction, tcProductionSubdirectory + "*.*", "SD" )
IF .NOT. USED('cProduction')
CREATE CURSOR cProduction ( cDirectory C(100), cFileName C(70), dFileDate D, cFiletime C(8) )
INDEX ON cDirectory + cFileName TAG FFileName
SELECT cProduction
ENDIF
IF lnNumFiles > 0
FOR lnFile = 1 to lnNumFiles
lcFileName = laProduction[lnFile,1]
llDirectory = "D" $ laProduction[lnFile,5]
IF lcFileName == "." OR lcFileName == ".."
*-----------------------------------------------
*-- Forget the current and parent subdirectories
*-----------------------------------------------
ELSE
IF llDirectory
=GetListOfProductionFiles( tcProductionSubdirectory + ALLTRIM(laProduction[lnFile,1]) + "\" )
ELSE
IF .NOT. EMPTY( tcProductionSubdirectory )
tcProductionDrive = LEFT( tcProductionSubdirectory, 3 )
ENDIF
INSERT INTO cProduction ( cDirectory , ;
cFileName , ;
dFileDate , ;
cFileTime ) ;
VALUES ( tcProductionSubdirectory , ;
ALLTRIM(laProduction[ lnFile, 1 ]) , ;
laProduction[ lnFile, 3 ] , ;
laProduction[ lnFile, 4 ] )
ENDIF
ENDIF
ENDFOR
ENDIF
ENDFUNC
*--------------------------------------------------------------------------------------------------
FUNCTION UpdateProductionFiles( tcProductionDrive, tcUpdateSubdirectory, tcProductionSubdirectory )
*--------------------------------------------------------------------------------------------------
LOCAL lcUpdateFullFileName , ;
lcUpdateSubdirectory , ;
lcProductionSubdirectory , ;
lcSeekFileName , ;
llFound , ;
llUpdateProductionFile , ;
lcFullProductionFileName , ;
ltUpdateTimeStamp , ;
ltProductionTimeStamp , ;
lcFullSourceFileName
SELECT cUpdate
IF RECCOUNT('cUpdate') > 0
SCAN
lcUpdateFullFileName = ALLTRIM( cUpdate.cDirectory ) + cUpdate.cFileName
lcUpdateSubdirectory = ALLTRIM( cUpdate.cDirectory )
lcProductionSubdirectory = STRTRAN( lcUpdateSubdirectory, tcUpdateSubdirectory, tcProductionSubdirectory )
lcSeekFileName = PADR(lcProductionSubdirectory,LEN(cProduction.cDirectory)) + cUpdate.cFileName
llFound = SEEK( lcSeekFileName , "cProduction" , "FFileName" )
IF .NOT. llFound
llUpdateProductionFile = .T.
lcFullProductionFileName = STRTRAN( lcUpdateFullFileName, tcUpdateSubdirectory, tcProductionSubdirectory )
IF .NOT. DIRECTORY( lcProductionSubdirectory )
MD ( lcProductionSubdirectory )
ENDIF
ELSE
ltUpdateTimeStamp = CTOT( ALLTRIM(DTOC( cUpdate.dFileDate )) + " " + ;
cUpdate.cFileTime )
ltProductionTimeStamp = CTOT( ALLTRIM(DTOC( cProduction.dFileDate )) + " " + ;
cProduction.cFileTime )
llUpdateProductionFile = ( ltUpdateTimeStamp > ltProductionTimeStamp )
lcFullProductionFileName = ALLTRIM( cProduction.cDirectory ) + cProduction.cFileName
ENDIF
IF llUpdateProductionFile
lcFullSourceFileName = ALLTRIM( cUpdate.cDirectory ) + ALLTRIM( cUpdate.cFileName )
SET MESSAGE TO "APPLICATION UPDATE ... copying file " + lcFullSourceFileName + " ... please be patient."
COPY FILE ( lcFullSourceFileName ) TO ( lcFullProductionFileName )
ENDIF
ENDSCAN
ENDIF
ENDFUNC
*---------------------------
FUNCTION LaunchApplication()
*---------------------------
LOCAL lcApplicationSubdirectory, ;
lcApplication
lcApplicationSubdirectory = ALLTRIM( appstrt.cPrdSubDir )
lcApplication = ALLTRIM( appstrt.cAppExe )
IF .NOT. EMPTY( lcApplication )
CD ( lcApplicationSubdirectory )
CLOSE ALL
DO ( lcApplication )
ENDIF
ENDFUNC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -