private async void openFile(string fileName) { try { dynamic file = null; var dgv = new DataGridView(); // Display the hidden progressbar in the statusbar. pbProgress.Visible = true; // Determine what file type it is and cast to the appropriate type. switch (Path.GetExtension(fileName)) { case ".shn": if (Path.GetFileNameWithoutExtension(fileName).ToLower() == "questdata") { file = new QuestFile(fileName); Program.LoadedFiles.Add(file); Extensions.FileType = FileType.QuestFile; var mainTab = new TabPage("QuestFile"); var qTab = new TabPage("Quests"); var dTab = new TabPage("Dialouges"); mainTab.BackColor = Color.White; dTab.BackColor = Color.White; qTab.BackColor = Color.White; var tc = new TabControl(); tc.Dock = DockStyle.Fill; qTab.Padding = new Padding(0, 5, 0, 0); dTab.Padding = new Padding(0, 5, 0, 0); mainTab.Padding = new Padding(0, 5, 0, 0); tc.TabPages.Add(qTab); tc.TabPages.Add(dTab); mainTab.Controls.Add(tc); var qPanel = new QuestPanel(file); qPanel.Dock = DockStyle.Fill; qTab.BackColor = Color.White; qTab.Controls.Add(qPanel); tcFiles.TabPages.Add(mainTab); tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1; pbProgress.Visible = false; pbProgress.Value = 0; lblStatus.Text = "Ready"; updateFileInfo(); return; } file = new SHNFile(fileName); Extensions.FileType = FileType.SHNFile; break; case ".txt": file = new ShineFile(fileName); Extensions.FileType = FileType.ShineFile; break; default: throw new Exception("File type not supported"); } lblStatus.Text = "Reading " + Path.GetFileName(fileName); // Await the asynchronous Load method and display the reported progress in our progressbar. await Task.Run(() => file.Load(new Progress<int>(value => mainStatusStrip.Invoke(new MethodInvoker(() => { pbProgress.Value = value; })) ))); Program.LoadedFiles.Add(file); if (file.GetType() == typeof(SHNFile)) { dgv = new DataGridView(); dgv.Dock = DockStyle.Fill; dgv.BackgroundColor = Color.WhiteSmoke; dgv.DoubleBuffered(true); dgv.DataSource = file; dgv.CellEnter += File_CellEnter; var tab = new TabPage(file.TableName); file.RowChanged += new DataRowChangeEventHandler(File_RowChanged); tab.Controls.Add(dgv); tcFiles.TabPages.Add(tab); tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1; } else if (file.GetType() == typeof(ShineFile)) { var mainTab = new TabPage(file.DataSetName); var tcTables = new TabControl(); tcTables.Dock = DockStyle.Fill; tcTables.SelectedIndexChanged += new EventHandler((object s, EventArgs e) => { file.SelectedIndex = tcTables.SelectedIndex; }); mainTab.Controls.Add(tcTables); tcFiles.TabPages.Add(mainTab); mainTab.BackColor = Color.White; tcFiles.SelectedIndex = tcFiles.TabCount - 1; foreach (var table in file.Tables) { dgv = new DataGridView(); dgv.Dock = DockStyle.Fill; dgv.BackgroundColor = Color.WhiteSmoke; dgv.DoubleBuffered(true); dgv.DataSource = table; dgv.CellEnter += File_CellEnter; var tab = new TabPage(table.TableName); table.RowChanged += new DataRowChangeEventHandler(File_RowChanged); tab.Controls.Add(dgv); tcTables.TabPages.Add(tab); } } // Hide and reset the progressbar. pbProgress.Visible = false; pbProgress.Value = 0; lblStatus.Text = "Ready"; updateFileInfo(); } catch (Exception ex) { pbProgress.Visible = false; pbProgress.Value = 0; lblStatus.Text = "Ready"; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private async void createFile(IFile file) { try { var dgv = new DataGridView(); if (file.GetType() == typeof(QuestFile)) { file = file ?? new QuestFile(""); Program.LoadedFiles.Add(file); Extensions.FileType = FileType.QuestFile; var mainTab = new TabPage("QuestFile"); var qTab = new TabPage("Quests"); var dTab = new TabPage("Dialouges"); mainTab.BackColor = Color.White; dTab.BackColor = Color.White; qTab.BackColor = Color.White; var tc = new TabControl(); tc.Dock = DockStyle.Fill; qTab.Padding = new Padding(0, 5, 0, 0); dTab.Padding = new Padding(0, 5, 0, 0); mainTab.Padding = new Padding(0, 5, 0, 0); tc.TabPages.Add(qTab); tc.TabPages.Add(dTab); mainTab.Controls.Add(tc); var qPanel = new QuestPanel((QuestFile)file); qPanel.Dock = DockStyle.Fill; qTab.Controls.Add(qPanel); mainTab.Controls.Add(tc); tcFiles.TabPages.Add(mainTab); tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1; } else if (file.GetType() == typeof(SHNFile)) { dgv = new DataGridView(); dgv.Dock = DockStyle.Fill; dgv.BackgroundColor = Color.WhiteSmoke; dgv.DoubleBuffered(true); dgv.DataSource = file; ((SHNFile)file).CreateFile(); dgv.CellEnter += File_CellEnter; var tab = new TabPage(((DataTable)file).TableName); ((DataTable)file).RowChanged += new DataRowChangeEventHandler(File_RowChanged); tab.Controls.Add(dgv); tcFiles.TabPages.Add(tab); tcFiles.SelectedIndex = tcFiles.TabPages.Count - 1; } else if (file.GetType() == typeof(ShineFile)) { var mainTab = new TabPage(((ShineFile)file).DataSetName); var tcTables = new TabControl(); tcTables.Dock = DockStyle.Fill; tcTables.SelectedIndexChanged += new EventHandler((object s, EventArgs e) => { ((ShineFile)file).SelectedIndex = tcTables.SelectedIndex; }); mainTab.Controls.Add(tcTables); tcFiles.TabPages.Add(mainTab); mainTab.BackColor = Color.White; tcFiles.SelectedIndex = tcFiles.TabCount - 1; foreach (var table in ((ShineFile)file).Tables) { dgv = new DataGridView(); dgv.Dock = DockStyle.Fill; dgv.BackgroundColor = Color.WhiteSmoke; dgv.DoubleBuffered(true); dgv.DataSource = table; dgv.CellEnter += File_CellEnter; var tab = new TabPage(((DataTable)table).TableName); ((DataTable)table).RowChanged += new DataRowChangeEventHandler(File_RowChanged); tab.Controls.Add(dgv); tcTables.TabPages.Add(tab); } } updateFileInfo(); } catch (Exception ex) { pbProgress.Visible = false; pbProgress.Value = 0; lblStatus.Text = "Ready"; MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }