//TeraCopy Integration v7.4b3 // tweaks // #1 - delete and test commands // #2 - path to the script's configuration file // #3 - the default path for the "copy/move to..." -> "browse..." dialog // #4 - delay (milisecs) before clearing the collection after operation when $clearcol==true "_settings" global $useclipboard,$workpath,$savedatabase,$teracopypath,$checkupdatefreq,$tagupdatefreq,$settagproc,$configfile,$isconf; global $copycmd,$movecmd,$delcmd,$testcmd,$color_e,$color_s,$defbrowse,$clearcol,$clearcoldelay; //tweak #1 variables: , and $delcmd='"" delete *""'; $testcmd='"" test *"" ""'; //tweak #2 $configfile="\teracopy_settings.ini"; //tweak #3 $defbrowse="%systemdrive%\.."; //tweak #4 $clearcoldelay=300; //default settings if(exists($configfile)==1){ //read settings from ini file $workpath = getkey(workpath,settings,$configfile); $teracopypath = getkey(teracopypath,settings,$configfile); $copycmd = getkey(copycmd,settings,$configfile); $movecmd = getkey(movecmd,settings,$configfile); $settagproc = getkey(settagproc,settings,$configfile); $savedatabase = getkey(savedatabase,settings,$configfile); $checkupdatefreq = getkey(checkupdatefreq,settings,$configfile); $tagupdatefreq = getkey(tagupdatefreq,settings,$configfile); $color_s = getkey(color_s,settings,$configfile); $color_e = getkey(color_e,settings,$configfile); $useclipboard = getkey(useclipboard,settings,$configfile); $clearcol = getkey(clearcol,settings,$configfile);} //else if("$workpath"==""){$workpath='%temp%';} if("$teracopypath"==""){$teracopypath='%programfiles%\TeraCopy\teracopy.exe';} if("$copycmd"==""){$copycmd='"" copy *"" ""';} if("$movecmd"==""){$movecmd='"" move *"" ""';} if("$settagproc"==""){$settagproc=2;} if("$savedatabase"==""){$savedatabase=1;} if("$checkupdatefreq"==""){$checkupdatefreq=25;} if("$tagupdatefreq"==""){$tagupdatefreq=25;} if("$color_e"==""){$color_e="FFFF00";} if("$color_s"==""){$color_s="80FF00";} if("$useclipboard"==""){$useclipboard="false";} if("$clearcol"==""){$clearcol="false";} if($isconf!=1){ $drive=gettoken(,1,":"); $workpath = regexreplace($workpath,"^\?",$drive); $workpath=eval(quote($workpath)); $teracopypath = regexreplace($teracopypath,"^\?",$drive); $teracopypath=eval(quote($teracopypath)); $copycmd=replace($copycmd,"",$teracopypath); $movecmd=replace($movecmd,"",$teracopypath); $delcmd=replace($delcmd,"",$teracopypath);} "Cut|:cut : cut" global $op,$ishere; $op=move; $ishere=1; sub _copyormove; "Copy|:copy : copy" global $op,$ishere; $op=copy; $ishere=1; sub _copyormove; "Paste|:paste : paste" global $settagproc; sub _settings; //$settagproc=2; sub _pastestart; "Paste (XYplorer style) : _pastexy" global $settagproc; sub _settings; $settagproc=1; sub _pastestart; "Paste (no tags) : _pastenotags" global $settagproc; sub _settings; $settagproc=0; sub _pastestart; - "Move to...|:moveto : moveto" global $op,$ishere; $op=move; $ishere=0; sub _copyormove; "Copy to...|:copyto : copyto" global $op,$ishere; $op=copy; $ishere=0; sub _copyormove; - "Move here by Tag...|:tagsset : movetag" global $op;$op="move";sub _tagmenu; "Copy here by Tag...|:tagsadd : copytag" global $op;$op="copy";sub _tagmenu; "_tagmenu" global $istag,$thistag,$savedatabase,$workpath,$tagset; sub _settings; //step; $tagset=0; if($savedatabase!=0){#195;} //save database $stin=readfile("\tag.dat"); //read database $sta=regexreplace($stin,"^.(?!:).+",""); //remove lines that are not items $stb=substr(regexreplace($sta,"^.+?\|.+?\|\|\|\|\|.*?$",""),2); //remove items that are not tagged (might not be necessary) $stc=regexreplace($stb,"^.+?\|.+?\|(.+?)\|\|\|\|.*?$","$1"); //remove everything but the tags $std=replace($stc,", ",""); //separate tags from same item $ste=formatlist($std,s,""); //sort and clear the tag list $stf=formatlist($ste,e,""); $stg=formatlist($stf,d,""); //generate the tags menu $tagmenu=regexreplace($stg,"^([^\r\n]+)$",'"$1" global $thistag,$tagset; $thistag="$1";$tagset=1;')."-""Cancel"""; //step; load $tagmenu,,s; end ($tagset==0); $stu=regexreplace($sta,"^([^|]+)\|.+?(\||.+, )$thistag(\||, .+)\|\|\|.*?$","$1"); //find the items with the specified tag $stv=regexreplace($stu,"^.*\|.*$",""); //and delete the others $stw=regexreplace($stv,"\r|\n",""); //fix line breaks $stx=formatlist($stw,s,""); //sort and clear the list $sty=formatlist($stx,e,""); $stz=formatlist($sty,d,""); writefile("$workpath\teracopytag.tmp",$stz.); //save list to a file $istag=1; //copytext $stz; //step; sub _copyormovecollection; - "Delete|:del : delete" global $op,$ishere; $op="delete"; $ishere=1; sub _copyormove; sub _pastestart; - "Add items to collection : addcollection" //add selected items to collection global $workpath,$totalcoll,$color_e,$color_s; sub _settings; if(get("FocusedControl")=="T"){ $items=""; $selitems=1;} else{ focus l; $items=get("SelectedItemsPathNames").; $selitems=get("CountSelected");} //get number of items if($selitems<1){ status "Nothing selected!",$color_e,alert; end 1;} writefile("$workpath\teracopycollection.tmp",$items,a); //save list of items sub _countcollected; status "TeraCopy: $selitems item".(($selitems > 1)?"s":"")." added to collection (Total=$totalcoll items)",$color_s,ready; "Move collection here : movecollection" global $op; $op=move; sub _copyormovecollection; "Copy collection here : copycollection" global $op; $op=copy; sub _copyormovecollection; "Test collected items : testcollection" global $workpath,$teracopypath,$testcmd; sub _settings; $testcmd=replace($testcmd,"",$teracopypath); $testcmd=replace($testcmd,"","$workpath\teracopycollection.tmp"); $testcmd=replace($testcmd,"",); open $testcmd,w; "View/edit collection : editcollection" global $workpath,$totalcoll,$color_s; sub _settings; sub _countcollected; $collection=input("Edit collection ($totalcoll items)",,readfile("$workpath\teracopycollection.tmp"),m); $collection=regexreplace($collection,"(\r\n){2,}",""); writefile("$workpath\teracopycollection.tmp",$collection); sub _countcollected; status "TeraCopy: $totalcoll item".(($totalcoll > 1)?"s ":" ")."in collection",$color_s,ready; "Clear collection : clearcollection" global $workpath,$color_s; sub _settings; writefile("$workpath\teracopycollection.tmp",""); status "TeraCopy: Removed all items from collection",$color_s,ready; - "Restore moved tags|:undo : restore" global $tagupdatefreqtest,$workpath,$color_s; sub _settings; msg "TeraCopy Script
Restore moved tags?",1; //confirm action $fulltaglist=readfile("$workpath\teracopymovedtags.tmp"); //read backup file $test2=replace($fulltaglist,";",""); //count items $test2=replace($test2,"",";"); $test2=regexreplace($test2,"[^;]",""); $taggedcount=strlen($test2); $counter=0; //start restore loop while($counter<$taggedcount){ $data=gettoken($fulltaglist,($counter+1),""); //get data for current item $name=gettoken($data,1,"|"); $label=gettoken($data,2,"|"); $tags=gettoken($data,3,"|"); $comm=replace($data,"$name|$label|$tags|",""); tag $label,$name; //restore tags tag $tags,$name,1; tag $comm,$name,2; if($tagupdatefreq>0){ if(strpos(($counter/$tagupdatefreq),".")==-1){ //progress update status "TeraCopy: Restoring tags ($counter/$taggedcount)",,progress; }} $counter++;} status "TeraCopy: $counter tags restored",$color_s,ready; //done! - "Configure script|:conf : configure" global $useclipboard,$workpath,$savedatabase,$teracopypath,$checkupdatefreq,$tagupdatefreq,$settagproc,$configfile,$isconf; global $movecmd,$copycmd,$color_e,$color_s,$clearcol; $isconf=1; sub _settings; $movecmd=replace($movecmd,'"',"""); $copycmd=replace($copycmd,'"',"""); $workpath=replace($workpath,'"',"""); $teracopypath=replace($teracopypath,'"',"""); $html=<<
Work Path
Handler Path
Move Command
Copy Command
Tags Processing
Do nothing
Move only (XY default)
Copy and Move
Database
Keep original
Save before changing
Save after changing
Status Update
When checking
When tagging
Status Colors
Success
Error
Collection Clear collection after operation
Send items to clipboard
MENU; $input=substr(html($html,800,600,"TeraCopy Script Settings"),3); end ("$input"==""); //step; $useclipboard="false"; $clearcol="false"; $count=2; while(1){ $current=replace(urldecode(gettoken($input,$count,"&")),"'","''"); if("$current"==""){break;} $command=regexreplace($current,"^(\w+)=(.*)$","global $$$1; $$$1='$2';"); load $command,,s; $count++;} setkey $workpath,workpath,settings,$configfile; setkey $teracopypath,teracopypath,settings,$configfile; setkey $copycmd,copycmd,settings,$configfile; setkey $movecmd,movecmd,settings,$configfile; setkey $settagproc,settagproc,settings,$configfile; setkey $savedatabase,savedatabase,settings,$configfile; setkey $checkupdatefreq,checkupdatefreq,settings,$configfile; setkey $tagupdatefreq,tagupdatefreq,settings,$configfile; setkey $color_s,color_s,settings,$configfile; setkey $color_e,color_e,settings,$configfile; setkey $useclipboard,useclipboard,settings,$configfile; setkey $clearcol,clearcol,settings,$configfile; status "TeraCopy: Settings saved!",$color_s,ready; - "Cancel : cancel" end 1; "copy or move : _copyormove" global $useclipboard,$workpath,$teracopypath,$op,$ishere,$path,$selitems,$savedatabase,$iscollection,$settagproc; global $movecmd,$copycmd,$color_e,$color_s,$defbrowse; sub _settings; if(get("FocusedControl")=="T"){ //if focus is on the tree $items=""; //get focused folder folder $selitems=1;} else{ //else make sure focus is on the list focus l; $items=get("SelectedItemsPathNames"); //get selected items $selitems=get("CountSelected");} //and the number of items if($selitems<1){ status "Nothing selected!",$color_e,alert; end 1;} if($ishere==0){ $favorites=get("list_copyto"); $favorites=regexreplace($favorites,"\\+$",""); $favorites=regexreplace($favorites,"^([^\r\n]+)$",'"$1|$1" global $path; $path="$1";'); //generate a menu using the fav. folders $path='$path'; $favorites=<<'); $path=eval(quote($path)); $path=replace($path,'<$>','$'); if(exists($teracopypath)!=1){ //check if teracopy exists and use the default file handler if necessary if("$op"=="move"){moveto $path;} else{copyto $path;} end 1;} writefile("$workpath\teracopylist.tmp",$items); //save list of items end (exists($path)==1), "Target path is a file!"; if(exists($path)==0){new $path,dir;} if("$op"=="move"){ //launch copy handler $movecmd=replace($movecmd,"","$workpath\teracopylist.tmp"); $movecmd=replace($movecmd,"",$path); open $movecmd,w;} else{ $copycmd=replace($copycmd,"","$workpath\teracopylist.tmp"); $copycmd=replace($copycmd,"",$path); open $copycmd,w;} $iscollection=0; if($settagproc==2){ //see what to do with tags sub _updatetags; if($savedatabase==2){#195;}} //check if tag.dat must be saved after moving or copying tags elseif($settagproc==1){ if("$op"=="move"){ sub _updatetags; if($savedatabase==2){#195;}}} status "TeraCopy: $selitems item".(($selitems > 1)?"s ":" ").(("$op"=="copy")?"copied":"moved")." to $path",$color_s,ready;} else{ //step; if(exists($teracopypath)!=1){ if("$op"=="move"){#200;} elseif("$op"=="copy"){#201;} elseif("$op"=="delete"){#169;} end 1;} elseif("$useclipboard"=="true"){ if("$op"=="move"){#200;} elseif("$op"=="copy"){#201;}} writefile("$workpath\teracopylist.tmp",$items); setkey $op,operation,tc,"$workpath\teracopyvars.tmp"; //save operation setkey $selitems,selitems,tc,"$workpath\teracopyvars.tmp"; //save item count if("$op"!="delete"){ status "TeraCopy: ".("$op"=="move")?("Cut "):("Copy ")."($selitems item".(($selitems > 1)?"s":"").")",$color_s,ready;}} "_pastestart" global $selitems,$path,$op,$settagproc,$workpath,$savedatabase,$teracopypath,$iscollection; global $movecmd,$copycmd,$delcmd,$color_e,$color_s; if((exists($teracopypath)!=1)&&("$op"!="delete")){ #202; end 1;} if(get("FocusedControl")=="T"){$path="";} else{focus l;$path="";} $op = getkey(operation,tc,"$workpath\teracopyvars.tmp"); //get operation, number of items and source path $selitems = getkey(selitems,tc,"$workpath\teracopyvars.tmp"); if("$op"=="move"){ //launch copy handler $movecmd=replace($movecmd,"","$workpath\teracopylist.tmp"); $movecmd=replace($movecmd,"",$path); open $movecmd,w;} elseif("$op"=="copy"){ $copycmd=replace($copycmd,"","$workpath\teracopylist.tmp"); $copycmd=replace($copycmd,"",$path); open $copycmd,w;} elseif("$op"=="delete"){ $delcmd=replace($delcmd,"","$workpath\teracopylist.tmp"); open $delcmd,w;} $iscollection=0; //step; if($settagproc==2){ //check if tags must be processed sub _updatetags; if($savedatabase==2){#195;}} //check if tag.dat must be saved after moving or copying tags elseif($settagproc==1){ if("$op"=="move"||"$op"=="delete"){ sub _updatetags; if($savedatabase==2){#195;}}} status "TeraCopy: $selitems item".(($selitems > 1)?"s ":" ").(("$op"=="copy")?"copied":(("$op"=="move")?"moved":"deleted")),$color_s,ready; //done! "_updatetags" global $selitems,$path,$op,$workpath,$savedatabase,$tagupdatefreq,$checkupdatefreq,$iscollection; global $color_e,$color_s,$istag; $databasebkp=readfile("\tag.dat"); //read current tag.dat #195; //save an updated tag.dat $fulltaglist="".readfile("\tag.dat").""; //read the new file if($savedatabase==0){writefile("\tag.dat","$databasebkp",,tu);} //restore or backup old tag.dat else{writefile("\bkp_tc-script_tag.dat","$databasebkp",,tu);} if($iscollection==1){ if($istag==1){$itemlist=readfile("$workpath\teracopytag.tmp")} else{$itemlist=readfile("$workpath\teracopycollection.tmp")}} //read items list else{$itemlist=readfile("$workpath\teracopylist.tmp");} $counter=0; //start the checking loop $taggeditemslist=""; $movedtagslist=""; //step; while($counter<$selitems){ $item=gettoken($itemlist,($counter+1),""); //get current item name $fulltaglistmod=replace($fulltaglist,"$item|","$item\"); //a bugfix $pos = strpos($fulltaglistmod,"$item\"); //see if it's tagged if($pos!=-1){ $fulltaglist2=replace($fulltaglist,"$item","<>"); $fulltaglist2=regexreplace($fulltaglist2,"\n(?!<>[\\|]).+$",""); $oldpath=regexreplace($item,"^(.+)\\.+?$","$1"); //get parent folder for current item $fulltaglist2=replace($fulltaglist2,"<>","$oldpath|$item"); //restore paths and save parent folder $taggeditemslist="$taggeditemslist"."$fulltaglist2";} //add new items to tag list if($checkupdatefreq>0){ if(strpos(($counter/$checkupdatefreq),".")==-1){ //progress update status "TeraCopy: Looking for tags ($counter/$selitems scanned)",,progress; //$checkupdatefreqtest=($checkupdatefreqtest+$checkupdatefreq); }} $counter++;} //step; $taggeditemslist=regexreplace($taggeditemslist,"(\r\n){2,}","");//remove any repeated line breaks $test3=replace($taggeditemslist,";",""); //count tagged items $test3=replace($test3,"",";"); $test3=regexreplace($test3,"[^;]",""); $taggedcount=strlen($test3); $taggedcount--; $counter=0; //start the tagging loop //step; while($counter<$taggedcount){ $data=gettoken($taggeditemslist,($counter+2),""); //get data for current item $oldpath=gettoken($data,1,"|"); $name=gettoken($data,2,"|"); $label=gettoken($data,3,"|"); $tags=gettoken($data,4,"|"); $comm=replace($data,"$oldpath|$name|$label|$tags||||",""); if("$op"=="delete"){ $movecheck=1; tag 0,"$name"; //remove tags tag ,"$name",1,1; tag "","$name",2; $movedtagslist="$movedtagslist"."$name|$label|$tags|$comm";} //remember removed data elseif("$oldpath"!="$path"){ //source path == target path -> bad $newname=replace($name,"$oldpath","$path"); //replace old path if("$op"=="move"){ $movecheck=1; tag 0,"$name"; //remove tags tag ,"$name",1,1; tag "","$name",2; $movedtagslist="$movedtagslist"."$name|$label|$tags|$comm";} //remember removed data tag $label,"$newname"; //set tags of pasted item tag $tags,"$newname",1; tag $comm,"$newname",2;} if($tagupdatefreq>0){ if(strpos(($counter/$tagupdatefreq),".")==-1){ //progress update status "TeraCopy: ".("$op"=="copy")?("Copying"):(("$op"=="move")?"Moving":"Deleting")." tags ($counter/$taggedcount)",,progress; }} $counter++;} //step; if($movecheck==1){writefile("$workpath\teracopymovedtags.tmp","$movedtagslist");} //save moved tags list "copy or move collection : _copyormovecollection" //move collection to current folder global $workpath,$totalcoll,$teracopypath,$iscollection,$op,$path,$selitems,$settagproc,$savedatabase; global $movecmd,$copycmd,$color_e,$color_s,$clearcol,$clearcoldelay,$istag,$thistag; sub _settings; sub _countcollected; if($totalcoll>0){ //see if there are any collected items //step; if($istag==1){$colfile="teracopytag.tmp";} else{$colfile="teracopycollection.tmp";} if(get("FocusedControl")=="T"){$path="";} else{focus l;$path="";} if(exists($teracopypath)!=1){ $itemlist=replace(readfile("$workpath\$colfile"),"","|"); if("$op"=="move"){moveto "$path","$itemlist";} else{copyto "$path","$itemlist";} status ("$op"=="move")?("Move "):("Copy ").": $totalcoll collected item".(($totalcoll > 1)?"s ":" ").("$op"=="move")?("moved"):("copied"),$color_s,ready; end 1;} if("$op"=="move"){ //launch copy handler $movecmd=replace($movecmd,"","$workpath\$colfile"); $movecmd=replace($movecmd,"",$path); open $movecmd,w;} else{ $copycmd=replace($copycmd,"","$workpath\$colfile"); $copycmd=replace($copycmd,"",$path); open $copycmd,w;} $iscollection=1; //remember that this is a collection $selitems=$totalcoll; if($settagproc==2){ sub _updatetags; if($savedatabase==2){#195;}} elseif($settagproc==1){ if("$op"=="move"){ sub _updatetags; if($savedatabase==2){#195;}}} //step; if($istag==1){ status "TeraCopy: $totalcoll item".(($totalcoll > 1)?"s ":" ")."tagged ""$thistag"" ".("$op"=="move")?("moved"):("copied"),$color_s,ready; } else{ if("$clearcol"=="true"){wait $clearcoldelay;sub clearcollection;} status "TeraCopy: $totalcoll collected item".(($totalcoll > 1)?"s ":" ").("$op"=="move")?("moved"):("copied"),$color_s,ready;}} else{status "TeraCopy: Collection is empty",$color_e,alert;} "_countcollected" global $workpath,$totalcoll,$istag; //step; if($istag==1){$colfile="teracopytag.tmp";} else{$colfile="teracopycollection.tmp";} end (exists("$workpath\$colfile")!=1), "Collection list not found!"; $totalcoll=replace(readfile("$workpath\$colfile"),"",";"); $totalcoll=regexreplace($totalcoll,"[^;]",""); $totalcoll=strlen($totalcoll);