PascalScript: hook for both side local syncing?

General Discussion in English
Post Reply
Nikolai
Posts: 6
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: 1603
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: 1603
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/

Nikolai
Posts: 6
Joined: Fri Apr 09, 2021 3:43 pm

Re: PascalScript: hook for both side local syncing?

Post by Nikolai »

Thanks for the new hook.

But I have observed some strange behavior:

If the profile's
1) Sync Operation Mode is Move Files to Destination
and
2) the right side is a local folder
then OnActionComplete does not get triggered.

BUT:

1) If the Sync Operation Mode is Standard Copying
and
2) the right side is a local folder
then OnActionComplete does get triggered.


1) If Sync Operation Mode is Move Files to Destination
and
2) the right side is a remote folder sftp://..
then OnActionComplete also gets triggered!

Here is my profile where OnActionComplete does not get triggered(Move Files to Destination and right side is local folder):

Code: Select all

------------------------------------------------------------------

Profile Settings From C:\ProgramData\Syncovery\Syncovery.ini

[General]
Name=bla
LastModified=18.09.2023 17:03:15
LeftPath=c:\temp\sync\from
RightPath=c:\temp\sync\to
Subfolders=Yes
LeftToRight=Yes
RightToLeft=No
UseSubfolderSelection=No
MoveFilesMode=mmMoveNormal

[Comparison]
AdjustFolderTimes=Yes
SizeConflictAction=scaCopy

[Files]
DontReplaceFiles=Yes

[Files->Deletions]
RecycleDeletedFiles=No

[Job]
PascalScript=function OnActionComplete(const StartTimeUTC, CompletionTimeUTC: Double;;        const Success: Boolean;;        const ActionStr, DirectionStr, Filename,;              LeftFile, RightFile, Subfolder, MovedTo,;              ErrorMsg: UnicodeString;;        const ResultCode: Int64;;        const ErrorSide: UnicodeString;;        const ASize,ACompressedSize:Int64):Boolean;;begin;  Log('Action Complete: '+ActionStr+' '+DirectionStr+' '+Filename);;  Result:=true;;  end;

[Safety->Attended]
WarnMoving=No

[Safety->Unattended]
UnattendedDeleteMaxPercent=10


------------------------------------------------------------------
My Syncovery version: 10.7.0 (64 bit) build 120
My OS: Windows 11
Last edited by Nikolai on Tue Sep 19, 2023 6:38 am, edited 5 times in total.

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

Re: PascalScript: hook for both side local syncing?

Post by tobias »

Hi,
thanks, I will check it and fix it.

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

Re: PascalScript: hook for both side local syncing?

Post by tobias »

Hello,
this should be fixed in 10.7.2 now.

Post Reply