1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Add option to export BCSV as CSV

This commit is contained in:
KillzXGaming 2020-03-18 16:53:26 -04:00
parent f44b2ed920
commit 241833ca8f
2 changed files with 53 additions and 1 deletions

View File

@ -41,7 +41,10 @@ namespace FirstPlugin
public TextEditor OpenForm()
{
return new TextEditor();
var textEditor = new TextEditor();
textEditor.ClearContextMenus(new string[] { "Search" });
textEditor.AddContextMenu("Export as CSV", ExportCSV);
return textEditor;
}
public void FillEditor(UserControl control)
@ -74,6 +77,30 @@ namespace FirstPlugin
return strBuilder.ToString();
}
private void ExportCSV(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "CSV |*.csv;";
sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);
sfd.DefaultExt = ".csv";
if (sfd.ShowDialog() == DialogResult.OK)
System.IO.File.WriteAllText(sfd.FileName, ConvertToCSV());
}
public string ConvertToCSV()
{
StringBuilder strBuilder = new StringBuilder();
using (var textWriter = new System.IO.StringWriter(strBuilder))
{
var fields = BCVFile.Entries.FirstOrDefault().Fields;
textWriter.WriteLine($"{string.Join(",", fields.Keys)}");
for (int i = 0; i < BCVFile.Entries.Count; i++)
textWriter.WriteLine($"{string.Join(",", BCVFile.Entries[i].Fields.Values)}");
}
return strBuilder.ToString();
}
public void ConvertFromString(string text)
{
}

View File

@ -22,6 +22,17 @@ namespace FirstPlugin
public Dictionary<string, object> Fields;
}
static Dictionary<uint, string> hashes = new Dictionary<uint, string>();
public static Dictionary<uint, string> Hashes
{
get
{
// if (hashes.Count == 0)
//CalculateHashes();
return hashes;
}
}
public List<DataEntry> Entries = new List<DataEntry>();
public void Read(FileReader reader)
@ -90,6 +101,9 @@ namespace FirstPlugin
break;
}
if (Hashes.ContainsKey(fields[f].Hash))
name = Hashes[fields[f].Hash];
entry.Fields.Add(name, value);
}
@ -97,6 +111,12 @@ namespace FirstPlugin
}
}
private bool IsFloatValue(int value)
{
// Use a very dumb "algorithm" to check if the resulting integer would be "too long".
return value.ToString().Length > 6;
}
public enum DataType
{
Byte,
@ -111,5 +131,10 @@ namespace FirstPlugin
{
writer.Write(Entries.FirstOrDefault().Fields.Count);
}
private static void CalculateHashes()
{
}
}
}