Очень нужна функция, а С++ я не знаю
Заранее спасибо
Код:
bool __declspec(dllexport) _stdcall GenerateGuide(char* filename, bool extract)
{
FILETIME ft;
SYSTEMTIME st;
FILE *f1;
int f2,f3;
char name[5000];
// printf("JTV 3.0 TVGuide generator v3\n");
// error(argc<2,"Usage: guidegen.exe filename_without_extension [/extract]\n");
char sf1[100];sprintf(sf1,"%s.txt",filename);
char sf2[100];sprintf(sf2,"%s.ndx",filename);
char sf3[100];sprintf(sf3,"%s.pdt",filename);
if(!extract){
f1=fopen(sf1,"rt");error(!f1,"Can't open file .txt!\n");
f2=open(sf2,O_RDWR|O_BINARY|O_CREAT|O_TRUNC,_S_IWRITE|_S_IREAD);
f3=open(sf3,O_RDWR|O_BINARY|O_CREAT|O_TRUNC,_S_IWRITE|_S_IREAD);
error(f2<0 || f3<0,"Can't open file .ndx or .pdt!\n");
int nelem=0;
write(f2,&nelem,2);
char jtvsgn[]="JTV 3.x TV Program Data\x0a\x0a\x0a";
write(f3,jtvsgn,26);
int offset=0x1a;
while(7==
fscanf(f1,"%hd %hd %hd %hd %hd %hd %[^\n]",
&st.wDay,
&st.wMonth,
&st.wYear,
&st.wHour,
&st.wMinute,
&st.wDayOfWeek,
name
)){
st.wSecond=0;
st.wMilliseconds=0;
SystemTimeToFileTime(&st,&ft);
int tmp=0;
write(f2,&tmp,2);
write(f2,&ft,8);
write(f2,&offset,2);
int len=strlen(name);
write(f3,&len,2);
write(f3,name,len);
offset+=len+2;
nelem++;
}
lseek(f2,0,SEEK_SET);
write(f2,&nelem,2);
//printf(".ndx and .pdt files created success.\n");
}else{
error(!extract,"Incorrect option!\n");
f1=fopen(sf1,"wt");error(!f1,"Can't open file .txt!\n");
f2=open(sf2,_O_RDONLY|O_BINARY);
f3=open(sf3,_O_RDONLY|O_BINARY);
error(f2<0 || f3<0,"Can't open file .ndx or .pdt!\n");
int nelem=0;
error(read(f2,&nelem,2)<0,"Read error!\n");
for(int i=0;i<nelem;i++){
int tmp;
read(f2,&tmp,2);
read(f2,&ft,8);
FileTimeToSystemTime(&ft,&st);
fprintf(f1,"%d %d %d %d %d %d\n",
st.wDay,
st.wMonth,
st.wYear,
st.wHour,
st.wMinute,
st.wDayOfWeek?st.wDayOfWeek:7
);
long offset=0;
read(f2,&offset,2);
lseek(f3,offset,SEEK_SET);
int len=0;
read(f3,&len,2);
read(f3,name,len);name[len]=0;
fprintf(f1,"%s\n",name);
}
//printf(".txt file created success.\n");
}
fclose(f1);
close(f2);
close(f3);
return true;
}