Commits

Nathan Durnan committed f9c359a

Add KeepLogs settings to keep specified number of old log files (clean out older ones)

Comments (0)

Files changed (2)

-_HgPreBackup.au3,1325796010.06
+_HgPreBackup.au3,1325797916.28
 .hgsub,1325791137.19
 HgPreBackupSettings.ini,1325730491.97
 .hgsubstate,1325791876.03
 HgPreBackup.ico,1325031982.39
 HgPreBackup.svg,1325032006.66
 .hgignore,1325796114.66
-.hgtimestamp,1325796203.78
+.hgtimestamp,1325797991.88
 Global $Gf_TimeStart	;Timestamp (in ticks) for application start (floating point value).
 Global $Gs_LogFilePath	;Path to create/write log file.
 Global $Gh_LogFile 		;Handle for log file
+Global $Gi_KeepLogs		;Number of old logs to keep in log path.
 
 Global $Ga_RepoList[1]				;Array containing paths of repositories to be backed up.
 Global $Ga_RepoValidErr[1]			;Array containing list of source repositories that failed validation.
 $Gf_TimeStart = _Timer_Init()
 $Ga_TimeStampStart = _GetTimeStampArray()
 ;Create Log File
-$Gh_LogFile = _LogFileCreate($Gs_LogFilePath, $Ga_TimeStampStart)
-_LogFileAddMessage($Gh_LogFile, "Beginning HgPreBackup Operation")
+If ($Gi_KeepLogs <> 0) Then
+	$Gh_LogFile = _LogFileCreate($Gs_LogFilePath, $Ga_TimeStampStart)
+	_LogFileAddMessage($Gh_LogFile, "Beginning HgPreBackup Operation")
+Endif ;Check if keeping any logs.
 ;Validate Mercurial Installation or Command Path
 If Not _VerifyMercurial() Then
 	;Mercurial installation not detected!!!
 	$Gs_RepoHomeDir = IniRead($IN_sSettingsFilePath, 'paths', 'repopath', @ScriptDir)
 	$Gs_BackupDir = IniRead($IN_sSettingsFilePath, 'paths', 'backuppath', @TempDir)
 	$Gs_LogFilePath = IniRead($IN_sSettingsFilePath, 'paths', 'logpath', @TempDir)
+	
 	;Read Settings:
+	$Gi_KeepLogs = IniRead($IN_sSettingsFilePath, 'settings', 'KeepLogs', -1)
 	
 	;Read Email Configuration:
 	;NOTE: The default settings will probably not work if the IniRead command fails to retrieve data from the file.
 	Local $sTimeStamp
 	Local $myResult
 	
+	If ($IN_hLogFile <= 0) Then Return ;Can't do anything with an invalid file handle.
 	If IsArray($optIN_aTimeStamp) Then
 		$sTimeStamp = " Starting " & StringFormat("%04d/%02d/%02d, at %02d:%02d:%02d", _
 				$optIN_aTimeStamp[2], $optIN_aTimeStamp[0], $optIN_aTimeStamp[1], _
 	$myResult = $myResult And FileWriteLine($IN_hLogFile, "|  Date  |    Time    | Message     ")
 	$myResult = $myResult And FileWriteLine($IN_hLogFile, "+yyyymmdd+hh:mm:ss.mmm+-----------------------------------------------")
 	Return $myResult
+	
 EndFunc ;==> _LogFileWriteHeader
 
 ; #FUNCTION# ....:	_LogFileAddMessage ******************************************
 	Local $aTimeStamp, $sTimeStamp
 	Local $myResult
 	
+	If ($IN_hLogFile <= 0) Then Return ;Can't do anything with an invalid file handle.
 	$aTimeStamp = _GetTimeStampArray()
 	$sTimeStamp = StringFormat("|%04d%02d%02d|%02d:%02d:%02d.%03d", _
 			$aTimeStamp[2], $aTimeStamp[0], $aTimeStamp[1], _
 Func _LogFileWriteFooter($IN_hLogFile)
 	Local $myResult, $ii
 	
+	If ($IN_hLogFile <= 0) Then Return ;Can't do anything with an invalid file handle.
 	$myResult = FileWriteLine($IN_hLogFile, "+--------+------------+-----------------------------------------------")
 	$myResult = $myResult And FileWriteLine($IN_hLogFile, "+---------------------------------------------------------------------")
 	$myResult = $myResult And FileWriteLine($IN_hLogFile, "| ~~ SUMMARY ~~ " )