#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#define LISTFILE "file.lst"
#define INIFILE "setup.ini"
void *GetFilePath(char *Fullpath,char *filepath,char *filename)
{
int flag = 0;
int tmplen = 0;
char *p = Fullpath;
char *fp = filepath;
char *fn = filename;
char tmpbuf[128] = {0};
char *tb = tmpbuf;
while(*p != NULL)
{
if(*p != '/')
{
*tb++ = *p++;
}
else
{
if(!strcmp(tmpbuf,"release"))
{
flag = 1;
}
if(flag == 1)
{
tb = tmpbuf;
while(*tb != 0x00)
*fp++ = *tb++;
*fp++ = '\\';//*fp++ = '\\';
}
memset(tmpbuf,0,128);
*p++;
tb = tmpbuf;
}
}
tb = tmpbuf;
while(*tb != 0x00 && *tb != '\n')
*fn++ = *tb++;
tmplen = strlen(tmpbuf);
fp -= 2;
*fp++ = 0x00; *fp = 0x00;
return ;
}
void *GetFileURL(char *Fullpath,char *filepath)
{
int flag = 0;
char *p = Fullpath;
char *fp = filepath;
char tmpbuf[128] = {0};
char *tb = tmpbuf;
flag = 0;
while(*p != NULL)
{
if(*p != ' ')
{
*tb++ = *p++;
}
else
{
flag++;
if(flag == 2)
{
tb = tmpbuf;
while(*tb != 0x00)
*fp++ = *tb++;
return ;
}
memset(tmpbuf,0,128);
*p++;
tb = tmpbuf;
}
}
return ;
}
void CreateList(char *url)
{
int rv;
FILE *fpin,*fpout;
char Fullpath[255] = {0};
char filepath[255] = {0};
char urlstr[512] = {0};
if((fpin = fopen(INIFILE,"r")) == NULL)
{
printf("INI file is not Exist !\n");
return -1;
}
if((fpout = fopen(LISTFILE,"w")) == NULL)
{
printf("List file is not Create!\n");
return -1;
}
while(!feof(fpin))
{
memset(Fullpath,0,255);
fgets(Fullpath,255,fpin);
if(memcmp(Fullpath,"install:",8))
{
continue;
}
memset(filepath,0,255);
memset(urlstr,0,255);
GetFileURL(Fullpath,filepath);
sprintf(urlstr,"%s%s\n",url,filepath);
fputs(urlstr,fpout);
}
fclose(fpin);
fclose(fpout);
printf("OK..\n");
}
void ChangeDir()
{
int rv;
FILE *fp;
char curDir[255] = {0},Fullpath[255] = {0};
char filepath[255] = {0},filename[255] = {0};
char cmd[512] = {0};
char newfile[512] = {0};
GetCurrentDirectory(255,curDir);
if((fp = fopen(LISTFILE,"r")) == NULL)
{
printf("List file is not Exist !\n");
return -1;
}
while(!feof(fp))
{
memset(Fullpath,0,255);
memset(filepath,0,255);
memset(filename,0,255);
fgets(Fullpath,255,fp);
GetFilePath(Fullpath,filepath,filename);
sprintf(cmd,"mkdir %s\\%s",curDir,filepath);
system(cmd);
//sprintf(cmd,"%s\\%s",curDir,filename);
//sprintf(newfile,"%s\\%s\\%s",curDir,filepath,filename);
//MoveFile(cmd,newfile);
sprintf(cmd,"move %s\\%s %s\\%s\\%s",curDir,filename,curDir,filepath,filename);
system(cmd);
}
fclose(fp);
printf("OK..\n");
}
int main(int args,char *argv[])
{
char url[128] = {0};
if (args != 1)
{
//添加变量处理
argv++;
if(!memcmp(*argv,"-f",2))
{
if(args != 3)
{
printf("cygLoad [-f 下载点url]: create file.lst\n [-d]: change Dir of download file by file.lst\n");
return ;
}
argv++;
strcpy(url,*argv);
CreateList(url);
}
else if(!memcmp(*argv,"-d",2))
{
ChangeDir();
}
else
{
printf("cygLoad [-f 下载点url]: create file.lst\n [-d]: change Dir of download file by file.lst\n");
}
}
else
printf("cygLoad [-f]: create file.lst\n [-d]: change Dir of download file by file.lst\n");
}
评论0