// WinXP Folder View State Manipulation Code

if ( g_bDisableWinXPBagNodesManip == FALSE )
{
	if ( dispidMember == DISPID_BEFORENAVIGATE2 ||
		( dispidMember == DISPID_NAVIGATECOMPLETE2 && m_bStoreBagNodeSettingsLater ) )
	{
		// reset the StoreBagNodeSettingsLater flag

		BOOL		bStoreBagNodeSettingsLater = m_bStoreBagNodeSettingsLater;

		m_bStoreBagNodeSettingsLater = FALSE;

		// try to get the bag node slot for this URL (Win XP only)

		if ( m_iWinXpBagNodeSlot != -1 )
			RetrieveBagNodeSettings( m_iWinXpBagNodeSlot );

		m_iWinXpBagNodeSlot = -1;

		if ( ::stricmp( csFolders.c_str(), (m_csBeforeNavigate2Url+"\\").substr( 0, csFolders.size() ).c_str() ) == 0 )
		{
			// get the view state from the registry

			if ( m_bWinXpFolderViewStateAcquired == FALSE )
			{
				m_bWinXpFolderViewStateAcquired = TRUE;

				m_pbColInfo = ::GetParamBinary( charstring( IMGDWNLREG_WINXPCOLINFO ), & m_ulColInfoSize );

				charstring		csSort = ::GetParam( charstring( IMGDWNLREG_WINXPSORT ) );
				charstring		csSortDir = ::GetParam( charstring( IMGDWNLREG_WINXPSORTDIR ) );
				charstring		csCol = ::GetParam( charstring( IMGDWNLREG_WINXPCOL ) );

				m_dwSort = csSort.empty() ? 0 : ::strtol( csSort.c_str(), NULL, 10 );
				m_dwSortDir = csSortDir.empty() ? 0 : ::strtol( csSortDir.c_str(), NULL, 10 );
				m_dwCol = csCol.empty() ? 0 : ::strtol( csCol.c_str(), NULL, 10 );

				if ( m_pbColInfo == NULL )
				{
					int		iOrdinal = GetColExtFirstColOrdinal();
					if ( iOrdinal != -1 )
					{
						BYTE		vbStream[] = {
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							0xFD, 0xDF, 0xDF, 0xFD, 0x0F, 0x00, 0x04, 0x00,
							0x20, 0x00, 0x10, 0x00, 0x28, 0x00, 0x3C, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
							0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
							0xFB, 0x00, 0x60, 0x00, 0xBE, 0x00, 0xF0, 0x00,
							0x00, 0x00, 0x00, 0x00,    0,    0,    0,    0,
							   0,    0,    0,    0,    0,    0,    0,    0,
							0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
							0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
						};

						*( (DWORD*)vbStream + 15 ) = iOrdinal + 0;
						*( (DWORD*)vbStream + 16 ) = iOrdinal + 1;
						*( (DWORD*)vbStream + 17 ) = iOrdinal + 2;

						m_ulColInfoSize = sizeof( vbStream );
						m_pbColInfo = (BYTE*) ::malloc( m_ulColInfoSize );
						::memcpy( m_pbColInfo, vbStream, m_ulColInfoSize );
					}
				}
			}

			// set the bag infos for this folder

			m_iWinXpBagNodeSlot = GetBagNodeSlot( m_csBeforeNavigate2Url );
			if ( m_iWinXpBagNodeSlot != -1 )
			{
				StoreBagNodeSettings( m_iWinXpBagNodeSlot );

				if ( bStoreBagNodeSettingsLater )
				{
					m_bSkipSaveViewStateHook = TRUE;
					m_pWebBrowser->Refresh();
					m_bSkipSaveViewStateHook = FALSE;
				}
			}
			else if ( dispidMember == DISPID_BEFORENAVIGATE2 )
				m_bStoreBagNodeSettingsLater = TRUE;
		}
	}
}
