Exemple #1
0
        /// <summary>
        /// Validates and stores an indexed packet to the update storage file.
        /// </summary>
        /// <param name="packet">The packet data to be stored.</param>
        /// <returns>Returns true if successful, false otherwise.</returns>
        public bool AddPacket(MFUpdatePkt packet)
        {
            if (m_updateHandle == -1 || !m_authenticated)
            {
                throw new InvalidOperationException();
            }

            int pktIndex = packet.PacketIndex;

            if (pktIndex >= m_maxPkt)
            {
                throw new IndexOutOfRangeException();
            }
            if (packet.Data == null || packet.Data.Length > m_packetSize)
            {
                throw new ArgumentException();
            }

            int div = pktIndex >> 5;
            int rem = pktIndex % 32;

            // We already have this packet
            if (0 == (m_pktBitChk[div] & (1u << rem)))
            {
                return(true);
            }

            if (MFNativeUpdate.AddPacket(m_updateHandle, packet.PacketIndex, packet.Data, packet.ValidationData))
            {
                m_pktBitChk[pktIndex >> 5] &= ~(1u << (pktIndex % 32));

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Validates and stores an indexed packet to the update storage file.
        /// </summary>
        /// <param name="packet">The packet data to be stored.</param>
        /// <returns>Returns true if successful, false otherwise.</returns>
        public bool AddPacket(MFUpdatePkt packet)
        {
            if (m_updateHandle == -1 || !m_authenticated) throw new InvalidOperationException();

            int pktIndex = packet.PacketIndex;
            if (pktIndex >= m_maxPkt) throw new IndexOutOfRangeException();
            if (packet.Data == null || packet.Data.Length > m_packetSize) throw new ArgumentException();

            int div = pktIndex >> 5;
            int rem = pktIndex % 32;

            // We already have this packet
            if (0 == (m_pktBitChk[div] & (1u << rem))) return true;

            if (MFNativeUpdate.AddPacket(m_updateHandle, packet.PacketIndex, packet.Data, packet.ValidationData))
            {
                m_pktBitChk[pktIndex >> 5] &= ~(1u << (pktIndex % 32));
                
                return true;
            }

            return false;
        }