Ejemplo n.º 1
0
        private void LoadFolder(object state)
        {
            _loadedTables.Clear();
            lbLoadedTables.Items.Clear();

            meLog.Text += $"Populating and loading tables in {_sourceFolder}" + Environment.NewLine;
            string[] files = Directory.GetFiles(_sourceFolder);
            foreach (string path in files)
            {
                FileInfo fi = new FileInfo(path);
                if (!fi.Exists || fi.Extension != ".tbl")
                {
                    continue;
                }

                DataTable        table      = null;
                KOEncryptionBase encryption = null;
                /* Try to decrypt file. */
                foreach (var encryptionMethod in StaticReference.EncryptionMethods)
                {
                    table = encryptionMethod.GetDataTableFromFile(path, fi.Name);
                    if (table == null)
                    {
                        continue;
                    }
                    encryption = encryptionMethod;
                    break;
                }

                if (table == null)
                {
                    lbLoadedTables.Items.Add($"{fi.Name} - Load failed.");
                }
                else
                {
                    lbLoadedTables.Items.Add($"{fi.Name} [{encryption.Name()}] - OK");
                    var newTable = new KOTableFile(fi, table, encryption);
                    _loadedTables.Add(path, newTable);
                }
            }
        }