setup.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:3k
- #include "stdafx.h"
- #include "windows.h"
- #include "setup.h"
- setup::setup()
- {
- int i;
- i = GetSystemDirectory(SysPath, 256);
- SysPath[i]=0;
- GetModuleFileName(0,AppPath,256);
- for(i=strlen(AppPath)-1;i>=0;i--)
- if(AppPath[i]=='\')
- {
- AppPath[i]=0;
- break;
- }
- }
- setup::~setup()
- {
- ;
- }
- int setup::FileCopyBAT(char* Path1, char*Path2,char*batFile)
- {
- FILE *infp;
- char buf[1000];
- char copy1[1000],copy2[1000],*pp ;
- infp=fopen(batFile, "rb"); //打开文字文件只读
- if(infp!=NULL)
- {
- while(!feof(infp))
- {
- fReadLine(buf,infp);
- pp=MyCutStr(buf," ");
- if(*pp!=0)
- {
- sprintf(copy1,"%s\%s", Path1,pp);
- sprintf(copy2,"%s\%s", Path2,buf);
- CopyFile(copy1,copy2,0);
- // if(!FileExists(copy2))
- // MessageBox(0,"CopyFile函数打开文件失败",copy2,0);
- }
-
- }
- fclose(infp);
- }
- return 0;
- }
- char*setup:: MyCutStr(char* ss, char*CutChar)
- {
- //用给定的字符串把字符串切成两半,并半部返回,后半部放入第一个参数中
- int i=0 ;
- char *p;
- while(1)
- {
- if(ss[i]==0||ss[i]==CutChar[0])
- {
- p=&ss[i];
- if(ss[i]==CutChar[0])
- {
- while(*p==CutChar[0])
- p++;
- ss[i]=0;
- }
- break;
- }
- i++;
- }
- return p;
- }
- bool setup::fReadLine(char *buf, FILE *fp)
- {
- char c;
- int i=0;
- buf[0]=0;
- //得到第一个有效字符
- while(!feof(fp))
- {
- c=getc(fp);
- if(!(13==c||10==c))
- break;
- }
- while(!feof(fp))
- {
- buf[i]=c;
- i++;
- c=getc(fp);
- if(13==c||10==c)
- {
- buf[i]=0;
- break;
- }
- }
- return 1;
- }
- bool setup:: DirExists(const char *dir)
- {
- bool tf;
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(dir, &fd);
- if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- tf = true;
- }
- else
- {
- tf = false;
- }
- FindClose(hFind);
- return tf;
- }
- //判断文件是否存在
- BOOL setup:: FileExists(const char *dir)
- {
- BOOL tf;
- WIN32_FIND_DATA fd;
- HANDLE hFind = FindFirstFile(dir, &fd);
- if (hFind !=INVALID_HANDLE_VALUE)
- {
- tf = TRUE;
- }
- else
- {
- tf = FALSE;
- }
- FindClose(hFind);
- return tf;
- }
- BOOL setup::copypathfile(char *path1){
- copypathfile(AppPath,path1);
- return 0;
- }
- BOOL setup::copypathfile(char *path1,char *path2){
- BOOL tf,bFound;
- WIN32_FIND_DATA fd;
- char copy1[1000],copy2[1000] ;
- HANDLE hFind ;
- if(!DirExists(path2))//没有工作目录就建一个
- {
- //MessageBox(0,"没有工作目录就建一个","错误",0);
- CreateDirectory(path2,0);
- }
- sprintf(copy1,"%s\*",path1);
- hFind = FindFirstFile(copy1, &fd);
- //MessageBox(0,copy1,copy1,0);
- if (hFind !=INVALID_HANDLE_VALUE) {
- bFound = FindNextFile(hFind,&fd);
- while(bFound)
- {
- if(strcmp(fd.cFileName,".")!=0 && strcmp(fd.cFileName,"..")!=0){
- sprintf(copy1,"%s\%s", path1,fd.cFileName);
- sprintf(copy2,"%s\%s", path2,fd.cFileName);
- if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
- copypathfile(copy1,copy2);
- }else
- CopyFile(copy1,copy2,0);
- }
- bFound = FindNextFile(hFind,&fd);
- }
- }
- return 0;
- }