Esempio n. 1
0
BOOL vmsDownloadsGroupsMgr::LoadFromDisk()
{
    fsString strFile = fsGetDataFilePath ("groups.sav");

    if (GetFileAttributes (strFile) == DWORD (-1))
    {
        fsDownloads_GroupsMgr grps;
        if (FALSE == grps.LoadGroups () || grps.GetCount () == 0)
        {
            CreateDefaultGroups ();
            return TRUE;
        }

        for (int i = 0; i < grps.GetCount (); i++)
        {
            fsDownloadGroup grp;
            grps.GetGroup (&grp, i);

            vmsDownloadsGroupSmartPtr grpNew;
            grpNew.CreateInstance ();
            grpNew->strName = grp.szName;
            grpNew->strOutFolder = grp.szOutFolder;
            grpNew->strExts = grp.szExts;
            grpNew->nId = grp.bOther ? GRP_OTHER_ID : m_nGrpNextId++;
            Add (grpNew, NULL, TRUE);
        }

        return TRUE;
    }



    HANDLE hFile = CreateFile (strFile, GENERIC_READ, FILE_SHARE_READ, NULL,
                               OPEN_EXISTING, 0, NULL);

    if (hFile != INVALID_HANDLE_VALUE)
    {
        vmsDownloadsGroupsFileHdr hdr;
        DWORD dw;
        if (ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL))
        {
            if (hdr.wVer == DLDSGRPSFILE_CURRENT_VERSION &&
                    lstrcmp (hdr.szSig,	DLDSGRPSFILE_SIG) == 0)
            {
                if (FALSE == ReadFile (hFile, &m_nGrpNextId, sizeof (UINT), &dw, NULL))
                    return FALSE;

                LoadGroupsTreeFromFile (hFile, m_tGroups);
            }
        }
        CloseHandle (hFile);
    }

    if (m_tGroups->GetLeafCount () == 0)
        CreateDefaultGroups ();

    return TRUE;
}
BOOL vmsDownloadsGroupsMgr::LoadFromDisk()
{
	fsString strFile = fsGetDataFilePath ("groups.sav");

	if (GetFileAttributes (strFile) == DWORD (-1))
	{	
		fsDownloads_GroupsMgr grps;
		if (FALSE == grps.LoadGroups () || grps.GetCount () == 0)
		{
			CreateDefaultGroups ();
			return TRUE;
		}

		for (int i = 0; i < grps.GetCount (); i++)
		{
			fsDownloadGroup grp;
			grps.GetGroup (&grp, i);

			vmsDownloadsGroupSmartPtr grpNew;
			grpNew.CreateInstance ();
			grpNew->strName = grp.szName;
			grpNew->strOutFolder = grp.szOutFolder;
			grpNew->strExts = grp.szExts;
			grpNew->nId = grp.bOther ? GRP_OTHER_ID : m_nGrpNextId++;
			Add (grpNew, NULL, TRUE);
		}

		return TRUE;
	}

	DWORD dwRequiredSize = 0;

	

	HANDLE hFile = CreateFile (strFile, GENERIC_READ, FILE_SHARE_READ, NULL, 
		OPEN_EXISTING, 0, NULL);
	
	if (hFile != INVALID_HANDLE_VALUE)
	{
		dwRequiredSize = ::GetFileSize(hFile, NULL);

		vmsDownloadsGroupsFileHdr hdr;
		DWORD dw;
		if (ReadFile (hFile, &hdr, sizeof (hdr), &dw, NULL))
		{
			if (hdr.wVer == DLDSGRPSFILE_CURRENT_VERSION && 
					lstrcmp (hdr.szSig,	DLDSGRPSFILE_SIG) == 0)
			{
				
				
				
				
				

				dwRequiredSize -= sizeof(hdr);
				if (dwRequiredSize <= 0) {
					CloseHandle (hFile);
					return FALSE;
				}

				std::auto_ptr<BYTE> pbtBufferGuard( new BYTE[dwRequiredSize] );
				LPBYTE pbtBuffer = pbtBufferGuard.get();
				if (pbtBuffer == 0) {
					CloseHandle (hFile);
					return FALSE;
				}
				memset(pbtBuffer, 0, dwRequiredSize);

				if (!ReadFile (hFile, pbtBuffer, dwRequiredSize, &dw, NULL) || dw != dwRequiredSize) {
					CloseHandle (hFile);
					return FALSE;
				}

				if (!loadFromStateBuffer(pbtBuffer, &dwRequiredSize, hdr.wVer)) {
					CloseHandle (hFile);
					return FALSE;
				}
			}
		}
		CloseHandle (hFile);
	}

	if (m_tGroups->GetLeafCount () == 0)
		CreateDefaultGroups ();

	return TRUE;
}