Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Property"/> class.
        /// </summary>
        /// <param name="id">The property's ID.</param>
        /// <param name="src">The bytes the property Set stream consists of.</param>
        /// <param name="offset">The property's type/value pair's offset in the
        /// section.</param>
        /// <param name="Length">The property's type/value pair's Length in bytes.</param>
        /// <param name="codepage">The section's and thus the property's
        /// codepage. It is needed only when Reading string values</param>
        public Property(long id, byte[] src, long offset,
                        int Length, int codepage)
        {
            this.id = id;

            /*
             * ID 0 is a special case since it specifies a dictionary of
             * property IDs and property names.
             */
            if (id == 0)
            {
                value = ReadDictionary(src, offset, Length, codepage);
                return;
            }

            int o = (int)offset;

            type = LittleEndian.GetUInt(src, o);
            o   += LittleEndianConsts.INT_SIZE;

            try
            {
                value = VariantSupport.Read(src, o, Length, (int)type, codepage);
            }
            catch (UnsupportedVariantTypeException ex)
            {
                VariantSupport.WriteUnsupportedTypeMessage(ex);
                value = ex.Value;
            }
        }
Esempio n. 2
0
        /**
         * Writes an array of {@link Property} instances To an output stream
         * according To the Horrible Property  Format.
         *
         * @param out The stream To Write To
         * @param properties The array To Write To the stream
         * @param codepage The codepage number To use for writing strings
         * @exception IOException if an I/O error occurs
         * @throws UnsupportedVariantTypeException if HPSF does not support some
         *         variant type.
         */
        public static void WriteToStream(Stream out1,
                                         Property[] properties,
                                         int codepage)
        {
            /* If there are no properties don't Write anything. */
            if (properties == null)
            {
                return;
            }

            /* Write the property list. This is a list containing pairs of property
             * ID and offset into the stream. */
            for (int i = 0; i < properties.Length; i++)
            {
                Property p = properties[i];
                WriteUIntToStream(out1, (uint)p.ID);
                WriteUIntToStream(out1, (uint)p.Count);
            }

            /* Write the properties themselves. */
            for (int i = 0; i < properties.Length; i++)
            {
                Property p    = properties[i];
                long     type = p.Type;
                WriteUIntToStream(out1, (uint)type);
                VariantSupport.Write(out1, (int)type, p.Value, codepage);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Writes the property To an output stream.
        /// </summary>
        /// <param name="out1">The output stream To Write To.</param>
        /// <param name="codepage">The codepage To use for writing non-wide strings</param>
        /// <returns>the number of bytes written To the stream</returns>
        public int Write(Stream out1, int codepage)
        {
            int  length      = 0;
            long variantType = this.Type;

            /* Ensure that wide strings are written if the codepage is Unicode. */
            if (codepage == (int)Constants.CP_UNICODE && variantType == Variant.VT_LPSTR)
            {
                variantType = Variant.VT_LPWSTR;
            }

            length += TypeWriter.WriteUIntToStream(out1, (uint)variantType);
            length += VariantSupport.Write(out1, variantType, this.Value, codepage);
            return(length);
        }