예제 #1
0
        private void BuildCache(SRL Engine)
        {
            Log.Debug("Cache not found, Building database...");
            Engine.Databases            = new List <Database>();
            Engine.CurrentDatabaseIndex = 0;
            Engine.CharRemap            = new Dictionary <char, char>();

            if (!Directory.Exists(Engine.Settings.WorkingDirectory))
            {
                Directory.CreateDirectory(Engine.Settings.WorkingDirectory);
            }

            string[] SpecialLSTs = new string[] { "chars", "charsalt", "regex", "mtl" };

            foreach (string Lst in Directory.GetFiles(Engine.Settings.WorkingDirectory, "*.lst"))
            {
                var Parser = new LSTParser(Lst);

                if (SpecialLSTs.Contains(Parser.Name.ToLowerInvariant()))
                {
                    continue;
                }

                Database DB = new Database(Parser.Name);
                DB.AddRange(Parser.GetEntries());

                Log.Debug($"Database {Parser.Name} Initialized (ID: {Engine.Databases.Count})");
                Engine.Databases.Add(DB);
            }

            Engine.CharRemap    = LoadCharRemap(Path.Combine(Engine.Settings.WorkingDirectory, "Chars.lst"));
            Engine.CharRemapAlt = LoadCharRemap(Path.Combine(Engine.Settings.WorkingDirectory, "CharsAlt.lst"));


            Cache Builder = new Cache(Engine.Settings.CachePath);

            Builder.BuildDatabase(Engine.Databases.ToArray(), Engine.CharRemap.ToArray(), Engine.CharRemapAlt.ToArray());
        }
예제 #2
0
        private void BuildCache(SRL Engine)
        {
            Log.Debug("Cache not found, Building database...");
            Engine.Databases            = new List <Database>();
            Engine.CurrentDatabaseIndex = 0;
            Engine.CharRemap            = new Dictionary <char, char>();

            if (!Directory.Exists(Engine.Settings.WorkingDirectory))
            {
                Directory.CreateDirectory(Engine.Settings.WorkingDirectory);
            }

            string[] SpecialLSTs = new string[] { "chars", "regex", "mtl" };

            foreach (string Lst in Directory.GetFiles(Engine.Settings.WorkingDirectory, "*.lst"))
            {
                var Parser = new LSTParser(Lst);

                if (SpecialLSTs.Contains(Parser.Name.ToLowerInvariant()))
                {
                    continue;
                }

                Database DB = new Database(Parser.Name);
                DB.AddRange(Parser.GetEntries());

                Log.Debug($"Database {Parser.Name} Initialized (ID: {Engine.Databases.Count})");
                Engine.Databases.Add(DB);
            }

            string CharsFile = Path.Combine(Engine.Settings.WorkingDirectory, "Chars.lst");

            if (File.Exists(CharsFile))
            {
                foreach (string Line in File.ReadAllLines(CharsFile))
                {
                    if (!Line.Contains('=') || string.IsNullOrWhiteSpace(Line))
                    {
                        continue;
                    }

                    string PartA = Line.Substring(0, Line.IndexOf('='));
                    string PartB = Line.Substring(Line.IndexOf('=') + 1);

                    if (PartA.Length > 1)
                    {
                        PartA = PartA.Trim();
                    }
                    if (PartB.Length > 1)
                    {
                        PartB = PartB.Trim();
                    }

                    char A, B;

                    if (PartA.ToLowerInvariant().StartsWith("0x"))
                    {
                        PartA = PartA.Substring(2);
                        A     = (char)Convert.ToInt16(PartA, 16);
                    }
                    else
                    {
                        A = PartA.First();
                    }

                    if (PartB.ToLowerInvariant().StartsWith("0x"))
                    {
                        PartB = PartB.Substring(2);
                        B     = (char)Convert.ToInt16(PartB, 16);
                    }
                    else
                    {
                        B = PartB.First();
                    }

                    Log.Debug($"Character Remap from {A} to {B}");
                    Engine.CharRemap[A] = B;
                }
            }

            Cache Builder = new Cache(Engine.Settings.CachePath);

            Builder.BuildDatabase(Engine.Databases.ToArray(), Engine.CharRemap.ToArray());
        }