Ejemplo n.º 1
0
 internal JStream(uint index, bool isBStream, PsbReader parent = null) : base(string.Empty)
 {
     this.index     = index;
     this.isBStream = isBStream;
     Reader         = parent;
     UpdateName();
 }
Ejemplo n.º 2
0
        public static void GenerateRangeUsageVisualization(TextWriter writer, PsbReader reader)
        {
            RangeUsageAnalyzer analyzer = new RangeUsageAnalyzer();

            foreach (var node in reader.GenerateNameNodes().Values)
            {
                RegularNameNode regularNode = node as RegularNameNode;
                if (regularNode != null)
                {
                    var regularChildren = regularNode.Children.Values.Where(x => x is RegularNameNode).OrderBy(x => x.Index);
                    if (regularChildren.Count() > 0)
                    {
                        var minIndex = regularChildren.First().Index;
                        var maxIndex = regularChildren.Last().Index;
                        analyzer.AddRange(node.Index, minIndex, maxIndex, false);
                    }

                    var terminator = regularNode.Children.Values.Where(x => x is TerminalNameNode).FirstOrDefault();
                    if (terminator != null)
                    {
                        analyzer.AddRange(node.Index, terminator.Index, terminator.Index, false);
                    }
                }
                else
                {
                    analyzer.AddRange(node.Index, node.Index, node.Index, true);
                }
            }

            analyzer.OrderNodes();
            analyzer.WriteVisualization(writer);
        }
Ejemplo n.º 3
0
        public static bool TestKeyNamesGeneration(TextWriter writer, PsbReader reader)
        {
            KeyNamesGenerator generator = new KeyNamesGenerator(
                new StandardKeyNamesEncoder()
            {
                OutputDebug = false
            }, false);
            var keyNames = reader.KeyNames;

            for (uint i = 0; i < keyNames.Count; ++i)
            {
                writer.WriteLine(keyNames[i]);
                generator.AddString(keyNames[i]);
            }
            generator.Generate();
            writer.WriteLine("--------");
            var keyNamesNew = new PsbReader.KeyNamesReader(generator.ValueOffsets, generator.Tree, generator.Tails);

            for (uint i = 0; i < keyNamesNew.Count; ++i)
            {
                writer.WriteLine(keyNamesNew[i]);
            }

            for (uint i = 0; i < keyNames.Count; ++i)
            {
                if (keyNamesNew[i] != keyNames[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        public static void GenerateNameRanges(TextWriter writer, PsbReader reader)
        {
            var nodes = reader.GenerateNameNodes();
            var root  = nodes[0];
            IndentedTextWriter indentedWriter = new IndentedTextWriter(writer);

            WriteRange(indentedWriter, root);
        }
Ejemplo n.º 5
0
        public static void GenerateNameGraphDot(TextWriter writer, PsbReader reader)
        {
            var nodes = reader.GenerateNameNodes();

            writer.WriteLine("digraph {");
            writer.WriteLine("node [shape=record]");
            writer.WriteLine("edge [dir=back]");
            foreach (var node in nodes.OrderBy(x => x.Key))
            {
                node.Value.WriteDot(writer);
            }
            writer.WriteLine("}");
        }
 public KeyNamesReader(PsbReader reader)
 {
     if (reader.Version == 1)
     {
         reader.stream.Seek(reader.keysOffsetsOffset, SeekOrigin.Begin);
         uint[] offsets = reader.ParseUIntArray();
         for (uint i = 0; i < offsets.Length; ++i)
         {
             reader.stream.Seek(reader.keysBlobOffset + offsets[i], SeekOrigin.Begin);
             cache.Add(i, reader.ReadStringZ());
         }
     }
     else
     {
         reader.stream.Seek(reader.keysBlobOffset, SeekOrigin.Begin);
         valueOffsets = reader.ParseUIntArray();
         tree         = reader.ParseUIntArray();
         tails        = reader.ParseUIntArray();
     }
 }
Ejemplo n.º 7
0
        public static bool TestSerializeDeserialize(JToken root, IPsbStreamSource streamSource, string psbOutPath, TextWriter jsonWriter, TextWriter debugWriter)
        {
            using (FileStream fs = File.Create(psbOutPath))
            {
                PsbWriter writer = new PsbWriter(root, streamSource)
                {
                    Version  = 4,
                    Optimize = true
                };
                writer.Write(fs);
                fs.Flush();

                fs.Seek(0, SeekOrigin.Begin);
                PsbReader reader = new PsbReader(fs, null, debugWriter);
                reader.Root.WriteTo(new JsonTextWriter(jsonWriter)
                {
                    Formatting = Formatting.Indented
                });

                return(new JTokenEqualityComparer().Equals(root, reader.Root));
            }
        }
Ejemplo n.º 8
0
        public static bool TestSerializeDeserialize(PsbReader reader, string psbOutPath, TextWriter jsonWriter, TextWriter debugWriter)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                PsbWriter writer = new PsbWriter(reader.Root, null)
                {
                    Version  = reader.Version,
                    Optimize = true
                };
                writer.Write(ms);

                File.WriteAllBytes(psbOutPath, ms.ToArray());

                ms.Seek(0, SeekOrigin.Begin);
                PsbReader      newReader = new PsbReader(ms, null, debugWriter);
                JsonTextWriter jtw       = new JsonTextWriter(jsonWriter)
                {
                    Formatting = Formatting.Indented
                };
                newReader.Root.WriteTo(jtw);
                return(new JTokenEqualityComparer().Equals(reader.Root, newReader.Root));
            }
        }