Knowledge Base Nr: 00177 videotextcache.cpp - http://www.swe-kaiser.de

Downloads:

Win32: Cachen von langdauernden Vörgängen (Beispiel Videotextauswertung)

  
void CExtractvtDlg::DoGetTVProg(const char* lpszSender)
{
CStringArray arPage;

SYSTEMTIME now;
::GetSystemTime(&now);

CString strCacheFile;

strCacheFile.Format("c:\\temp\\vt%d.%d.%d%s.txt", now.wYear, now.wMonth, now.wDay, lpszSender);

int nAttr = ::GetFileAttributes(strCacheFile);
if (nAttr > 0)
{
FILE* fp = fopen(strCacheFile, "rt");
if (!fp)
{
ASSERT(FALSE);
return;
}

char szLine[500] = {0};
while (fgets(szLine, sizeof(szLine), fp) != NULL)
{
arPage.Add(szLine);
}

fclose(fp);
}
else
{
FILE* fp = fopen(strCacheFile, "wt");
if (!fp)
{
ASSERT(FALSE);
return;
}

CVideoTextSupport vtsupp;

int nFirstPage = 301;
int nLastPage = 304;
int nTimeout_ms = 60000;

int nErr = vtsupp.LoadPage(lpszSender, nFirstPage, nLastPage, arPage, false, nTimeout_ms);
if (nErr)
{
fclose(fp);
::DeleteFile(strCacheFile);

CString str;

str.Format("ERROR: LoadPage()=>%d", nErr);
arPage.Add(str);
}
else
{
for (int n=0; n<arPage.GetSize(); n++)
{
if (arPage[n][1] == ' ')
{
arPage.RemoveAt(n);
n--;
}
else
{
fprintf(fp, arPage[n]);
}
}

fclose(fp);
}
}

m_lb.ResetContent();
for (int n=0; n<arPage.GetSize()-1; n++)
{
CString strLine;

strLine.Format("%s\t%s\t%s\t%s"
, lpszSender
, (const char*)arPage[n].Mid(1, 6)
, (const char*)arPage[n+1].Mid(1, 6)
, (const char*)arPage[n].Mid(14, 23) );

m_lb.AddString(strLine);
}
}