'
' Example script for 2BrightSparks SyncBackPro V8 that adds an extra
' column in the main window that shows the number of files that
' were copied, deleted, etc. in the last profile run.
'
' You need to install this script and enable it on the Main Interface
' tab. You also need to enable for each profile that you want the column
' to be used with (modify the profile and go to the Scripts tab).
'
' SBLang=Basic
'
' http://www.2BrightSparks.com/
'

'
' This is both a runtime script and a main interface script
'
Function Description(ByRef ScriptType)
  Description = "Show number of files copied, deleted, etc."
  ScriptType = SCRIPTTYPE_MAIN + SCRIPTTYPE_RUN
End Function

'
' Called when the profile has finished running. We get the
' variables and create a description, which we save as a
' property of the profile. This description is then used in
' the main interface.
'
Sub RunProfileResult(ProfileResult, ErrMsg)
  SBVariables.SetProperty("XInfo", 
    SBVariables.GetVar("%COPIEDTOTAL%") & " copied, " & 
    SBVariables.GetVar("%DELETEDTOTAL%") & " deleted, " & 
    SBVariables.GetVar("%MOVEDTOTAL%") & " moved, " & 
    SBVariables.GetVar("%SKIPPEDTOTAL%") & " skipped")
End Sub

'
' Just one column
'
Function MainColumnsCount
  MainColumnsCount = 1
End Function

'
' Column title. We can ignore Col because we only have
' one columm. Also ignore Width and just use the default.
'
Function MainColumnTitle(Col, ByRef Width)
  MainColumnTitle = "Count"
End Function

'
' Column text. We can ignore Col because we only have
' one columm. If its a group then we have no info.
'
Function MainColumnText(Col, IsGroup, ProfileName)
  ' Ignore groups
  If Not IsGroup Then
    ' We get the info from the variable that was cached in RefreshDisplay()
    VarName = "%" & ProfileName & "*XInfo%"
    MainColumnText = SBVariables.GetVar(VarName)
    if (MainColumnText = VarName) or (MainColumnText = "") Then
      MainColumnText = "Not using script or not run yet"
    End If
  Else
    MainColumnText = ""
  End If
End Function

'
' This routine is called when SyncBack refreshes the display.
'
' To reduce CPU and drive load we cache the property as a variable. This saves
' us from constantly reading from the drive. The property was set/created in
' the call to RunProfileResult() when the profile finished.
'
Sub RefreshDisplay
  Cnt = SBSystem.ProfileCount
  For Idx = 0 to Cnt - 1
    ProfileName = SBSystem.GetProfileName(Idx)
    If ProfileName <> "" Then
      SBVariables.SetVar(ProfileName & "*XInfo", SBVariables.GetProfileProperty(ProfileName, "XInfo", "", False))
    End If
  Next
End Sub

