Exemplo n.º 1
0
        private static string DecodeDesc(byte[] descBytes)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            sb.AppendLine("<root>");

            if (descBytes.Length < 4 ||
                descBytes[0] != 0x50 || descBytes[1] != 0x4b || descBytes[2] != 0x03 || descBytes[3] != 0x04)
            {
                string source = Encoding.UTF8.GetString(descBytes);
                int    curr   = 0;
                string fn;
                int    size;
                while (true)
                {
                    int pos = source.IndexOf("|", curr, StringComparison.Ordinal);
                    if (pos == -1)
                    {
                        break;
                    }
                    fn   = source.Substring(curr, pos - curr);
                    curr = pos + 1;
                    pos  = source.IndexOf("|", curr, StringComparison.Ordinal);
                    size = int.Parse(source.Substring(curr, pos - curr));
                    curr = pos + 1;
                    sb.Append(source.Substring(curr, size));
                    curr += size;
                }
            }
            else
            {
                ZipReader          zip   = new ZipReader(descBytes);
                ZipReader.ZipEntry entry = new ZipReader.ZipEntry();
                while (zip.GetNextEntry(entry))
                {
                    if (entry.isDirectory)
                    {
                        continue;
                    }

                    sb.Append(Encoding.UTF8.GetString(zip.GetEntryData(entry)));
                }
            }

            sb.AppendLine();
            sb.Append("</root>");
            return(sb.ToString());
        }