public KOTableFile(FileInfo fi, DataTable tbl, KOEncryptionBase encryption) { Trace.Assert(fi != null, "KOTableFile() - File information is null!"); Trace.Assert(tbl != null, "KOTableFile() - DataTable is null!"); Trace.Assert(encryption != null, "KOTable() - Encryption is null!"); FileInformation = fi; Table = tbl; Encryption = encryption; Name = FileInformation.Name; UnknownInteger = encryption.UnknownInteger; UnknownByte = encryption.UnknownByte; Padding = encryption.Padding; Altered = false; SavePath = FileInformation.DirectoryName + "\\" + Name; }
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); } } }
public void SetEncryption(KOEncryptionBase enc) { Encryption = enc; }
private void OpenFile(object ofileName) { string fileName = ofileName as string; var fi = new FileInfo(fileName); if (!fi.Exists) { ; StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileOpenError"), fileName)); return; } if (StaticReference.GetTableByFullName(fi.FullName) != null) { this.Invoke(new Action(() => { SwitchToTabpage(fi.FullName); })); return; } DataTable table = null; KOEncryptionBase encryption = null; /* Try to decrypt file. */ foreach (var encryptionMethod in StaticReference.EncryptionMethods) { table = encryptionMethod.GetDataTableFromFile(fileName, fi.Name); if (table == null) { continue; } encryption = encryptionMethod; break; } if (table == null) { this.Invoke(new Action(() => { StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileEncryptionError"), fi.Name)); return; })); return; } var newTable = new KOTableFile(fi, table, encryption); /* Otherwise, we've succeeded to open file */ StaticReference.AddNewTable(newTable); this.Invoke(new Action(() => { CreateNewTabPage(newTable.Name, newTable.FullName); var grid = GetTabPageGrid(newTable.FullName); grid.KeyPress += Grid_KeyPress; grid.MouseClick += Grid_MouseClick; Trace.Assert(grid != null, "OpenFile() - Grid is null!"); grid.BeginUpdate(); grid.DataSource = table; var view = grid.MainView as GridView; Trace.Assert(view != null, "OpenFile() - GridView is null!"); view.Tag = newTable.FullName; foreach (var v in _itemTableHeaders.Where(v => newTable.Name.ToLowerInvariant().Contains(v.Key))) { view.ColumnPanelRowHeight += 20; for (var i = 0; i < view.Columns.Count; i++) { if (i < v.Value.Length) { view.Columns[i].Caption = string.Format("{0}\n{1}\n{2}", v.Value[i], i, ColumnTypes.GetColumnTypeNameFromFullName(view.Columns[i].ColumnType.FullName)); } } } //view. foreach (GridColumn col in view.Columns) { col.AppearanceCell.Options.UseTextOptions = true; col.AppearanceHeader.Options.UseTextOptions = true; col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Center; col.AppearanceCell.TextOptions.VAlignment = VertAlignment.Center; col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; col.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center; col.MinWidth = col.ColumnType != typeof(string) ? 150 : 200; col.OptionsColumn.FixedWidth = true; } grid.Refresh(); grid.EndUpdate(); })); }