root/_FilesPanel/BF_GUI_FilesPanel_Tasks.cpp

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. RenameNodes
  2. Check_DestFolder
  3. PrepareTrashPath
  4. DeleteList
  5. CheckFolder_ForSys
  6. Run
  7. Copy_Atributes
  8. Copy_Nodes
  9. Move_Nodes
  10. Run
  11. Run
  12. Run
  13. Run

   1 #include <stdio.h>
   2 #include <File.h>
   3 #include <fs_attr.h>
   4 #include <stdlib.h>
   5 
   6 #include "BF_GUI_FilesPanel_Tasks.h"
   7 #include "BF_Dict.h"
   8 #include "BF_Roster.h"
   9 
  10 BF_GUI_FilesPanel_Task::BF_GUI_FilesPanel_Task(const char *pc_Name,int32 i_Styles)
  11 :BF_GUI_OperTask(pc_Name,i_Styles)
  12 {
  13 }
  14 
  15 void
  16 BF_GUI_FilesPanel_Task::RenameNodes(    /* [previous][next][first][last][top][bottom][index][help] */
  17         const BF_NodeCollection & lo_Node,
  18         const BF_FilesPath & o_SrcPath,
  19         const BL_String &s_NewName)
  20 {
  21         BF_Node         *poNode=NULL;
  22         BL_String       s;
  23         const char  *pcNewName = NULL;
  24         BL_String       sAfterMask;
  25         
  26         
  27                 // check drive for read_only //
  28         if(o_SrcPath.IsVolumeReadOnly()){
  29                 Ask_Error(BF_DictAt(BF_DICT_TASKS_READONLYVOL),false);
  30                 return;
  31         }
  32 
  33         
  34         // check mask 
  35         if(s_NewName.FindFirst("*")<0)
  36         {// has not mask_chars
  37                 // check count 
  38                 if(lo_Node.CountItems()>1){
  39                         Ask_Error(BF_DictAt(BF_DICT_TASKS_ONENAMEMANYFILES),false,s_NewName.String());
  40                         return;
  41                 }
  42         }       
  43         
  44         SetProgress(0,lo_Node.CountItems());
  45         
  46         for(int i=0;i<lo_Node.CountItems();i++){
  47                 poNode = lo_Node.NodeAt(i);
  48                 
  49                 pcNewName = s_NewName.String();
  50                 
  51                 if(poNode->ConvertNameByMask(s_NewName,sAfterMask)){
  52                         pcNewName = sAfterMask.String();
  53                 }
  54                 
  55                 ASSERT(pcNewName);
  56                 
  57                 status_t uRes = BF_Roster_RenameNode(o_SrcPath,poNode,pcNewName);
  58                 if(uRes!=B_OK){
  59                         BL_String s;
  60                         BL_System_TranslError(uRes,s);
  61                         if(BF_GUI_OPERTASK_ERROR_OK!=Ask_Error(s.String())) return;
  62                 }
  63                                 
  64                 SetProgress(i,lo_Node.CountItems());
  65                 if(Canceled()) return;
  66         }
  67 }
  68 
  69 bool
  70 BF_GUI_FilesPanel_Task::Check_DestFolder(BF_FilesPath &oPathDest)    /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72         // check dest_path for normal rules 
  73         if(!oPathDest.IsStorageKit()){
  74                 Ask_Error(BF_DictAt(BF_DICT_TASKS_DESTFOLDERNAMEWRONG),false,oPathDest.Path());
  75                 return false;           
  76         }
  77         
  78         // check dest_path on existing          
  79         if(!oPathDest.IsExisting())
  80         {// not exist,create  it ? //
  81                 BL_List *ploMenu = new BL_List();
  82                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_TASKS_CREATEITNOW),""));
  83                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCEL),""));
  84                 
  85                 // ask question                 
  86                 if(1==Ask_Message(BF_DictAt(BF_DICT_TASKS_DESTFOLDERNOTEXIST),ploMenu)) return false;
  87                 // try to create 
  88                 status_t uRes = oPathDest.Create();
  89                 // check result of creating
  90                 if(uRes!=B_OK){
  91                         Ask_Error(BF_DictAt(BF_DICT_TASKS_CANTMAKEFOLDER),false,oPathDest.Path());
  92                         return false;
  93                 }                               
  94         }
  95                 
  96         // check drive for read_only //
  97         if(oPathDest.IsVolumeReadOnly()){
  98                 Ask_Error(BF_DictAt(BF_DICT_TASKS_DESTVOLREADONLY),false);
  99                 return false;
 100         }
 101         
 102         return true;
 103 }
 104 
 105 
 106 /////////////////////////////////////////////////////////////////////////
 107 
 108 
 109 BF_GUI_FilesPanel_DeleteTask::BF_GUI_FilesPanel_DeleteTask(
 110         BF_FilesPath o_Path,
 111         BF_NodeCollection & lo_Node,
 112         BF_GUI_FilesPanel_DeleteTask_Type i_DeleteType
 113 ):BF_GUI_OperTask("")
 114 {
 115         iOperIndex = 0;
 116         iOperCount = lo_Node.CountItems();
 117         
 118         oPath = o_Path;         
 119         lo_Node.CopyTo(loNode,false);
 120         loNode.SetSelfPath(&oPath);
 121         iDeleteType = i_DeleteType;     
 122         
 123         // prepare sys_paths // 
 124         lsSysPath.AddItem(new BL_String("/boot/home"));
 125         lsSysPath.AddItem(new BL_String("/boot"));
 126         lsSysPath.AddItem(new BL_String("/boot/home/config"));
 127         lsSysPath.AddItem(new BL_String("/boot/home/mail"));
 128         lsSysPath.AddItem(new BL_String("/boot/home/apps"));
 129         //lsSysPath.AddItem(new BL_String("/boot/home/test"));
 130         
 131         // set new name //
 132         {
 133                 BL_String s;
 134                 s = "deleting files from /";
 135                 s << oPath.LastDir();
 136                 sName = s;
 137         }       
 138 }
 139 
 140 
 141 bool
 142 BF_GUI_FilesPanel_DeleteTask::PrepareTrashPath()    /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         BL_String s(oPath.GetVolume());
 145         if(s=="") return false;
 146         sTrashPath = s;
 147         sTrashPath<<"/home/Desktop/Trash";
 148         if(!BF_Roster_NodeExists(sTrashPath.String())){
 149                 sTrashPath = s;
 150                 sTrashPath<<"/RECYCLED/_BEOS_";
 151                 if(!BF_Roster_NodeExists(sTrashPath.String())){
 152                         if(B_OK!=BF_Roster_MakeDir(sTrashPath.String())){
 153                                 s=BF_DictAt(BF_DICT_TASKS_CANTMAKETRASH);
 154                                 s<<sTrashPath.String();
 155                                 ASSERT(false,s.String());
 156                         }
 157                 }
 158         }
 159         return true;
 160 }
 161 
 162 bool
 163 BF_GUI_FilesPanel_DeleteTask::DeleteList(BF_NodeCollection & lo_Node)    /* [previous][next][first][last][top][bottom][index][help] */
 164 {
 165         BF_Node         *poNode;
 166         status_t        uRes;
 167         BL_String   s;
 168         
 169         for(int i=0;i<lo_Node.CountItems();i++){
 170                 poNode = (BF_Node*)lo_Node.ItemAt(i);
 171                 
 172                 if(poNode->iType==BF_NODE_TYPE_DIR){
 173                         // check folder_path+name //
 174                         ASSERT(lo_Node.poPath);
 175                         s = lo_Node.poPath->Path();
 176                         s << "/";
 177                         s << poNode->sName;
 178                         if(!CheckFolder_ForSys(s.String())){
 179                                 return false;
 180                         }                                       
 181                 }
 182                 
 183                 if(poNode->ploChild){                                           
 184                         DeleteList(*poNode->ploChild);
 185                 }
 186                 // check, remove file or move it to trash
 187                 if(BF_FILESPANEL_DELETE_TO_VOID==iDeleteType){
 188                         BF_Roster_RemoveNode(*lo_Node.poPath,poNode);
 189                 }else
 190                 if(BF_FILESPANEL_DELETE_TO_TRASH==iDeleteType){                 
 191                         int64           iIndex = 1;     
 192                         char            *pcName=NULL;
 193                         while(TRUE){
 194                                 uRes = BF_Roster_MoveNode(*lo_Node.poPath,poNode,sTrashPath.String(),pcName);
 195                                 if(B_OK==uRes) break;
 196                                 /* try to move to new name */
 197                                 if(B_FILE_EXISTS==uRes){
 198                                         s=poNode->sName;
 199                                         s<<" ";
 200                                         s<<iIndex++;
 201                                         pcName = (char*)s.String();
 202                                         continue;
 203                                 }
 204                                 /* ups....some error */                         
 205                                 BL_System_TranslError(uRes,s);
 206 
 207                                 BL_List *ploMenu = new BL_List();
 208                                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_TRYAGAIN),"try"));
 209                                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_SKIP),"skip"));
 210                                 
 211                                 if(1==Ask_Message(s.String(),ploMenu)) break;
 212                         }
 213                 }
 214                 //
 215                 SetProgress(++iOperIndex,iOperCount);
 216                 /* check for cancel_process */          
 217                 if(Canceled()) return false;                            
 218                 
 219         }
 220         return true;
 221 }
 222 
 223 bool
 224 BF_GUI_FilesPanel_DeleteTask::CheckFolder_ForSys(const char *pc_Folder)    /* [previous][next][first][last][top][bottom][index][help] */
 225 {       
 226         
 227         // check  current path //
 228         BL_String *ps=NULL,s;
 229         
 230         for(int i=0;i<lsSysPath.CountItems();i++){
 231                 ps = (BL_String*)lsSysPath.ItemAt(i);
 232                 if(ps->ICompare(pc_Folder)!=0) continue;
 233                 
 234                 // prepare menu_buttons //
 235                 BL_List *ploMenu = new BL_List();
 236                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_YES),"yes"));
 237                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_NO),"no"));
 238                 
 239                 // ask //
 240                 int32 iResult = Ask_Message(BF_DictAt(BF_DICT_TASKS_SYSFOLDERDELETE),ploMenu,pc_Folder);
 241                 if(iResult!=0) return false;
 242                 
 243         }
 244         return true;    
 245 }
 246 
 247 void
 248 BF_GUI_FilesPanel_DeleteTask::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 249 {
 250         // check drive for read_only //
 251         if(oPath.IsVolumeReadOnly()){
 252                 Ask_Error(BF_DictAt(BF_DICT_TASKS_READONLYVOL),false);
 253                 return;
 254         }       
 255 
 256         /// prepare ///
 257         if(BF_FILESPANEL_DELETE_TO_TRASH==iDeleteType) if(!PrepareTrashPath()) return;          
 258         
 259         // load childs for void_deleting
 260         if(BF_FILESPANEL_DELETE_TO_VOID==iDeleteType){                  
 261                 loNode.LoadChilds(BF_ROSTER_LOAD_NODE_ALL_REAL|BF_ROSTER_LOAD_NORMAL);
 262                 iOperCount = loNode.CountAll(true);
 263                 SetProgress(iOperIndex,iOperCount);
 264         }       
 265                                 
 266         /// run ///
 267         DeleteList(loNode);
 268 }
 269 /////////////////////////////////////////////////////////////////////////
 270 
 271 BF_GUI_FilesPanel_CopyTask::BF_GUI_FilesPanel_CopyTask(
 272         BF_FilesPath& o_PathSrc,
 273         BF_FilesPath& o_PathDest,       
 274         BF_NodeCollection & lo_Node,
 275         bool b_FilesMove
 276 ):BF_GUI_FilesPanel_Task(BF_DictAt(BF_DICT_TASKS_COPYINGFILES))
 277 {       bFilesMove = b_FilesMove;
 278         oPathSrc = o_PathSrc;
 279         oPathDest = o_PathDest;
 280         lo_Node.CopyTo(loNode,false);
 281         loNode.SetSelfPath(&oPathSrc);
 282         
 283         iOperIndex = 0;
 284         iOperCount = loNode.CountItems();       
 285         
 286         // set new name //
 287         {
 288                 BL_String s;
 289                 s = BF_DictAt(BF_DICT_TASKS_COPYINGFILESFROM);
 290                 s << oPathSrc.LastDir();
 291                 s << BF_DictAt(BF_DICT_TASKS_COPYINGFILESTO);
 292                 s << oPathDest.LastDir();
 293                 sName = s;
 294         }       
 295 }
 296 
 297 /* copy atribytes */
 298 bool 
 299 BF_GUI_FilesPanel_CopyTask::Copy_Atributes(BNode & o_NodeSrc,BNode & o_NodeDest)    /* [previous][next][first][last][top][bottom][index][help] */
 300 {
 301         char            pcName[B_ATTR_NAME_LENGTH];
 302         attr_info       uAttrInfo;
 303         uint32          iBufMaxSize=255;
 304         char            *pcBuf = (char*)malloc(iBufMaxSize);
 305         
 306         o_NodeSrc.RewindAttrs();
 307         //
 308         while(B_OK==o_NodeSrc.GetNextAttrName(pcName)){
 309                 if(B_OK==o_NodeSrc.GetAttrInfo(pcName,&uAttrInfo)){
 310                         /* check buffer size  */
 311                         if(uAttrInfo.size>iBufMaxSize){
 312                                 DELETE(pcBuf);
 313                                 iBufMaxSize = uAttrInfo.size;
 314                                 pcBuf = (char*)malloc(iBufMaxSize);                                                                     
 315                         }
 316                         /* read attr */
 317                         o_NodeSrc.ReadAttr(pcName,uAttrInfo.type,0,
 318                                 (void*)pcBuf,uAttrInfo.size);
 319                         /* write attr */
 320                         o_NodeDest.WriteAttr(pcName,uAttrInfo.type,
 321                                         0,(void*)pcBuf,uAttrInfo.size);
 322                         /* check for cancel_process */          
 323                         if(Canceled()) return false;                            
 324                 }
 325         }                                               
 326         DELETE(pcBuf);
 327         return true;
 328 }/* end of atributes */                                 
 329 
 330 
 331 bool
 332 BF_GUI_FilesPanel_CopyTask::Copy_Nodes(    /* [previous][next][first][last][top][bottom][index][help] */
 333         BF_NodeCollection *plo_Node,
 334         BString         & s_NewPath,
 335         bool            b_DeleteAfterCopy)
 336 {
 337         if(!plo_Node) return true;
 338 
 339         BF_Node         *poNode;
 340         BL_String       s,s1;
 341         const char      *pcNewName;
 342         status_t        uRes;
 343         BString         sNewName;
 344                 
 345         for(int i=0;i<plo_Node->CountItems();i++){
 346                 poNode = (BF_Node*)plo_Node->ItemAt(i);
 347                 ASSERT(plo_Node->poPath);               
 348                 /* convert name for mask */
 349                 /*
 350                 if(poNode->ConvertNameByMask(s_NewPath,sNewName)) pcNewName = sNewName.String();
 351                 else */pcNewName = poNode->sName.String();
 352                 /* make new link */             
 353                 if(poNode->bLink){
 354                         // make link
 355                         s=plo_Node->poPath->Path();
 356                         s<<"/";
 357                         s<<poNode->sName;
 358                         s1=s_NewPath;
 359                         s1<<"/";
 360                         s1<<pcNewName;
 361                         while(true){
 362                                 uRes = BF_Roster_MakeLink(s.String(),s1.String());
 363                                 if(B_FILE_EXISTS==uRes){
 364                                         BF_GUI_OperTask_Copy_Answer iResult = Ask_Copy_FileExist(poNode->Name(),false);
 365                                         
 366                                         if(BF_GUI_OPERTASK_COPY_SKIP == iResult ){                                              
 367                                                 break;
 368                                         }else
 369                                         if(BF_GUI_OPERTASK_COPY_OVERWRITE == iResult){
 370                                                 BF_Roster_RemoveNode(s1.String());                                      
 371                                                 continue;
 372                                         }else
 373                                         if(BF_GUI_OPERTASK_COPY_CANCEL == iResult){
 374                                                 return false;
 375                                         }else
 376                                         {}                                                              
 377                                 }else
 378                                 if(B_OK!=uRes){
 379                                         // show message about uknown error //                                   
 380                                         BL_System_TranslError(uRes,s);
 381                                         if(BF_GUI_OPERTASK_ERROR_CANCEL_ALL==Ask_Error(s.String())) 
 382                                                 return false; // cancel all //
 383                                 }else
 384                                 {}
 385                                 break;
 386                         }
 387                         //iOperIndex += poNode->iSize;
 388                         //SetProgress(iOperIndex,iOperCount);                   
 389                 }else
 390                 // make new dir //
 391                 if(BF_NODE_TYPE_DIR==poNode->iType){
 392                         // make new dir //
 393                         s=s_NewPath;
 394                         s<<"/";
 395                         s<<pcNewName;
 396                         BF_Roster_MakeDir(s.String());                  
 397                         
 398                         //iOperIndex += poNode->iSize;
 399                         //SetProgress(iOperIndex,iOperCount);
 400                         
 401                         // copy atributes //
 402                         {
 403                                 // open src and dest nodes //
 404                                 BNode oDirDest(s.String());
 405                                 
 406                                 s1=plo_Node->poPath->Path();
 407                                 s1<<"/";
 408                                 s1<<poNode->sName;                      
 409                                 
 410                                 BNode oDirSrc(s1.String());                             
 411                                 
 412                                 if(!Copy_Atributes(oDirSrc,oDirDest)) return false;
 413                         }                                               
 414                         // copy childs  //
 415                         BString  sNewPath(s);
 416                         if(!Copy_Nodes(poNode->ploChild,sNewPath,b_DeleteAfterCopy)) return false;                                              
 417                 }else                                   
 418                 // copy file //
 419                 {               
 420                         // open source file
 421                         s=plo_Node->poPath->Path();
 422                         s<<"/";
 423                         s<<poNode->sName;                       
 424                         
 425                         BFile oSrcFile(s.String(),B_READ_ONLY);
 426                         if(B_OK==oSrcFile.InitCheck()){                         
 427                                 // open dest file
 428                                 s="";
 429                                 if(!strchr(pcNewName,'/')) 
 430                                         if(s_NewPath.FindFirst("/")==0) s<<s_NewPath; else        s<<plo_Node->poPath->Path();
 431                                 s<<"/";
 432                                 s<<pcNewName;
 433                                 BFile oDestFile;        
 434                                 
 435                                 /*uRes = oDestFile.SetTo(s.String(),B_READ_WRITE | B_CREATE_FILE | B_FAIL_IF_EXISTS);                           
 436                                 if(B_FILE_EXISTS==uRes){*/
 437                                 
 438                                 uRes = oDestFile.SetTo(s.String(),B_READ_ONLY);                         
 439                                 
 440                                 if(B_OK==uRes){
 441                                         BF_GUI_OperTask_Copy_Answer iResult = Ask_Copy_FileExist(poNode->Name());
 442                                         if(BF_GUI_OPERTASK_COPY_SKIP == iResult ){
 443                                                 iOperIndex+=poNode->iSize;
 444                                                 SetProgress(iOperIndex,iOperCount);
 445                                                 continue;
 446                                         }else
 447                                         if(BF_GUI_OPERTASK_COPY_APPEND == iResult){
 448                                                 uRes = oDestFile.SetTo(s.String(),B_READ_WRITE | B_CREATE_FILE | B_OPEN_AT_END);                                
 449                                         }else
 450                                         if(BF_GUI_OPERTASK_COPY_OVERWRITE == iResult){
 451                                                 uRes = oDestFile.SetTo(s.String(),B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);                         
 452                                         }else
 453                                         if(BF_GUI_OPERTASK_COPY_CANCEL == iResult){
 454                                                 return false;
 455                                         }else
 456                                         {}
 457                                 }
 458                                 else{
 459                                         uRes = oDestFile.SetTo(s.String(),B_READ_WRITE | B_CREATE_FILE | B_FAIL_IF_EXISTS);                                     
 460                                 }                                                                               
 461                                                                                 
 462                                 if(B_OK == uRes)
 463                                 {
 464                                         //oDestFile.Unset();
 465                                         //oDestFile.SetTo(s.String(),
 466                                         /// copy data
 467                                         uint64  iStart=0,iCount=0;                                      
 468                                         while(iStart<poNode->iSize){
 469                                                 // calc buffer_size
 470                                                 iCount = BF_GUI_FILESPANEL_COPY_BUFFER_SIZE;
 471                                                 if((iStart+iCount)>poNode->iSize)       iCount = poNode->iSize-iStart;
 472                                                 // read
 473                                                 oSrcFile.Read((void*)pcBuffer,iCount);
 474                                                 // write
 475                                                 oDestFile.Write((void*)pcBuffer,iCount);                                                                                                
 476                                                 // step one_progress
 477                                                 iStart+=iCount;
 478                                                 iOperIndex+=iCount;
 479                                                 //printf("iOperIndex=%i  iCount=%i\n",iOperIndex,iCount);
 480                                                 SetProgress(iOperIndex,iOperCount);                                                                                             
 481                                                 /* check for cancel_process */          
 482                                                 if(Canceled()) return false;                            
 483                                         }                                                                                                       
 484                                 }else /* end of work with oDestFile */
 485                                 { // skip this file
 486                                         BL_String sError;
 487                                         BL_System_TranslError(uRes,sError);
 488                                         if(BF_GUI_OPERTASK_ERROR_CANCEL_ALL==Ask_Error(sError.String())) return false;
 489                                         iOperIndex+=poNode->iSize;
 490                                         SetProgress(iOperIndex,iOperCount);                                                             
 491                                 }                               
 492                                 if(!Copy_Atributes(oSrcFile,oDestFile)) return false;
 493                                 oDestFile.Unset();                              
 494                         }
 495                 } /* end of file_node */
 496                 /* check for cancel_process */          
 497                 if(Canceled()) return false;                            
 498                 /* delete, if removing */
 499                 if(b_DeleteAfterCopy){
 500                         BF_Roster_RemoveNode(*plo_Node->poPath,*poNode);
 501                 }
 502         }                               
 503         return true;
 504 }
 505 
 506 void                                                            
 507 BF_GUI_FilesPanel_CopyTask::Move_Nodes()    /* [previous][next][first][last][top][bottom][index][help] */
 508 {
 509         iOperCount = loNode.CountItems();
 510         SetProgress(iOperIndex,iOperCount);
 511         
 512         BF_Node         *poNode=NULL;
 513         status_t        uRes=B_ERROR;   
 514         
 515         
 516         for(int i=0;i<loNode.CountItems();i++){
 517                 poNode = loNode.NodeAt(i);
 518                 while(true){
 519                         uRes = BF_Roster_MoveNode(oPathSrc,poNode,oPathDest.Path());
 520                         if(uRes==B_OK) break;
 521                         if(B_FILE_EXISTS == uRes){
 522                                 BL_String s(BF_DictAt(BF_DICT_TASKS_DESTFILE));
 523                                 s<<poNode->sName;
 524                                 s<<BF_DictAt(BF_DICT_TASKS_DESTFILEEXIST);
 525                                 BL_List *ploMenu= new BL_List();
 526                                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_OWERWRITE),"") );
 527                                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_SKIP),"") );
 528                                 ploMenu->AddItem(new BF_GUI_ViewMenu_Item(BF_DictAt(BF_DICT_CANCELALL),"") );
 529                                 int iRes = Ask_Message(s.String(),ploMenu);
 530                                 if(iRes==0){
 531                                         // delete dest_file //
 532                                         BF_Roster_RemoveNode(oPathDest,poNode->sName.String());
 533                                         continue;
 534                                 }else
 535                                 if(iRes==2){
 536                                         // cancel all //
 537                                         i = loNode.CountItems()+1;                                                                                                      
 538                                 }
 539                         }else{
 540                                 BL_String s(BF_DictAt(BF_DICT_TASKS_CANTMOVE)),s1;
 541                                 BL_System_TranslError(uRes,s1); 
 542                                 s<<poNode->sName;                                                       
 543                                 if(BF_GUI_OPERTASK_ERROR_CANCEL_ALL==Ask_Error(s.String(),true,s1.String()) ){                          
 544                                         // cancel all //
 545                                         i = loNode.CountItems()+1;                              
 546                                 }                               
 547                         }       
 548                         break;          
 549                 }
 550                 SetProgress(++iOperIndex,iOperCount);
 551         }
 552 }
 553 
 554 void                                                            
 555 BF_GUI_FilesPanel_CopyTask::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 556 {       
 557         if(bFilesMove)
 558         {// prepare to move 
 559         
 560                 BL_String s(oPathDest.Path());
 561                 
 562                 // check first slash 
 563                 if(s.FindFirst("/")==0){
 564                         // begin from slash
 565                         if(s.FindFirst("*")>=0){
 566                                 Ask_Error("Sorry, but this release can`t move and rename by mask at one time",false);
 567                                 return;
 568                         }
 569                 }else{
 570                         // begin from non-slash
 571                         // rename files
 572                         RenameNodes(loNode,oPathSrc,s);
 573                         return;                 
 574                 }
 575         
 576                 BL_String  sSrcVol(oPathSrc.GetVolume()),sDestVol(oPathDest.GetVolume());
 577                 if(sSrcVol==sDestVol){
 578                         Move_Nodes();
 579                         return; 
 580                 }               
 581         }else
 582         {// prepare to copy 
 583                 
 584         }
 585         
 586         if(!Check_DestFolder(oPathDest)) return;
 587         
 588         // load childs for 
 589         {                       
 590                 loNode.LoadChilds(BF_ROSTER_LOAD_NODE_ALL_REAL|BF_ROSTER_LOAD_NORMAL);
 591                 iOperCount = loNode.SizeAll(true);
 592                 SetProgress(iOperIndex,iOperCount);
 593         }
 594         BL_String sNewPath(oPathDest.Path());
 595         Copy_Nodes(&loNode,sNewPath,bFilesMove);
 596 }
 597 
 598 
 599 /////////////////////////////////////////////////////////////////////////
 600 
 601 BF_GUI_FilesPanel_ChangeCaseTask::BF_GUI_FilesPanel_ChangeCaseTask(
 602         BF_FilesPath& o_Path,
 603         BF_NodeCollection & lo_Node,
 604         int32 i_CaseType
 605 ):BF_GUI_OperTask("change case")
 606 {
 607         lo_Node.CopyTo(loNode,false);
 608         iCaseType = i_CaseType;
 609         iOperIndex = 0;
 610         iOperCount = loNode.CountItems();
 611 
 612         oPath = o_Path;
 613 }
 614 
 615 void                                                            
 616 BF_GUI_FilesPanel_ChangeCaseTask::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 617 {
 618         // check drive for read_only //
 619         if(oPath.IsVolumeReadOnly()){
 620                 Ask_Error(BF_DictAt(BF_DICT_TASKS_READONLYVOL),false);
 621                 return;
 622         }       
 623 
 624         BF_Node *poNode=NULL;
 625         BL_String s;
 626         
 627         SetProgress(iOperIndex,iOperCount);
 628         
 629         for(int i=0;i<loNode.CountItems();i++){
 630                 poNode = loNode.NodeAt(i);
 631                 s = poNode->sName;
 632                 switch(iCaseType){
 633                 case 0:
 634                         s.ToLower();
 635                         break;
 636                 case 1:
 637                         s.ToUpper();
 638                         break;
 639                 case 2:
 640                         s.Capitalize();
 641                         break;
 642                 case 3:
 643                         s.CapitalizeEachWord();
 644                         break;                  
 645                 }
 646                 BF_Roster_RenameNode(oPath,poNode,s.String());
 647                 SetProgress(++iOperIndex,iOperCount);
 648                 if(Canceled()) return;
 649         }
 650 }
 651 /////////////////////////////////////////////////////////////////////////
 652 BF_GUI_FilesPanel_Rename::BF_GUI_FilesPanel_Rename(
 653         BF_FilesPath& o_Path,
 654         BF_NodeCollection & lo_Node,
 655         BL_String & s_NewName
 656 ):BF_GUI_FilesPanel_Task("rename files")
 657 {
 658         lo_Node.CopyTo(loNode,false);
 659         oPath = o_Path;
 660         sNewName = s_NewName;
 661 }
 662 
 663 void
 664 BF_GUI_FilesPanel_Rename::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 665 {
 666         RenameNodes(loNode,oPath,sNewName);
 667 }
 668 
 669 /////////////////////////////////////////////////////////////////////////
 670 BF_GUI_FilesPanel_MakeLinksTask::BF_GUI_FilesPanel_MakeLinksTask(
 671         BF_FilesPath& o_PathSrc,
 672         BF_FilesPath& o_PathDest,
 673         BF_NodeCollection & lo_Node
 674 ):BF_GUI_FilesPanel_Task("make links")
 675 {
 676         oPathSrc = o_PathSrc;
 677         oPathDest = o_PathDest;
 678         lo_Node.CopyTo(loNode,false);
 679         loNode.SetSelfPath(&oPathSrc);          
 680 }
 681         
 682 void
 683 BF_GUI_FilesPanel_MakeLinksTask::Run()    /* [previous][next][first][last][top][bottom][index][help] */
 684 {
 685         // check dest_path
 686         {
 687                 BL_String s(oPathDest.Path());
 688                                 
 689                 if(s.FindFirst("/")==0)
 690                 {// path begin from /
 691                         if(s.FindFirst("*")>=0)
 692                         {// path include * 
 693                                 Ask_Error(BF_DictAt(BF_DICT_TASKS_CANTMAKERENAME),false);
 694                                 return;         
 695                         }                                               
 696                 }else
 697                 {// path dosn`t begin from /
 698                         if(s.FindFirst("/")>0)
 699                         {// path include /
 700                                 Ask_Error(BF_DictAt(BF_DICT_TASKS_CANTMAKEINFOLDER),false,s.String());
 701                                 return;
 702                         }                       
 703                         // ? mask with * 
 704                         if(s.FindFirst("*")>=0){        
 705                                 // ok mask with *, mask = dest_path and dest_path = oPathSrc
 706                                 sMask = s;
 707                                 oPathDest = oPathSrc;
 708                         }else{
 709                                 // fuck,mask without *                          
 710                                 if(loNode.CountItems()>1){
 711                                         Ask_Error(BF_DictAt(BF_DICT_TASKS_CANTMAKELINKONENAME),false,s.String());
 712                                         return; 
 713                                 }else{
 714                                         // ok, we must make only one link
 715                                         sMask = s;
 716                                         oPathDest = oPathSrc;
 717                                 }
 718                         }                       
 719                 }
 720         }
 721 
 722         // check dest_path
 723         if(!Check_DestFolder(oPathDest)) return;        
 724 
 725         // start //
 726         
 727         SetProgress(0,loNode.CountItems());     
 728         
 729         BL_String       sSrc,sDest,s,s1;
 730         status_t        uRes;
 731         BF_Node         *poNode=NULL;
 732         
 733         
 734         for(int i=0;i<loNode.CountItems();i++){
 735                 poNode = loNode.NodeAt(i);
 736         
 737                 sSrc = oPathSrc.Path();
 738                 sSrc<<"/";
 739                 sSrc<<poNode->Name();
 740                 
 741                 sDest = oPathDest.Path();
 742                 sDest<<"/";
 743                 sDest<<*poNode->ConvertNameByMaskExt(sMask,s1);
 744                 
 745                 uRes = BF_Roster_MakeLink(sSrc.String(),sDest.String());
 746                 if(B_FILE_EXISTS==uRes){
 747                         s=BF_DictAt(BF_DICT_TASKS_DESTFILE);
 748                         s<<poNode->sName;
 749                         s<<BF_DictAt(BF_DICT_TASKS_DESTFILEEXIST);
 750                         if(BF_GUI_OPERTASK_ERROR_CANCEL_ALL==Ask_Error(s.String())) return;
 751                 }else
 752                 if(uRes!=B_OK){
 753                         BL_System_TranslError(uRes,s);
 754                         if(BF_GUI_OPERTASK_ERROR_CANCEL_ALL==Ask_Error(s.String())) return;
 755                 }               
 756                 SetProgress(i,loNode.CountItems());
 757                 if(Canceled()) return;
 758         }
 759 }
 760 

/* [previous][next][first][last][top][bottom][index][help] */