Пример #1
0
        public void Mount(string addonPath)
        {
            using (BinaryReader reader = new BinaryReader(File.Open(addonPath, FileMode.Open), Encoding.ASCII))
            {
                int p = 0;
                if (reader.ReadUInt32() != magic)
                {
                    throw new InvalidDataException("File is corrupt.");
                }

                reader.ReadLongString();
                reader.ReadLongString();
                reader.ReadLongString();

                if (reader.ReadBoolean()) // macros
                {
                    LoadMacroList(reader.ReadStringArray());
                }
                if (reader.ReadBoolean()) // globals
                {
                    LoadGlobalList(reader.ReadStringArray());
                }

                if (reader.ReadBoolean()) // outlines
                {
                    if (reader.ReadBoolean())
                    {
                        oIntros.AddRange(reader.ReadStringArray());
                    }
                    if (reader.ReadBoolean())
                    {
                        oBodies.AddRange(reader.ReadStringArray());
                    }
                    if (reader.ReadBoolean())
                    {
                        oEndings.AddRange(reader.ReadStringArray());
                    }
                }

                if (reader.ReadBoolean()) // vocab
                {
                    int c = reader.ReadInt32();

                    for(int i = 0; i < c; i++)
                    {
                        reader.ReadLongString(); // filename
                        int bufferLength = reader.ReadInt32(); // data length - skipping because we can just load right off the stream
                        int bufferEnd = bufferLength + (int)reader.BaseStream.Position;
                        var list = new WordList(reader, ref p);
                        reader.BaseStream.Position = bufferEnd;

                        if (wordBank.ContainsKey(list.Symbol))
                        {
                            wordBank[list.Symbol].Merge(list);
                        }
                        else
                        {
                            wordBank.Add(list.Symbol, list);
                        }
                    }
                }

                if (reader.ReadBoolean())
                {
                    int c = reader.ReadInt32();

                    for(int i = 0; i < c; i++)
                    {
                        reader.ReadLongString(); // dir name
                        char sc = reader.ReadChar();
                        string symbol = sc.ToString(); // symbol
                        string title = reader.ReadLongString(); // title

                        var list = new PatternList(title, sc, reader.ReadStringArray());

                        if (patternBank.ContainsKey(symbol))
                        {
                            patternBank[symbol].Merge(list);
                        }
                        else
                        {
                            patternBank.Add(symbol, list);
                        }
                    }
                }
            }
        }
Пример #2
0
        public bool Merge(WordList list)
        {
            if (list.Subtypes.Length != this.Subtypes.Length)
            {
                return false;
            }

            int o = this.Words.Length;
            int s = list.Words.Length + this.Words.Length;

            if (o == s)
            {
                return true;
            }

            Array.Resize<string[]>(ref this.Words, s);
            Array.Resize<int>(ref this.Weights, s);
            Array.Resize<int>(ref this.DistWeights, s);

            Array.Copy(list.Words, 0, this.Words, o, list.Words.Length);
            Array.Copy(list.Weights, 0, this.Weights, o, list.Weights.Length);
            Array.Copy(list.DistWeights, 0, this.DistWeights, o, list.DistWeights.Length);

            foreach(KeyValuePair<string, List<int>> pair in list.Classes)
            {
                if (this.Classes.ContainsKey(pair.Key))
                {
                    this.Classes[pair.Key].AddRange(pair.Value);
                }
                else
                {
                    this.Classes.Add(pair.Key, pair.Value);
                }
            }

            return true;
        }