Dump csv async

Skip Sprite column completely
This commit is contained in:
Kurt 2021-01-16 17:25:55 -08:00
parent 03ae3d470c
commit c31285fd6d

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using PKHeX.Core; using PKHeX.Core;
using PKHeX.Drawing; using PKHeX.Drawing;
@ -96,7 +96,7 @@ namespace PKHeX.WinForms
dgData.Rows[i].Height = height; dgData.Rows[i].Height = height;
} }
private void PromptSaveCSV(object sender, FormClosingEventArgs e) private async void PromptSaveCSV(object sender, FormClosingEventArgs e)
{ {
if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgReportExportCSV) != DialogResult.Yes) if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgReportExportCSV) != DialogResult.Yes)
return; return;
@ -106,20 +106,19 @@ namespace PKHeX.WinForms
FileName = "Box Data Dump.csv" FileName = "Box Data Dump.csv"
}; };
if (savecsv.ShowDialog() == DialogResult.OK) if (savecsv.ShowDialog() == DialogResult.OK)
Export_CSV(savecsv.FileName); await Export_CSV(savecsv.FileName).ConfigureAwait(false);
} }
private void Export_CSV(string path) private async Task Export_CSV(string path)
{ {
var sb = new StringBuilder(); using var fs = new FileStream(path, FileMode.Create);
using var s = new StreamWriter(fs);
var headers = dgData.Columns.Cast<DataGridViewColumn>(); var headers = dgData.Columns.Cast<DataGridViewColumn>();
sb.AppendLine(string.Join(",", headers.Select(column => $"\"{column.HeaderText}\""))); await s.WriteLineAsync(string.Join(",", headers.Skip(1).Select(column => $"\"{column.HeaderText}\""))).ConfigureAwait(false);
foreach (var cells in from DataGridViewRow row in dgData.Rows select row.Cells.Cast<DataGridViewCell>()) foreach (var cells in from DataGridViewRow row in dgData.Rows select row.Cells.Cast<DataGridViewCell>())
sb.AppendLine(string.Join(",", cells.Select(cell => $"\"{cell.Value}\""))); await s.WriteLineAsync(string.Join(",", cells.Skip(1).Select(cell => $"\"{cell.Value}\""))).ConfigureAwait(false);
File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
} }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) protected override bool ProcessCmdKey(ref Message msg, Keys keyData)