hschumann2/TempleOS-Source-Code
0847
1 2Bool CopySingleZ(U8 *f1,U8 *f2) //Just one file3{4 U8 *file_buf=NULL;5 I64 size,attr=0,c;6 CDirEntry de;7 if (FileFind(f1,&de,FUF_JUST_FILES)) {8 Free(de.full_name);9 file_buf=FileRead(f1,&size,&attr);10 attr=FileAttr(f2,attr);11 if (file_buf) {12 "Copying %s to %s\n",f1,f2;13 c=FileWrite(f2,file_buf,size,de.datetime,attr);14 Free(file_buf);15 return ToBool(c);16 } else17 PrintErr("File not found: \"%s\".\n",f1);18 } else19 PrintErr("File not found: \"%s\".\n",f1);20 return FALSE;21}22 23#define COPY_BUF_BLKS 0x8024Bool CopySingle(U8 *f1,U8 *f2) //Just one file25{26 U8 *absf1=FileNameAbs(f1),*absf2=FileNameAbs(f2),*buf;27 I64 cnt,n,size,attr1=FileAttr(f1),attr2=FileAttr(f2),i,j;28 CFile *in_file=NULL,*out_file=NULL;29 if (!StrCmp(absf1,absf2)) {//onto self?30 Free(absf1);31 Free(absf2);32 return FALSE;33 }34 Free(absf1);35 Free(absf2);36 if (attr1!=attr2)37 return CopySingleZ(f1,f2);38 buf=MAlloc(COPY_BUF_BLKS<<BLK_SIZE_BITS);39 if (attr1 & RS_ATTR_CONTIGUOUS)40 in_file=FOpen(f1,"rc");41 else42 in_file=FOpen(f1,"r");43 if (in_file) {44 size=FSize(in_file);45 cnt=(size+BLK_SIZE-1)>>BLK_SIZE_BITS;46 if (attr2 & RS_ATTR_CONTIGUOUS)47 out_file=FOpen(f2,"wc",cnt);48 else49 out_file=FOpen(f2,"w",cnt);50 if (out_file) {51 "Copying %s to %s\n",f1,f2;52 j=size;53 while (cnt>0) {54 if (cnt>COPY_BUF_BLKS) {55 n=COPY_BUF_BLKS;56 i=n<<BLK_SIZE_BITS;57 } else {58 n=cnt;59 i=j;60 }61 FBlkRead(in_file, buf,FFB_NEXT_BLK,n);62 FBlkWrite(out_file,buf,FFB_NEXT_BLK,n);63 cnt-=n;64 j-=n<<BLK_SIZE_BITS;65 }66 out_file->flags|=FF_USE_OLD_DATETIME;67 out_file->de.datetime=in_file->de.datetime;68 out_file->de.size=size;69 out_file->de.attr=FileAttr(f2,in_file->de.attr);70 FClose(out_file);71 FClose(in_file);72 Free(buf);73 return TRUE;74 } else75 PrintErr("File not found: \"%s\".\n",f2);76 FClose(in_file);77 } else78 PrintErr("File not found: \"%s\".\n",f1);79 Free(buf);80 return FALSE;81}82 83I64 Del(U8 *files_find_mask,Bool make_mask=FALSE,84 Bool del_dir=FALSE,Bool print_msg=TRUE)85{//Delete files.86 I64 res=0;87 CDirContext *dirc;88 if (dirc=DirContextNew(files_find_mask,make_mask)) {89 switch (dirc->dv->fs_type) {90 case FSt_REDSEA:91 res=RedSeaFilesDel(dirc->dv,Fs->cur_dir,dirc->mask,92 0,del_dir,print_msg);93 break;94 case FSt_FAT32:95 res=FAT32FilesDel(dirc->dv,Fs->cur_dir,dirc->mask,96 0,del_dir,print_msg);97 break;98 case FSt_ISO9660:99 PrintErr("Not Writable\n");100 break;101 default:102 PrintErr("File System Not Supported\n");103 }104 DirContextDel(dirc);105 }106 return res;107}108 