⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splitf.cpp

📁 绝好的文件分割器.
💻 CPP
字号:
#include<conio.h>
#include<fstream.h>
#include<dos.h>
#include<stdio.h>
#include<io.h>
#include<process.h>
#include<string.h>
#include<stdlib.h>

struct spltf
{ char ID[5];
  char f_name[14];
  unsigned int parts;
};
struct finf
{ char f_name[14];
  long int size;
};
spltf split;
finf fili;
void progress(int pt,int stat);
void textxy(int x1,int y1,char *t);
void intxy(int x1,int y1,long int t);
void rectangle(int x1,int y1,int x2,int y2);
void intext(char *t,char *&a);
void inint(char *t,long int &a);
void Cl();
void splitfl();
void combfl();
void fatalE(char *t);
void end()
{ 
  exit(1);
}
int mainmenu()
{ clrscr();
  textcolor(14);
  rectangle(1,1,79,3);
  textcolor(15);
  textxy(30,2,"File Splitter--MADE BY Yu Xin");
  textcolor(9);
  rectangle(1,5,79,20);
  textcolor(2);
  rectangle(1,21,79,25);
  textcolor(10);
  textxy(33,7,"MAIN MENU");
  textcolor(12);
  textxy(30,8,"1. Split a file");
  textxy(30,9,"2. Combine split files");
  textxy(30,10,"3. Exit");
  textcolor(10);
  textxy(14,18,"This program can help you splite or combile files.");
  textxy(14,20,"This program was made by Yu Xin using Turbo C++ 3.0");
  long int opt;
  progress(0,1);
  textcolor(15);
  do
  {inint("Enter option : ",opt);
  } while((opt<1)||(opt>3));
  Cl();
  switch(opt)
  { case 1: splitfl();break;
    case 2: combfl();break;
    default:break;
  }
  return(opt);
}

void main()
{ int r;
  do
  {r=mainmenu();}while(r!=3);
  end();
}

void textxy(int x1,int y1,char *t)
{ gotoxy(x1,y1);
  cprintf(t);
}
void intxy(int x1,int y1,long int t)
{ gotoxy(x1,y1);
  cout<<t;
}

void progress(int pt,int stat)
{ if(stat==1)
  { textcolor(1);
    for(int i=15;i<=65;i++)
    { gotoxy(i,4);
      putch(219);
    }
  }
  else
  { textcolor(4);
    for(int i=15;i<=pt/2;i++)
    { gotoxy(i,4);
      putch(219);
    }
  }

}
void rectangle(int x1,int y1,int x2,int y2)
{ gotoxy(x1,y1);
  putch(218);
  gotoxy(x2,y1);
  putch(191);
  gotoxy(x1,y2);
  putch(192);
  gotoxy(x2,y2);
  putch(217);
  for(int i=x1+1;i<x2;i++)
  { gotoxy(i,y1); putch(196);
    gotoxy(i,y2); putch(196);
  }
  for(i=y1+1;i<y2;i++)
  { gotoxy(x1,i); putch(179);
    gotoxy(x2,i); putch(179);
  }
}

void intext(char *t,char *&a)
{ window(2,22,78,24);
  clrscr();
  window(1,1,79,25);
  textxy(3,23,t);
  cin>>a;
}
void inint(char *t,long int &a)
{ window(2,22,78,24);
  clrscr();
  window(1,1,79,25);
  textcolor(10);
  textxy(3,23,t);
  cin>>a;
}
void Cl()
{ window(2,6,78,19);
  clrscr();
  window(1,1,80,25);
}

void splitfl()
{ textxy(2,7,"Splitting a file to 2 or more files....");
  char f[80];
   lab01:
   intext("Enter filename (with path): ",f);
   ifstream tfl(f,ios::in|ios::binary);
   if(!tfl) { textxy(2,8,"File not found !");goto lab01; }
  long int remain,size=0,parts,sz;
  int pr=0;
  unsigned char ch;
  while(!tfl.eof())
  { tfl.read((char*)&ch,1);
    size++;
  }
  tfl.close();
  ifstream infile(f,ios::in|ios::binary);
  size--;
  textxy(2,9,"Total Size : ");cout<<size<<" Bytes";
  remain=size;
  textxy(40,9,"Remaining size : ");cout<<remain<<" Bytes";
  lab03:
  inint("Enter number of parts : ",parts);
  if(parts<=0) {goto lab03;}
  char kf[14];
  textxy(2,10,"Total parts : ");cout<<parts;
  textxy(40,10,"Remaining parts : ");cout<<parts;
  textxy(2,12,"NOTE : Key file contains Imortant data");
  intext("Enter name of key file : ",kf);
  ofstream okf(kf,ios::out|ios::binary);
  if(!okf) {fatalE("File creation error !"); }
  strcpy(split.f_name,f);
  split.parts=parts;
  strcpy(split.ID,"SPCK");
  okf.write((char*)&split,sizeof(split));
  char f2[14];
  for(long int i=1;i<=parts,remain>0;i++)
  {
    textcolor(10);
    textxy(2,14,"File : ");intxy(9,14,i);
    intext("Enter file name (without path): ",f2);
    if(i!=parts)
    { lab04:
      inint("Enter size in bytes : ",sz);
      if(sz>remain) {goto lab04;}
    }
    else{sz=remain;}
    ofstream of(f2,ios::out|ios::binary);
    if(!(of||okf)) { fatalE("File creation error !"); }
    strcpy(fili.f_name,f2);
    fili.size=sz;
    okf.write((char*)&fili,sizeof(fili));
    long int zz=1;
    while((zz<=sz)&&(infile)&&(remain>0))
    { infile.read((char*)&ch,sizeof(ch));
      of.write((char*)&ch,sizeof(ch));
      pr=((float)(size-remain)/size)*100;
      progress(pr,2);
      remain--;zz++;
    }
    textcolor(15);
    of.close();
    Cl();
    textcolor(10);
    textxy(2,7,"Filename : ");textxy(13,7,f);
    textxy(2,8,"Total size : ");cout<<size<<" Bytes";
    textxy(40,8,"Remaining size : ");cout<<remain<<" Bytes";
    textxy(2,9,"Total parts : ");cout<<parts;
    textxy(40,9,"Remaining parts : ");cout<<parts-i;
    progress(0,1);
    textcolor(15);
  }
  okf.close();
  infile.close();
  Cl();
  textxy(2,9,"File split completed !");
  textxy(2,10,"Total files created : ");cout<<parts<<" +1";
  getch();

}
void combfl()
{ Cl();
  textxy(2,9,"Combine split files...");
  char kf[14];
  unsigned char ch;
  lab05:
  intext("Enter name of Key file : ",kf);
  textxy(2,10,"Combining.....");
  ifstream ikf(kf,ios::in|ios::binary);
  if(!ikf) { textxy(2,11,"File not found !!"); goto lab05;}
  else {textxy(2,11,"                      ");}
  ikf.read((char*)&split,sizeof(split));
  if(strcmp(split.ID,"SPCK")!=0) {textxy(2,11,"Invalid key !!"); ikf.close();}
  ofstream mf(split.f_name,ios::out|ios::binary);
  long int i=1;
  int pr;
  while(i<=split.parts)
  { ikf.read((char*)&fili,sizeof(fili));
    ifstream f1(fili.f_name,ios::in|ios::binary);
    if(!f1) { fatalE("File not found !!");}
    for(long int j=1;j<=fili.size;j++)
    { f1.read((char*)ch,1);
      mf.write((char*)ch,1);

    }
    f1.close();
    i++;
    progress((((float)i/split.parts)*100),1);
  }
  ikf.close();
  mf.close();
  progress(0,1);textcolor(15);
  textcolor(12);
  textxy(2,12,"Done !");
  getch();
  Cl();
}




void fatalE(char *t)
{ clrscr();
  cprintf(t);
  exit(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -