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

📄 divide.cpp

📁 这是我自己写的wince程序
💻 CPP
字号:
#include "Stdafx.h"
#include "divide.h"
#include "string.h"


int scale(char* fullpath,long iiii,HWND hWnd)//按大小分
{
	FILE *file,*source;
	char* ch = fullpath;
	TCHAR del[100];//用来删除子文件
	MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,fullpath,-1,del,sizeof(del));
	
	int n=0;
	int i=0;
	float w;
	double e=0;
	int y=0,count=2,x,t,b;  
	char a;
	char ah[100],k[]="001",d[]="000";
	int ii=0,kk=0;

	char chch[20];

	source = fopen(fullpath,"rb");/////////////////////////////////////////////

	kk=strlen(ch);
	for(ii=kk-1;ii>=0;ii--)
		if(ch[ii]=='\\')break;
	for(i=0;ii < kk ;ii++,i++)
		ch[i]=ch[ii+1];
	ch[i]=0;
	strcpy(chch,ch);

	w = (float)iiii;

	a=fgetc(source);
	while(!feof(source))
	{
		e++;
		a=fgetc(source);
	}

	fclose(source);
	source = fopen(fullpath,"rb");
	b=(int)(e/w);
	b++;

	d[0]=b/100+48;
	d[1]=(b/10)%10+48;
	d[2]=b%10+48;
	i = 0;
	while(ch[i]!='.')
	{
		ah[i]=ch[i];
		i++;
	}
	x=t=i;//t为.前字符个数
	ah[i]='0';
	ah[i+1]='0';
	ah[i+2]='1';
	ah[i+4]='l';
	ah[i+5]='q';
	ah[i+6]='h';
	ah[i+7]='\0';
	ah[i+3]='.';

	a=fgetc(source);
	while(!feof(source))
	{
		file = fopen(ah,"wb");
		fwrite(chch,20,1,file);//将源文件名打入
		fputs("(part",file);
		fputc(k[0],file);
		fputc(k[1],file);
		fputc(k[2],file);
		fputc(d[0],file);
		fputc(d[1],file);
		fputc(d[2],file);
		fputc(')',file);

		if(b != 1)
		{
			for(n=0;n<w;n++)
			{
				if(!feof(source))
				{
					fputc(a,file);
					a=fgetc(source);
				}
			}
		}
		else
		{
			if(!feof(source))
			{
				fputc(a,file);
				a=fgetc(source);
			}
		}
		fclose(file);
		k[0]=ah[x]=count/100+48;
		k[1]=ah[x+1]=(count%100)/10+48;
		k[2]=ah[x+2]=count%10+48;
		count++;
		-- b;
	}
	i++;
	ch[i++]='e';ch[i++]='x';ch[i++]='e';ch[i]=0;

	fclose(file);
	fclose(source);
	int tt = ::MessageBox(hWnd,L"Divide successfully,Do you want to delete the original file?",L"Message",MB_YESNO);
	if(tt == IDYES)//
		DeleteFile(del);

	return 1;
}

/////////////////////////////////////////////////////
//void num:将文件以块数分开
//k,ah与scale中的用处相同
//b跟在k之后,显示共分出几个子文件
//n为文件分成的个数
//d为每块字节数

int num(char* fullpath,long iiii,HWND hWnd)//块数分  iiii块数
{
	TCHAR del[100];
	MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,fullpath,-1,del,sizeof(del));
	FILE *file,*source;
	char a,k[]="001",ah[100],b[]="000";
	int j=0,m,t,i=0;
	int n,x;
	int y=0,count=2;
	double d,w=0;
	int kk,ii;
	char chch[20];
	char* ch = fullpath;
	kk=strlen(ch);
	for(ii=kk-1;ii>=0;ii--)
		if(ch[ii]=='\\')break;
	for(i=0;ii < kk ;ii++,i++)
		ch[i]=ch[ii+1];
	ch[i]=0;
	strcpy(chch,ch);
	i=0;
	while(ch[i]!='.')
	{
		ah[i]=ch[i];
		i++;
	}
	x=t=i;//t为.前字符个数
	ah[t]='0';
	ah[t+1]='0';
	ah[t+2]='1';
	ah[t+3]='.';
	ah[t+4]='l';
	ah[t+5]='q';
	ah[t+6]='h';
	ah[t+7]='\0';

	n = iiii;
	b[0]=n/100+48;
	b[1]=(n/10)%10+48;
	b[2]=n%10+48;

	source = fopen(fullpath,"rb");
	a=fgetc(source);
	while(!feof(source))
	{
		w++;//字节长度
		a=fgetc(source);
	}

	fclose(source);
	source = fopen(fullpath,"rb");
	d=w/n;//每块字节数
	for(j=0;j<n;j++)
	{

		file = fopen(ah,"wb");
		fwrite(chch,20,1,file);//将源文件名打入
		fputs("(part",file);
		fputc(k[0],file);
		fputc(k[1],file);
		fputc(k[2],file);
		fputc(b[0],file);
		fputc(b[1],file);
		fputc(b[2],file);
		fputc(')',file);
		if(j==0)
		{
			a=fgetc(source);
		}
		if(j!=n-1)
		{
			for(m=0;m<d;m++)
			{
				if(!feof(source))
				{
					fputc(a,file);
					a=fgetc(source);
				}
			}
		}
		if(j==n-1)
		{
			while(!feof(source))
			{
				fputc(a,file);
				a=fgetc(source);
			}
		}
		fclose(file);
		ah[x]=count/100+48;
		ah[x+1]=(count%100)/10+48;
		ah[x+2]=count%10+48;
		k[0]=count/100+48;
		k[1]=(count%100)/10+48;
		k[2]=count%10+48;
		count++;
	}
	i++;
	ch[i++]='e';ch[i++]='x';ch[i++]='e';ch[i]=0;

	fclose(source);
	int tt = ::MessageBox(hWnd,L"Divide successfully,Do you want to delete the original file?",L"help",MB_YESNO);
	if(tt == IDYES)//
		DeleteFile(del);
	return 1;
}



void combine(char ch[100],HWND hWnd)
{
	int tt;
	char ah[100];//ah为子文件名
	char d[14],c,sign[]="(part001000)",z[]="000";
	FILE *fp,*mother;
	int n=0,i=0,k=2,t=0,x,b=0,a=0,y,g=0;
	char chch[20];//存放源文件名
	int len,czi;
	len=strlen(ch);
	for(czi=len-1;czi!=0;czi--)
		if(ch[czi]=='.') break;
	if(czi != 0)                     //有后缀名,检查是否是.lqh
		if(ch[czi+1]=='l'&&ch[czi+2]=='q'&&ch[czi+3]=='h')
		{
			if(ch[czi-1]<='9'&&ch[czi-1]>='0'&&ch[czi-2]<='9'&&ch[czi-2]>='0'&&ch[czi-3]<='9'&&ch[czi-3]>='0')  //有加001等切后的标识符
				czi=czi-3;
			else         //肯定没有加001等切后的标识符
		        ;
		}
	i=0;
	while(i!=czi)
	{
		ah[i]=ch[i];
		i++;
	}
	x=t=i;//t为.前字符个数
	ah[i]='0';
	ah[i+1]='0';
	ah[i+2]='1';
	ah[i+3]='.';
	ah[i+4]='l';
	ah[i+5]='q';
	ah[i+6]='h';
	ah[i+7]='\0';
	char ghg[100];
	strcpy(ghg,ah);
	i=i+5;
//	fp=fopen(ah,"rb");
	
	while((fp=fopen(ah,"rb"))!=NULL)
	{
		fclose(fp);
		ah[t]=k/100+48;
		ah[t+1]=(k%100)/10+48;
		ah[t+2]=k%10+48;
		k++;
		n++;//子文件的个数
	}
	ch[i+1]='\0';
	ah[t]=ah[t+1]='0';
	ah[t+2]='1';
	k=2;
	for(t=0;t<n;t++)
	{
		i=2;
		mother=fopen(ah,"rb");
	
		fread(chch,20,1,mother);//将源文件名读入
		strcpy(ch,chch);//准备按源文件名合并
		if(t==0)
		{   
			tt = ::MessageBox(hWnd,L"do you want to delete the subfiles?",L"help",MB_YESNO);

			if(fopen(ch,"r") != NULL)
			{			
				::MessageBox(hWnd,L"the original file exists,we will cover it",L"hello",1);
			}
		    fp=fopen(ch,"wb");
		}
		fgets(d,13,mother);
		z[0]=d[8];
		z[1]=d[9];
		z[2]=d[10];
		y=(z[0]-48)*100+(z[1]-48)*10+(z[2]-48)*1;
		while(d[5]!=sign[5]||d[6]!=sign[6]||d[7]!=sign[7])
		{
			fclose(mother);
			ah[x]=i/100+48;
			ah[x+1]=(i%100)/10+48;
			ah[x+2]=i%10+48;
			if((mother=fopen(ah,"rb"))==NULL)
			{
				i++;
				ah[x]=i/100+48;
				ah[x+1]=(i%100)/10+48;
				ah[x+2]=i%10+48;
				getchar();
		//		reuse();
			}
			i++;
			fread(chch,20,1,mother);//将源文件名读入
			
			fgets(d,13,mother);
		}
		ah[x]='0';
		ah[x+1]='0';
		ah[x+2]='1';
		sign[5]=k/100+48;
		sign[6]=(k%100)/10+48;
		sign[7]=k%10+48;
		k++;
		c=fgetc(mother);
		a++;
		while(!feof(mother))
		{
			fputc(c,fp);
			c=fgetc(mother);
		}
		fclose(mother);	
		
	}
	fclose(fp);
	if(y != n)
	{
		::MessageBox(hWnd,L"some file is missed,only try...",L"error",1);
	}
	TCHAR del[100];
	int ghgh = 1;
	if(tt == 6)//删除文件
	{
		for(int kkk = 1; kkk <= n; ++ kkk)
		{
			ghg[x]=kkk/100+48;
			ghg[x+1]=(kkk%100)/10+48;
			ghg[x+2]=kkk%10+48; 
			MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,ghg,-1,del,sizeof(del));
			DeleteFile(del);
		}
	}
}

⌨️ 快捷键说明

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