rejetto forum

bug corrected on macros 'move' 'delete' 'rename' with event [upload completed]

Mars · 3 · 3926

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
only two lines are necessary into main.pas, to allow the macro move to works in event section [upload completed], and the macro delete and rename the uploaded file

Quote
  function calcAverageSpeed(bytes:int64):integer;
  begin result:=round(safeDiv(bytes, (now()-data.fileXferStart)*SECONDS*1000)) end;

  procedure closeUploadingFile(); forward; //add by mars

  function runEventScript(event:string; table:array of string):string; overload;
  var
    md: TmacroData;
    pleaseFree: boolean;
  begin
   ...
    if assigned(md.f) and (md.folder = NIL) then
      md.folder:=md.f.getParent();

    if event='upload completed' then closeUploadingFile();  //add by mars

    tryApplyMacrosAndSymbols(result, md);
  finally
    if pleaseFree then
      freeIfTemp(md.f);
    end;
  end; // runEventScript

j'ai utilisé ici une instruction forward pour ne pas avoir à déplacer la procedure closeUploadingFile() . ;)
 Mais je suis sûr que toi , tu le feras. N'est-ce pas Oncle Max?  :D


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
c'est vrai ;D
your solution seems to be working mars, but it's a little dirty, so i decided to study a little more before to accept it.
our problem is closing the file a bit earlier, but to be still able to read the name of the file.
i noticed the name of the file is already kept in uploadDest, so every place where i used getFilename(data.f^) can be replaced by data.uploadDest.
...and now we can safely close the file before the event call :)
this solution seems to be better

Code: [Select]
  function runEventScript(event:string; table:array of string):string; overload;
...
  try
    if isReceivingFile(data) then
      begin
      // we must encapsulate it in a Tfile to expose file properties to the script. we don't need to cache the object because we need it only once.
      md.f:=Tfile.createTemp(data.uploadDest);

and clearly

closeUploadingFile();
if data.uploadFailed = '' then runEventScript('upload completed')
else runEventScript('upload failed');
« Last Edit: May 17, 2009, 07:29:58 PM by rejetto »


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
ta solution semble viable, elle me convient parfaitement ;)
« Last Edit: May 18, 2009, 08:19:07 AM by mars »