!
! (c) Copyright 2006-%(copyright-year)%, Sage Software Canada Ltd. (Ontario, Canada)
! $Id: set_mod_timestamp.pvc.pvt 2352 2019-03-05 18:03:33Z fmcguirk $
/*
* Build information:
! ** @Author Fred McGuirk
! ** @Date Nov 22, 2007
! ** @OutputFile set_mod_timestamp.pvc
! ** This observer will set the modification timestamp of the output file to be
! ** the same as the source file.
! **
! ** This program uses the Eclipse IResource class to get and set the timestamps.
*/
def class "set_mod_timestamp"
like "EventManagerObserver"
! Override values for description / NotificationFlag
local theDescription$= \
"Set modification timestamp of output file to be the same as source file"
local theNotificationFlag=_pvxConstants'_idePostProcess
! ** Private property to maintain the name of the temporary file that is created
! ** during the Pre-Process so that it can be deleted during the Post-Process.
local tempSourceFile$
/*
! ** The logic to be executed when the observer is triggered.
! ** @param state A reference to an object of class %PvxClass(PvxState)%
*/
function update(initPvxState) update
end def
/*
* The update routine will be executed by the event manager during the
* pre/post process logic depending on how this observer registers
* itself through the getEventNotification() method.
*/
update:
enter aPvxState
local psMajor$,psMinor$,source,dest$,enfState,x,destObj,fileObj,projObj,sysType$, \
utcMTime,secondsIntoDay,dayHours,dayMinutes,daySeconds,julDay,theCmd$
! Get the Major/Minor codes that identify the current action
psMajor$=aPvxState'getMajor$(), \
psMinor$=aPvxState'getMinor$()
/*
* This observer is for the program build event only; all other events
* should be ignored.
*/
if (psMajor$=_pvxConstants'Incremental_Build$ \
or psMajor$=_pvxConstants'Incremental_Build_Alt_Exe$) \
and psMinor$=_pvxConstants'BuildType_BuildOne$ {
! Check the current state of processing for the ProvideX Event Manager
enfState=aPvxState'getArgumentValue(_pvxConstants'_iEventNotificationFlag$)
switch enfState
case _pvxConstants'_idePostProcess
! Get the arguments from the current action that this logic will use
eventSourceFile$=aPvxState'getArgumentValue$(_pvxConstants'event_SrcFile$), \
dest$=aPvxState'getArgumentValue$(_pvxConstants'Dest$)
! Get the modification date of the original event source file and
! Set the modification date of the output file to be the same
sysType$=sys
if pos("LINUX"=ucs(sysType$))>0 then \
sysType$="Linux"
switch sysType$
case "MS-WINDOWS"
! Set control values for DLL call
access_rw=dec(ior($80000000$,$40000000$)), \
share_rw=1+3, \
open_existing=3, \
file_attr_normal=128
! Load the MS-Windows 'kernel32.dll' into memory
! (since it will be used several times)
aDLL=dll(addr "kernel32")
! Get a handle to the source file
hSrc=dll(aDLL,"CreateFileA",eventSourceFile$+$00$,access_rw,share_rw,0, \
open_existing,file_attr_normal,0)
dim aSrc$[1:3](8,$00$)
! Get creation, access, and modification times for source file
status=dll(aDLL,"GetFileTime",hSrc,aSrc$[1],aSrc$[2],aSrc$[3])
! Close reference to file
status=dll(aDLL,"CloseHandle",hSrc)
if status=1 {
! Get a handle to the destination file
hDest=dll(aDLL,"CreateFileA",dest$+$00$,access_rw,share_rw,0, \
open_existing,file_attr_normal,0)
dim aDest$[1:3](8,$00$)
! Get creation, access, and modification times for destination file
status=dll(aDLL,"GetFileTime",hDest,aDest$[1],aDest$[2],aDest$[3])
! change the modification time of the destination
aDest$[3]=aSrc$[3]
! Set the new times for the destination file
status=dll(aDLL,"SetFileTime",hDest,aDest$[1],aDest$[2],aDest$[3])
! Close reference to file
status=dll(aDLL,"CloseHandle",hDest)
}
! remove the "kernel32.dll" from memory.
s=dll(drop aDLL)
break
case "Linux"
open input (hfn,isz=1,err=*break)eventSourceFile$
utcMTime=num(fin(lfo,"UTC_Mtime",err=*next))
close (lfo)
if utcMTime>0 {
julDay=int(utcMTime/86400), \
secondsIntoDay=utcMTime-(julDay*86400)-tcb(44), \
dayHours=int(secondsIntoDay/3600), \
dayMinutes=int(secondsIntoDay/60)-(dayHours*60), \
daySeconds=secondsIntoDay-dayHours*3600-dayMinutes*60
theCmd$="touch -t "+dte(julDay:"%Y%Mz%Dz")+ \
str(dayHours:"00")+str(dayMinutes:"00")+ \
"."+str(daySeconds:"00")+" "+dest$
x=sys(theCmd$)
}
break
end switch
oReqClient = NEW( "pvxrequestclient")
oReqClient'print(_obj'getDescription$()+": Complete")
drop object oReqClient
break
end switch
}
return 0
end