Skip to content

Commit

Permalink
Add Event Trace Logging (ETL) file overwriting (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk4j authored May 14, 2024
1 parent e6ad78d commit fd95b4a
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions chcl3.vbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Sub Print(Message)
PrintBuffer = PrintBuffer & Message & vbCrLf
End Sub

Sub Flush(Title)
Sub Flush
WScript.Echo PrintBuffer
PrintBuffer = ""
End Sub
Expand Down Expand Up @@ -48,14 +48,22 @@ Sub ReadLine(Path, Callback)
Dim Tokens
Tokens = Split(Buffer)

If Not IsNull(Tokens) And IsArray(Tokens) And UBound(Tokens) > 0 Then
If Not IsNull(Tokens) And IsArray(Tokens) And UBound(Tokens) >= 0 Then
Call Callback(Tokens)
End If
Loop
fh.Close
Set fh = Nothing
End Sub

Sub ForEach(Path, Lambda)
Dim SubRef
Set SubRef = GetRef(Lambda)
Call ReadLine(Path, SubRef)
Set SubRef = Nothing
Call Flush
End Sub

Function DisplayLicense()
Dim LicenseText
LicenseText = ReadTextFile("LICENSE")
Expand Down Expand Up @@ -113,22 +121,43 @@ Sub StopService(Service)
End Sub

Sub StopServices
Dim SubRef
Set SubRef = GetRef("StopService")
Call ReadLine("data\services.txt", SubRef)
Set SubRef = Nothing
Call Flush("StopServices")
Call ForEach("data\services.txt", "StopService")
End Sub

Sub OverWriteFile(File)
Dim Status, FilePath
FilePath = File(0)

On Error Resume Next

Set f = fso.CreateTextFile(FilePath, True)

If Err.Number <> 0 Then
Status = "! (" & Err.Number & ": " & Err.Description & ")"
Err.Clear
Else
f.WriteLine("")
f.Close
Status = "-"
End If

Call Print(Status & " " & FilePath)
End Sub

Sub OverWriteFiles
Call ForEach("data\files.txt", "OverWriteFile")
End Sub

Function Main()
Dim Accepted
Accepted = DisplayLicense()
Accepted = vbOK 'DisplayLicense()

If Accepted = vbOK Then
Accepted = DisplayWarning()
Accepted = vbOK 'DisplayWarning()

If Accepted = vbOK Then
Call StopServices
Call OverWriteFiles
End If
End If

Expand Down

0 comments on commit fd95b4a

Please sign in to comment.