Page 1 of 1

PascalScript: hook for both side local syncing?

Posted: Fri Apr 09, 2021 4:06 pm
by Nikolai
I wrote a PascalScript with 2 hooks: OnUploadComplete and OnDownloadComplete.
They work fine for profiles where one side is FTP or Google Drive.
But these hooks are not called if both sides are local Windows folders.

Is there any generic hook available for all sync types - local ore remote destination ?
Something like 'OnFileSynced'

My aim is to log all successfully synced files to a Sqlite database file.

Whoever is interested, here is my PascalScript:

Code: Select all

const
  pathSqlite = 'c:\Program Files\sqlite\sqlite3.exe';
  pathDatabase = 'c:\appdata\Syncovery\syncovery_log.sqlite3';


function BoolToStr(const b: Boolean): UnicodeString;
begin
 if b then
    Result := 'true'
  else
    Result := 'false';
end;

{
If 'is_right_side' is true (=1) then
the remote machine (FTP or Google Drive) is on the RIGHT-hand side of the Syncovery profile.
If 'is_right_side' is false(=0) then the remote computer is on the LEFT-hand side of the profile.
}

function OnUploadComplete(const FileName, LocalFilePath, CompleteURL: UnicodeString; const isRightSide:Boolean; const FileSize:Int64;  const Connector: Opaque):Boolean;
 var 
     sql : UnicodeString;
     cmd : UnicodeString;
begin

  sql :=  'insert into log ( syncovery_hook, profile_name, file_name, file_size, local_file_path, complete_url, is_right_side) ' + 
          'values (''OnUploadComplete'', ''' + ProfileName  + ''', ''' + FileName + ''', ' + IntToStr(FileSize) + ', ''' + LocalFilePath + ''', ''' + CompleteURL + ''', ' + BoolToStr(isRightSide) + ')';
  cmd := pathSqlite + ' ' + pathDatabase + ' "' + sql + '"';
  Execute(cmd, 100);
  Log(BoolToStr(isRightSide));
  Result:=true;
end;



function OnDownloadComplete(const FileName, LocalFilePath, CompleteURL: UnicodeString; const isRightSide:Boolean; const FileSize:Int64;  const Connector: Opaque):Boolean;
 var
     sql : UnicodeString;
     cmd : UnicodeString;
begin

  sql :=  'insert into log (syncovery_hook, profile_name, file_name, file_size, local_file_path, complete_url, is_right_side) ' + 
          'values (''OnDownloadComplete'', ''' + ProfileName  + ''', ''' + FileName + ''', ' + IntToStr(FileSize) + ', ''' + LocalFilePath + ''', ''' + CompleteURL + ''', ' + BoolToStr(isRightSide) + ')';
  cmd := pathSqlite + ' ' + pathDatabase + ' "' + sql + '"';
  Execute(cmd, 100);
  Log(BoolToStr(isRightSide));
  Result:=true;
end;



{
Table 'log' in database 'syncovery_log.sqlite3' has the following structure:

CREATE TABLE log (
    id              INTEGER  PRIMARY KEY AUTOINCREMENT,
    syncovery_hook  TEXT     NOT NULL,
    profile_name    TEXT     NOT NULL,
    file_name       TEXT     NOT NULL,
    file_size       BIGINT,
    local_file_path TEXT,
    complete_url    TEXT,
    is_right_side   BOOLEAN,
    timestamp       DATETIME DEFAULT (datetime('now', 'localtime') ) 
);


}

Re: PascalScript: hook for both side local syncing?

Posted: Sun Apr 11, 2021 2:20 pm
by tobias
Hi,
great script!

I will add a generic hook like that ASAP and let you know.

Re: PascalScript: hook for both side local syncing?

Posted: Tue Apr 20, 2021 10:00 pm
by tobias
Hello,
Syncovery 9.34 for Windows now contains a new hook named OnActionComplete.

You will find the documentation and an example on the PascalScript documentation page:
https://www.syncovery.com/pascalscript/