'
' Example script for 2BrightSparks SyncBackPro V8 that exports
' the differences in files and folders when the Differences 
' window is displayed.
'
' Note that the Differences window has an Export ability already
' via the main menu.
'
' SBLang=Basic
'
' http://www.2BrightSparks.com/
'

'
' This is a runtime script and a configuration script
'
Function Description(ByRef ScriptType)
  Description = "Differences export"
  ScriptType = SCRIPTTYPE_RUN + SCRIPTTYPE_CONFIG
End Function

Sub DoTheExport
  ' Export files
  ExportFilename = CStr(SBVariables.GetProperty("DEFiles", "", FALSE))
  If ExportFilename <> "" then
    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(ExportFilename, 2, true, -1)
    For I = 0 to SBRunning.FileCount - 1 step 1
      ExportName = SBRunning.GetFilename(i)
      
      ' Filename,Difference,Action
      objFileToWrite.WriteLine(ExportName + "," + CStr(SBRunning.GetFileDiff(ExportName)) + "," + CStr(SBRunning.GetFileAction(ExportName)))
    Next
    objFileToWrite.Close
    Set objFileToWrite = Nothing
  End If

  ' Export folders
  ExportFilename = CStr(SBVariables.GetProperty("DEFolders", "", FALSE))
  If ExportFilename <> "" then
    Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile(ExportFilename, 2, true, -1)
    For I = 0 to SBRunning.FolderCount - 1 step 1
      ExportName = SBRunning.GetFoldername(i)

      ' Foldername,Difference,Action
      objFileToWrite.WriteLine(ExportName + "," + CStr(SBRunning.GetFolderDiff(ExportName)) + "," + CStr(SBRunning.GetFolderAction(ExportName)))
    Next
    objFileToWrite.Close
    Set objFileToWrite = Nothing
  End If
End Sub

Sub RunDiffOpened
  ' Uncomment the following line if you want to do the export
  ' when the window opens instead of closes. Or you may want
  ' to export before and after to see what was changed by the
  ' user.

  ' DoTheExport
End Sub

Sub RunDiffClosed(Aborted)
  ' If the user aborted then do nothing
  If Aborted then
    Exit Sub
  End If

  DoTheExport
End Sub

'
' Configuration part of the script
'

' Not for group profiles, and only display setup page if the profile
' is using the script.
Function ConfigWantSetupNode(IsGroup)
  ConfigWantSetupNode = not IsGroup and SBProfile.UsesScript
End Function

' Reset to factory defaults
Sub ConfigFactoryDefaults
  SBVariables.DeleteProperty("DEFiles")
  SBVariables.DeleteProperty("DEFolders")
End Sub

' Always allow the setup page to close
Function ConfigCanClose
  ConfigCanClose = TRUE
End Function

' Can revert to factory settings
Function ConfigCanRevert
  ConfigCanRevert = TRUE
End Function

' Setup node caption
Function ConfigNodeCaption
  ConfigNodeCaption = "Differences Export"
End Function

' Create setup window display
Sub ConfigSetupDisplay
  SBProfile.AddEdit("The filename to store the file differences in", 256, FALSE, FALSE, 1)
  SBProfile.AddEdit("The filename to store the folder differences in", 256, FALSE, FALSE, 2)
End Sub

' Load settings. Return error message on failure.
Function ConfigLoadSettings
  ConfigLoadSettings = ""

  SBProfile.SetEdit(SBVariables.GetProperty("DEFiles", "", FALSE), 1)
  SBProfile.SetEdit(SBVariables.GetProperty("DEFolders", "", FALSE), 2)
End Function

' Save settings. Return error message on failure.
Function ConfigSaveSettings(Silent)
  ConfigSaveSettings = ""

  SBVariables.SetProperty("DEFiles", SBProfile.GetEdit(1))
  SBVariables.SetProperty("DEFolders", SBProfile.GetEdit(2))
End Function

' The settings have changed
Sub ConfigUpdateConditionals
End Sub
