'
' Example script for 2BrightSparks SyncBackPro that sets the read-only
' attribute on the copy of a file (if the Source wasn't already). It
' is only for use with profiles where the destination is a normal
' filesystem and compression is not used.
'
' SBLang=VBScript
'
' http://www.2BrightSparks.com/
'

Dim FSO

'
' This is a runtime script 
'
Function Description(ScriptType)
  Description = "Set RO flag on files copied to destination"
  ScriptType = 2
End Function

'
' Initialise file system object
'
Sub RunAfterConfig()
  Set FSO = CreateObject("Scripting.FileSystemObject")
End Sub

'
' Note this function is not called if it is a simulation.
'
Sub RunAfterCopyFile(ToLeft, Filename, Failed)
  ' If the copy failed then dont even try
  If Failed then
    ' SBRunning.DebugOut Filename, "Failed", 1
    Exit Sub
  End If

  If ToLeft then
    ' Copying to the left
    Exit Sub
  End If

  ' Copying to the right. If the source file is not read-only
  ' then set the destination copy to read-only.
  attrs = SBRunning.GetFileAttrs(Filename, True)
  If NOT attrs AND 1 Then
    If not FSO.FileExists(SBRunning.RightFolder & Filename) Then
      ' SBRunning.DebugOut Filename, "File no longer exists", 1
      Exit Sub
    End If

    Set FileObj = FSO.GetFile(SBRunning.RightFolder & Filename)
    FileObj.Attributes = attrs + 1
  End If
End Sub
