Exemplo n.º 1
0
void CSimpleReport::LayoutSave(const char* id, const char* tag)
{
	CMemFile memFile;
	CArchive ar (&memFile,CArchive::store);
	SerializeState(ar);
	ar.Flush();
	DWORD nBytes = (DWORD)memFile.GetPosition();
	LPBYTE pData = memFile.Detach();
	AfxGetApp()->WriteProfileBinary(id, tag, pData, nBytes);
	ar.Close();
	memFile.Close();
	free(pData);
}
DWORD SupFileSubtitleProvider::ThreadProc()
{
    CFile f;
    if (!f.Open(m_fname, CFile::modeRead|CFile::typeBinary|CFile::shareDenyNone)) {
        return 1;
    }

    f.SeekToBegin();

    CMemFile sub;
    sub.SetLength(f.GetLength());
    sub.SeekToBegin();

    int len;
    BYTE buff[65536];
    while ((len = f.Read(buff, sizeof(buff))) > 0) {
        sub.Write(buff, len);
    }
    sub.SeekToBegin();

    WORD sync              = 0;
    USHORT size            = 0;
    REFERENCE_TIME rtStart = 0;

    CAutoLock cAutoLock(&m_csCritSec);
    while (sub.GetPosition() < (sub.GetLength() - 10)) {
        sync = (WORD)ReadByte(&sub, 2);
        if (sync == 'PG') {
            rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9));
            sub.Seek(4 + 1, CFile::current); // rtStop + Segment type
            size = ReadByte(&sub, 2) + 3;    // Segment size
            sub.Seek(-3, CFile::current);
            sub.Read(buff, size);
            m_pSub->ParseSample(buff, size, rtStart, 0);
        } else {
            break;
        }
    }

    sub.Close();

    return 0;
}
Exemplo n.º 3
0
//*********************************************************************************
static void openSnapshotTestSectrion()
{
    CTBSection xCurrentUser;
    xCurrentUser.Open(&CTBSection::tbRootSection, "CurrentUser");

    CTBSection xSnapshotTest;
    xSnapshotTest.Open(&xCurrentUser, "SnapshotTest", TBOPEN_MODE_SNAPSHOT);
    
    CString strName;
    DWORD dwType = 0;
    int nTop = 0;

    BOOL more = xSnapshotTest.GetFirstItem(strName, dwType);
    while(more)
    {
        TEST_VERIFY((dwType == TBVTYPE_LONGBINARY) == (strName == "Blob1"));
        TEST_VERIFY((dwType == TBVTYPE_SECTION) == (strName == "Section1"));

        if(dwType != TBVTYPE_LONGBINARY && dwType != TBVTYPE_SECTION)
        {
            CTBValue value;
            CString prefix;
            long index = 0;
            sscanf(strName, "%s %d", prefix.GetBuffer(10), &index);

            if(prefix == "Name")
            {
                if(nTop < index) nTop = index;
                TEST_VERIFY(dwType == TBVTYPE_TEXT);
                xSnapshotTest.GetValue(strName, &value);
                TEST_VERIFY(strcmp(value.m_pValue->data.text, "Name") == 0);
            }
            else if(prefix == "Age")
            {
                if(nTop < index) nTop = index;
                TEST_VERIFY(dwType == TBVTYPE_INTEGER);
                xSnapshotTest.GetValue(strName, &value);
                TEST_VERIFY(value.m_pValue->data.int32 == index);
            }
        }
        more = xSnapshotTest.GetNextItem(strName, dwType);
    }

    TEST_VERIFY(nTop == 199);

    CTBSection xSection1;
    xSection1.Open(&xSnapshotTest, "Section1");
    xSection1.Close();

    //--------------------------------------------------------------
    CMemFile memFile;
    xSnapshotTest.GetLongBinary("Blob1", &memFile);
    memFile.SeekToBegin();

    for(int i = 0; i < 64; ++i)
    {
        BYTE buff[1024] = {0};
        BYTE buff2[1024] = {0};

        memset(buff2, i, sizeof(buff2));
        memFile.Read(buff, sizeof(buff));

        TEST_VERIFY(memcmp(buff, buff2, 1024) == 0);
    }
    //--------------------------------------------------------------
    TEST_VERIFY(memFile.GetPosition() == memFile.GetLength());

    xSnapshotTest.Close();
}