/*
PRG: MLS12us.exe Auto Updating Service
Purpose: Background running routine to handle updates and submissions2/15/2022 4:51:32 PM
Updated: 11/26/2022 5:07:44 PM
*/
#INCLUDE "Fivewin.CH"
#INCLUDE "ini.CH"
#INCLUDE "TDATA.CH"
#INCLUDE "common.CH"
#INCLUDE "mail.ch"
#include "fileio.ch"
#include "hbwin.ch"
#include "hbmzip.ch"
#include "ads.ch"
#INCLUDE "constant.ch"
#INCLUDE "hbClass.ch"
#include "hbcurl.ch"
#DEFINE INTERNET_FLAG_PASSIVE 0x08000000
#define HKEY_LOCAL_MACHINE 2147483650
EXTERN ADSKeyCount, ADSKeyNo, AdsGetRelKeyPos, AdsSetRelKeyPos
#if ! defined( __HBSCRIPT__HBSHELL )
#define _SERVICE_NAME "MLS12_Auto_Updater"
PROCEDURE Main( cMode )
LOCAL nError
LOCAL cMsg
hb_default( @cMode, "S" ) // NOTE: Must be the default action
SWITCH Upper( cMode )
CASE "I"
IF win_serviceInstall( _SERVICE_NAME, "MLS Auto Updater Service" )
? "Service has been successfully installed"
ELSE
nError := wapi_GetLastError()
cMsg := Space( 128 )
wapi_FormatMessage( ,,,, @cMsg )
? "Error installing service: " + hb_ntos( nError ) + " " + cMsg
ENDIF
EXIT
CASE "U"
IF win_serviceDelete( _SERVICE_NAME )
? "Service has been deleted"
ELSE
nError := wapi_GetLastError()
cMsg := Space( 128 )
wapi_FormatMessage( ,,,, @cMsg )
? "Error deleting service: " + hb_ntos( nError ) + " " + cMsg
ENDIF
EXIT
CASE "S"
// NOTE: Used when starting up as service. Do not invoke the executable manually with this option
IF win_serviceStart( _SERVICE_NAME, @SrvMain() )
? "Service has started OK"
ELSE
nError := wapi_GetLastError()
cMsg := Space( 128 )
wapi_FormatMessage( ,,,, @cMsg )
? "Service has had some problems: " + hb_ntos( nError ) + " " + cMsg
ENDIF
EXIT
ENDSWITCH
RETURN
PROCEDURE SrvMain( cParam1, cParam2 )
LOCAL n := 0
LOCAL cParam
LOCAL CurDir := CURDIR(), CurDri := DISKNAME()
LOCAL owIcon, oIni, meSavStr, nHandle, nServer := 7
PRIVATE oWnd, oTray, oIcon, oIcon1, oTmr
PRIVATE cPath := hb_DirBase() + "DATA\"// CurDri + ":\" + CurDir + "\Data\"
PRIVATE cDnPath := hb_DirBase() + "MLS\"
PRIVATE cBakPath := CurDri + ":\" + CurDir
PRIVATE cValue, cStart := Time( )
PRIVATE cInstVer, dLstBkUp, cGetSN, eSavStr, lCFXActive, dCFLstDte,;
dvChkDte, cvChkVer, lvOKToDl, cvOnSrvr, cvAuthTo, cvChkBul, dCLLstDte,;
sCurDte, sWkCxDte, sWkClDte, cBackupPath, ldForce, lKukui, oDbLog
PRIVATE mCLinkAC, mCLinkFt, mCLinkPw, mCLinkUn, oDcf, lCloudBackup := .f.
PUBLIC fhnd := hb_FCreate( hb_FNameExtSet( hb_ProgName(), ".out" ), FC_NORMAL, FO_DENYNONE + FO_WRITE )
PUBLIC cHome := cPath
PUBLIC iDLL, lfHndl
PUBLIC nConnect := AdsIsServerLoaded( cPath ), lCFXloyalty := .f.
FWrite( fhnd, TIME() + " Startup" + hb_eol() )
REQUEST DBFCDX
rddRegister( "DBFCDX", 1 )
rddsetdefault( "DBFCDX" )
SET DELETED ON
SET EXCLUSIVE OFF
SET DEFAULT TO ( cPath )
FWrite( fhnd, TIME() + " RDD Initialized" + hb_eol() )
FWrite( fhnd, TIME() + " Path: " + cPath + hb_eol() )
// Load the DLL
iDLL := LoadLibrary( "wininet.dll" )
FWrite( fhnd, TIME() + " wininet.dll is loaded " + hb_eol() )
DO WHILE .t. // win_serviceGetStatus() == WIN_SERVICE_RUNNING
FWrite( fhnd, TIME() + " Work in progress " + hb_eol() )
/* This is where you add in your operations. You can call Functions from here
Remember, a service can have NO screen interaction or prompts. You will find
Many FWH calls won’t be useable in a service. */
FWrite( fhnd, TIME() + " Cycle Completed" + hb_eol() )
hb_idleSleep( 10000 ) // 3 hours
ENDDO
// Close the log file
FWrite( fhnd, TIME() + " Exiting..." + hb_eol() )
Close( fhnd )
// Close the library
FreeLibrary( iDLL )
RETURN