wyUpdate.Common.WriteFiles.WriteDeprecatedString C# (CSharp) Method

WriteDeprecatedString() public static method

public static WriteDeprecatedString ( Stream fs, byte flag, string text ) : void
fs Stream
flag byte
text string
return void
        public static void WriteDeprecatedString(Stream fs, byte flag, string text)
        {
            if (text == null)
                text = String.Empty;//fill with an empty string

            //the string data to be written
            byte[] tempBytes = Encoding.UTF8.GetBytes(text);

            //the byte-length of the string.
            //(Previously I used the string-length, this caused problems for non-bytelong characters)
            byte[] tempLength = BitConverter.GetBytes(tempBytes.Length);

            //write the flag (e.g. 0x01, 0xFF, etc.)
            fs.WriteByte(flag);

            //FIX: I'm storing both the size of the bytes *Twice*. It's stupid.

            //write the size of the data
            fs.Write(BitConverter.GetBytes(tempBytes.Length + 4), 0, 4);

            //write the string data
            fs.Write(tempLength, 0, 4);
            fs.Write(tempBytes, 0, tempBytes.Length);
        }

Usage Example

Ejemplo n.º 1
0
        public void WriteToStream(Stream fs, bool embedBinaryData)
        {
            fs.WriteByte(142);
            WriteFiles.WriteInt(fs, 1, (int)RegOperation);
            WriteFiles.WriteInt(fs, 2, (int)RegBasekey);
            WriteFiles.WriteInt(fs, 3, (int)RegValueKind);
            WriteFiles.WriteDeprecatedString(fs, 4, SubKey);
            if (!string.IsNullOrEmpty(ValueName))
            {
                WriteFiles.WriteDeprecatedString(fs, 5, ValueName);
            }
            bool flag = !embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string;

            if (flag)
            {
                fs.WriteByte(128);
            }
            if (RegOperation == RegOperations.CreateValue)
            {
                switch (RegValueKind)
                {
                case RegistryValueKind.Binary:
                    if (flag)
                    {
                        WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData);
                    }
                    else if (embedBinaryData && RegValueKind == RegistryValueKind.Binary && ValueData is string)
                    {
                        WriteOutFile(fs, 7, (string)ValueData);
                    }
                    else
                    {
                        WriteFiles.WriteByteArray(fs, 7, (byte[])ValueData);
                    }
                    break;

                case RegistryValueKind.DWord:
                    WriteFiles.WriteInt(fs, 7, (int)ValueData);
                    break;

                case RegistryValueKind.QWord:
                    WriteFiles.WriteLong(fs, 7, (long)ValueData);
                    break;

                case RegistryValueKind.MultiString:
                    WriteFiles.WriteDeprecatedString(fs, 7, MultiStringToString(ValueData));
                    break;

                case RegistryValueKind.String:
                case RegistryValueKind.ExpandString:
                    WriteFiles.WriteDeprecatedString(fs, 7, (string)ValueData);
                    break;
                }
            }
            if (Is32BitKey)
            {
                fs.WriteByte(129);
            }
            fs.WriteByte(158);
        }
All Usage Examples Of wyUpdate.Common.WriteFiles::WriteDeprecatedString