PascalScript: hook for both side local syncing?

General Discussion in English
Post Reply
Nikolai
Posts: 1
Joined: Fri Apr 09, 2021 3:43 pm

PascalScript: hook for both side local syncing?

Post 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') ) 
);


}
Last edited by Nikolai on Mon Apr 12, 2021 6:30 pm, edited 2 times in total.

tobias
Posts: 668
Joined: Tue Mar 31, 2020 7:37 pm

Re: PascalScript: hook for both side local syncing?

Post by tobias »

Hi,
great script!

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

tobias
Posts: 668
Joined: Tue Mar 31, 2020 7:37 pm

Re: PascalScript: hook for both side local syncing?

Post 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/

Post Reply