<commit_before>using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Forms;

using PlayOnline.Core;
using PlayOnline.FFXI;

namespace PlayOnline.Utils.FFXIDataBrowser {

  internal class CSVItemExporter : IItemExporter {

    private static CSVOptionDialog dlgOptions = null;

    public CSVItemExporter() {
      if (CSVItemExporter.dlgOptions == null)
	CSVItemExporter.dlgOptions = new CSVOptionDialog();
    }

    public void DoExport(FFXIItem[] Items) {
      if (CSVItemExporter.dlgOptions.ShowDialog() == DialogResult.OK) {
      StreamWriter CSVFile = new StreamWriter(CSVItemExporter.dlgOptions.FileName, false, CSVItemExporter.dlgOptions.Encoding);
      char TextQuote = '"';
      long Index = 0;
	foreach (FFXIItem I in Items) {
	FFXIItem.IItemInfo II = I.GetInfo(CSVItemExporter.dlgOptions.Language, CSVItemExporter.dlgOptions.Type);
	  if (Index == 0) {
	    CSVFile.Write("{0}{1}{0}", TextQuote, I18N.GetText("ColumnHeader:Index"));
	    foreach (ItemField IF in II.GetFields()) {
	      if (IF == ItemField.Description) {
	      string FieldName = new NamedEnum(IF).Name;
		CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, String.Format(I18N.GetText("ColumnHeader:DescriptionLineCount"), FieldName));
		for (byte i = 0; i < 6; ++i) // Max 6 lines - should be plenty
		  CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, String.Format(I18N.GetText("ColumnHeader:DescriptionLine"), FieldName, i + 1));
	      }
	      else
		CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, new NamedEnum(IF).Name);
	    }
	    CSVFile.WriteLine();
	  }
	  CSVFile.Write(++Index);
	  foreach (ItemField IF in II.GetFields()) {<commit_msg>Added constructor that takes a language & type. Get the list of fields to use in the export from the options dialog.<commit_after>using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Windows.Forms;

using PlayOnline.Core;
using PlayOnline.FFXI;

namespace PlayOnline.Utils.FFXIDataBrowser {

  internal class CSVItemExporter : IItemExporter {

    private static CSVOptionDialog dlgOptions = null;

    public CSVItemExporter() {
      if (CSVItemExporter.dlgOptions == null)
	CSVItemExporter.dlgOptions = new CSVOptionDialog();
    }

    public CSVItemExporter(ItemDataLanguage L, ItemDataType T) : this() {
      CSVItemExporter.dlgOptions.Language = L;
      CSVItemExporter.dlgOptions.Type     = T;
    }

    public void DoExport(FFXIItem[] Items) {
      if (CSVItemExporter.dlgOptions.ShowDialog() == DialogResult.OK) {
      StreamWriter CSVFile = new StreamWriter(CSVItemExporter.dlgOptions.FileName, false, CSVItemExporter.dlgOptions.Encoding);
      char TextQuote = '"';
      long Index = 0;
      ItemField[] Fields = CSVItemExporter.dlgOptions.Fields;
	foreach (FFXIItem I in Items) {
	FFXIItem.IItemInfo II = I.GetInfo(CSVItemExporter.dlgOptions.Language, CSVItemExporter.dlgOptions.Type);
	  if (Index == 0) {
	    //if (CSVItemExporter.dlgOptions.IncludeIndex)
	    CSVFile.Write("{0}{1}{0}", TextQuote, I18N.GetText("ColumnHeader:Index"));
	    foreach (ItemField IF in Fields) {
	      if (IF == ItemField.Description) {
	      string FieldName = new NamedEnum(IF).Name;
		CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, String.Format(I18N.GetText("ColumnHeader:DescriptionLineCount"), FieldName));
		for (byte i = 0; i < 6; ++i) // Max 6 lines - should be plenty
		  CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, String.Format(I18N.GetText("ColumnHeader:DescriptionLine"), FieldName, i + 1));
	      }
	      else
		CSVFile.Write("{0}{1}{2}{1}", CultureInfo.CurrentCulture.TextInfo.ListSeparator, TextQuote, new NamedEnum(IF).Name);
	    }
	    CSVFile.WriteLine();
	  }
	  //if (CSVItemExporter.dlgOptions.IncludeIndex)
	  CSVFile.Write(++Index);
	  foreach (ItemField IF in Fields) {
{'fraction_non_alphanumeric': 0.12685459940652818, 'fraction_numerical': 0.013353115727002967, 'mean_word_length': 4.3933333333333335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2761973', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1292, 'n_words': 269}