#include <allegro.h> #include <tdgui.h> char path[512]; char outname[1024]; long onetime=65536; // one block size static DIALOG the_dest[] = { /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */ { d_billwin_proc, 220, 210, 200, 70, 0, 0, 0, 0, 0, 0, "COPY FILE(S)"}, { d_billtext_proc, 230, 230, 0, 0, 0, 0, 0, 0, 0, 0, "Destination directory"}, { d_billedit_proc, 230, 240, 180, 12, 0, 0, 0, 0, 512, 0, path}, { d_billbutton_proc,230, 260, 80, 15, 0, 0, 0,D_EXIT, 0, 0, "OK"}, { d_billbutton_proc,330, 260, 80, 15, 0, 0, 0,D_EXIT, 0, 0, "Cancel"}, { NULL } //14 }; int cpy_dest() { char r; r=moveable_do_dialog(the_dest,-1); while(keypressed()==TRUE); clear_keybuf(); if(r==-1) return -1; if(r==4) return -1; r=strlen(path)-1; if(r<0) return -1; if(path[r]!='\\'&&path[r]!='/') strcat(path,"//"); if(get_config_int("copying","bits",32)==32) onetime=65536*16; else onetime=65536; return 0; } /* Return: -1 - error opening input file -2 - error creating file -3 - error reading input file -4 - error writing to file 0 - success 1 - destination file already exists */ int cpy_copy(char infile[256]) { char r=0; char *cpybuf; unsigned long l,n; PACKFILE *s,*f; strcpy(outname,path); strcat(outname,infile); text_mode(-1); show_mouse(0); tdbox1(screen,200,200,240,80,6); textout_centre(screen,font,"COPYING FILE",320,205,255); tdhline(screen,202,215,438); textout_centre(screen,font,infile,320,235,100); textout_centre(screen,font,infile,321,236,0); textout_centre(screen,font,"TO",320,245,100); textout_centre(screen,font,"TO",321,246,0); textout_centre(screen,font,outname,320,255,100); textout_centre(screen,font,outname,321,256,0); show_mouse(screen); if(file_exists(outname,0,0)!=0){ if(billalert("I have one question!","Destination file already exists.", "Overwrite?","&Yes","&No",'y','n')==2) return 1; } cpybuf=malloc(onetime); s=pack_fopen(infile,F_READ); if(s==0) return -1; l=file_size(infile); f=pack_fopen(outname,F_WRITE); if(f==0){ pack_fclose(s); return -2; } while(l!=0){ if(l>onetime) n=onetime; else n=l; if(pack_fread(cpybuf,n,s)==-1){ pack_fclose(s); pack_fclose(f); return -3; } if(pack_fwrite(cpybuf,n,f)==-2){ pack_fclose(s); pack_fclose(f); return -4; } l-=n; } pack_fclose(s); pack_fclose(f); free(cpybuf); return 0; }