/// <summary> /// 大雑把にfunctionを一覧。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { Log_ReportsImpl.BDebugmode_Static = true; Log_Reports log_Reports; //(2)メソッド開始 Log_Method log_Method = new Log_MethodImpl(); // デバッグモード静的設定の後で。 log_Method.BeginMethod(Info_Actorslist.Name_Library, this, "button2_Click", out log_Reports); Exception error_Exception; //コンフィグファイル ConfigxmlImpl configxml = new ConfigxmlImpl(); configxml.Read(log_Reports); //CSV→テーブル Table_Humaninput tableH; if (log_Reports.Successful) { if(!File.Exists(configxml.FilepathExportLualist)) { goto gt_Error_File1; } string csvtext = File.ReadAllText(configxml.FilepathExportLualist); CsvTo_Table_HumaninputImpl trans = new CsvTo_Table_HumaninputImpl(); tableH = trans.Read( csvtext, new Request_ReadsTableImpl(), new Format_Table_HumaninputImpl(), //true, log_Reports ); } else { tableH = null; } //各.luaファイル List<string> listFile = new List<string>(); List<string> listRow = new List<string>(); List<string> listFunction = new List<string>(); if (log_Reports.Successful) { Regex regex2 = new Regex(@"^\s*function\s+(.*)$", RegexOptions.Compiled); tableH.ForEach_Datapart( (Record_Humaninput recordH, ref bool isBreak2, Log_Reports log_Reports2) => { string filepathRelational = recordH.TextAt("FILE"); string filepath = Path.Combine(configxml.FolderpathProject, filepathRelational); //ystem.Console.WriteLine("filepath=[" + filepath + "]"); string luatext = File.ReadAllText(filepath, Encoding.GetEncoding("Shift-JIS")); string[] lines = luatext.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); int row = 1;//行番号 foreach (string line in lines) { Match m2 = regex2.Match(line); if (m2.Success) { listFile.Add(filepathRelational); listRow.Add(row.ToString()); listFunction.Add(line); //System.Console.WriteLine("ファイル=[" + filepathRelational + "] [" + row + "]行 関数line=[" + line + "]"); } else { } row++; } }, log_Reports); } //配列(空回し);buffer Dictionary<string, string> dictionary1 = new Dictionary<string, string>();// 関数名の問題文字列:["シーン","クラスネーム"] if (log_Reports.Successful) { Regex regex4 = new Regex(@"^\s*function\s+(.*?)(_OnClose|_OnVanish)\s*\(.*$", RegexOptions.Compiled); //「_OnClose」ならシーン、 //「_OnVanish」ならクラスネームに確定します。 for (int i = 0; i < listFunction.Count; i++) { string function = listFunction[i]; Match m4 = regex4.Match(function); if (m4.Success) { if ("_OnClose" == m4.Groups[2].Value) { //シーン dictionary1.Add(m4.Groups[1].Value, "シーン"); } else if ("_OnVanish" == m4.Groups[2].Value) { //クラスネーム dictionary1.Add(m4.Groups[1].Value, "クラスネーム"); } else { } } } } //配列→CSV if (log_Reports.Successful) { Regex regex3 = new Regex(@"^\s*function\s+(.*?)(?:_OnStart|_OnStep|_OnClose|_OnVanish|_OnDraw)\s*\(.*$", RegexOptions.Compiled); Regex regex4 = new Regex(@"^\s*function\s+(?:OnLoad|OnVanish)\s*\(.*$", RegexOptions.Compiled); Regex regex5 = new Regex(@"^\s*function\s+(.*?)_init\s*\(.*$", RegexOptions.Compiled); Regex regex6 = new Regex(@"^\s*function\s+(.*?)Thread\s*\(.*$", RegexOptions.Compiled); Regex regex7 = new Regex(@"^\s*function\s+thread_(.*?)\s*\(.*$", RegexOptions.Compiled); CsvLineParserImpl parser = new CsvLineParserImpl(); StringBuilder sb = new StringBuilder(); sb.Append("NO,FILE,ROW,INITIALIZER,SCENE,THREAD,CLASS_NAME,FUNCTION,END");//,EOL sb.Append(Environment.NewLine); sb.Append("int,string,int,string,string,string,string,string,"); sb.Append(Environment.NewLine); sb.Append("-1,ファイルパス,行番号,suica32用ローダースレッド・ハンドラ?,シーン,スレッド?,クラス名,関数シグネチャー,"); sb.Append(Environment.NewLine); int row = 0; for (int i = 0; i < listFunction.Count; i++) { string file = listFile[i]; string numberRow = listRow[i]; string function = listFunction[i]; string initializer = ""; string scene = ""; string thread = ""; string classname = ""; Match m3 = regex3.Match(function); if (m3.Success) { string functionname2 = m3.Groups[1].Value; if (dictionary1.ContainsKey(functionname2)) { switch (dictionary1[functionname2]) { case "シーン": scene = functionname2; break; case "クラスネーム": classname = functionname2; break; default: break; } } goto gt_Csv; } Match m4 = regex4.Match(function); if (m4.Success) { scene = Path.GetFileNameWithoutExtension(file); goto gt_Csv; } Match m5 = regex5.Match(function); if (m5.Success) { initializer = m5.Groups[1].Value; goto gt_Csv; } Match m6 = regex6.Match(function); if (m6.Success) { thread = m6.Groups[1].Value; goto gt_Csv; } Match m7 = regex7.Match(function); if (m7.Success) { thread = m7.Groups[1].Value; goto gt_Csv; } gt_Csv: sb.Append(row); sb.Append(","); sb.Append(file); sb.Append(","); sb.Append(numberRow); sb.Append(","); sb.Append(initializer); sb.Append(","); sb.Append(scene); sb.Append(","); sb.Append(thread); sb.Append(","); sb.Append(classname); sb.Append(","); sb.Append(parser.EscapeCell(function)); sb.Append(","); sb.Append(Environment.NewLine); //ystem.Console.WriteLine("row=[" + row + "] file=[" + file + "] numberRow=[" + numberRow + "] initializer=[" + initializer + "] scene=[" + scene + "] thread=[" + thread + "] classname=[" + classname + "] classname=[" + classname + "] function=[" + parser.EscapeCell(function) + "]"); row++; } sb.Append("EOF,,,,,,,,"); sb.Append(Environment.NewLine); string csvfile = Path.Combine(Application.StartupPath, configxml.FilepathExportFunctionlist); System.Console.WriteLine("csvfile=[" + csvfile + "]"); File.WriteAllText(csvfile, sb.ToString(), Encoding.UTF8); } goto gt_EndMethod; #region 異常系 //──────────────────────────────────────── gt_Error_File1: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー13007!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("ファイルが足りません。"); s.Append(Environment.NewLine); s.Append("readme.txtを読んで、手順を踏んでください。"); s.Append(Environment.NewLine); s.Append(" .lua一覧CSVファイル=["); s.Append(configxml.FilepathExportLualist); s.Append("]"); r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── #endregion gt_EndMethod: log_Method.EndMethod(log_Reports); log_Reports.EndLogging(log_Method); }
//──────────────────────────────────────── public string ToCsvText( Table_Humaninput tableH, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0); log_Method.BeginMethod(Info_Table.Name_Library, this, "ToCsvText",log_Reports); Log_TextIndented result = new Log_TextIndentedImpl(); RecordFielddefinition error_RecordFielddefinition; Exception err_Excep; int error_IndexColumn; Fielddefinition error_Fielddefinition; object error_Item; if (null == tableH) { // エラー goto gt_Error_NullTable; } CsvLineParserImpl csvParser = new CsvLineParserImpl(); // フィールド名をカンマ区切りで出力します。最後にENDを付加します。 // フィールド定義部 if (tableH.RecordFielddefinition.Count < 1) { //エラー。 error_RecordFielddefinition = tableH.RecordFielddefinition; goto gt_Error_FieldZero; } // フィールド定義部:名前 tableH.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { result.Append(csvParser.EscapeCell(fielddefinition.Name_Humaninput)); result.Append(","); } }, log_Reports); result.Append(ToCsv_Table_Humaninput_RowColRegularImpl.S_END); result.Append(Environment.NewLine);//改行 // フィールド定義部:型 tableH.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { switch(fielddefinition.Type_Field) { case EnumTypeFielddefinition.String: { result.Append(FielddefinitionImpl.S_STRING); } break; case EnumTypeFielddefinition.Int: { result.Append(FielddefinitionImpl.S_INT); } break; case EnumTypeFielddefinition.Bool: { result.Append(FielddefinitionImpl.S_BOOL); } break; default: { // TODO エラー対応。 // 未定義の型があった場合、そのまま出力します。 // C#のメッセージになるかと思います。 result.Append(fielddefinition.ToString_Type()); } break; } result.Append(","); } }, log_Reports); result.Append(ToCsv_Table_Humaninput_RowColRegularImpl.S_END); result.Append(Environment.NewLine);//改行 // フィールド定義部:コメント tableH.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { result.Append(csvParser.EscapeCell(fielddefinition.Comment)); result.Append(","); } }, log_Reports); result.Append(ToCsv_Table_Humaninput_RowColRegularImpl.S_END); result.Append(Environment.NewLine);//改行 // 0行目から数えて3行目以降はデータ・テーブル部。 // データ・テーブル部 DataTable dataTable = tableH.DataTable; // 各行について for (int nRowIndex = 0; nRowIndex < dataTable.Rows.Count; nRowIndex++) { DataRow dataRow = dataTable.Rows[nRowIndex]; // // 各フィールドについて // object[] itemArray = dataRow.ItemArray;// ItemArrayは1回の呼び出しが重い。 for (int indexColumn = 0; indexColumn < itemArray.Length; indexColumn++) { // TODO:範囲 リストサイズが0の時がある←プログラムミス? Fielddefinition fielddefinition; try { fielddefinition = tableH.RecordFielddefinition.ValueAt(indexColumn); } catch (Exception e) { // エラー。 err_Excep = e; error_RecordFielddefinition = tableH.RecordFielddefinition; error_IndexColumn = indexColumn; goto gt_Error_OutOfIndex; } if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { string value_Cell; object item = itemArray[indexColumn]; if (item is Value_Humaninput) { value_Cell = ((Value_Humaninput)item).Text; } else if (item is string) { //フィールド定義部など。 value_Cell = (string)item; } else if (item is DBNull) { //空欄。 value_Cell = ""; } else { // エラー error_Item = item; error_Fielddefinition = fielddefinition; goto gt_Error_UndefinedFieldType; } result.Append(csvParser.EscapeCell(value_Cell)); result.Append(this.charSeparator); } } result.Append(ToCsv_Table_Humaninput_RowColRegularImpl.S_END); result.Append(Environment.NewLine);//改行 } result.Append(ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF); // 最後に一応、改行を付けておきます。 result.Append(Environment.NewLine);//改行 goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_FieldZero: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー854!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)テーブルの列定義が0件です。 error_RecordFielddefinition.Count["); s.Append(error_RecordFielddefinition.Count); s.Append("] テーブル名=["); s.Append(tableH.Name); s.Append("]"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_OutOfIndex: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー853!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)err_NColIndex=["); s.Append(error_IndexColumn); s.Append("] error_RecordFielddefinition.Count["); s.Append(error_RecordFielddefinition.Count); s.Append("]"); s.Newline(); // ヒント s.Append(r.Message_SException(err_Excep)); r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_UndefinedFieldType: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー855!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)CSVを出力しようとしたとき、未定義のフィールド型=["); s.Append(error_Fielddefinition.ToString_Type()); s.Append("]がありました。"); s.Newline(); s.Append("型名=["); s.Append(error_Item.GetType().Name); s.Append("]"); s.Newline(); s.Append("型は["); s.Append(typeof(String_HumaninputImpl)); s.Append("],["); s.Append(typeof(Int_HumaninputImpl)); s.Append("],["); s.Append(typeof(Bool_HumaninputImpl)); s.Append("]が使えます。"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_NullTable: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー852!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)tableがヌルでした。"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); return result.ToString(); }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// 文字列エスケープされます。 /// </summary> /// <param name="name"></param> /// <param name="type"></param> /// <param name="comment"></param> public void AddWithEscape(string name, string type, string comment) { this.name_.Add(CsvLineParserImpl.EscapeCell(name)); this.type_.Add(CsvLineParserImpl.EscapeCell(type)); this.comment_.Add(CsvLineParserImpl.EscapeCell(comment)); }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── public string ToCsvText( Table_Humaninput xTable, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0); log_Method.BeginMethod(Info_Table.Name_Library, this, "ToCsvText", log_Reports); Log_TextIndented result = new Log_TextIndentedImpl(); RecordFielddef error_RecordFielddef; Exception err_Excep; int error_IndexColumn; Fielddef error_Fielddef; object error_Item; if (null == xTable) { // エラー goto gt_Error_NullTable; } CsvLineParserImpl csvParser = new CsvLineParserImpl(); // フィールド名をカンマ区切りで出力します。最後にEOLを付加します。 // フィールド定義部 if (xTable.RecordFielddef.Count < 1) { //エラー。 error_RecordFielddef = xTable.RecordFielddef; goto gt_Error_FieldZero; } // フィールド定義部:名前 xTable.RecordFielddef.ForEach(delegate(Fielddef fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { result.Append(CsvLineParserImpl.EscapeCell(fielddefinition.Name_Humaninput)); result.Append(","); } }, log_Reports); result.Append( ToCsv_Table_RowColRegularImpl_.S_EOL //ToCsv_Table_Humaninput_RowColRegularImpl.S_END ); result.Append(Environment.NewLine); //改行 // フィールド定義部:型 xTable.RecordFielddef.ForEach(delegate(Fielddef fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { switch (fielddefinition.Type_Field) { case EnumTypeFielddef.String: { result.Append(FielddefImpl.S_STRING); } break; case EnumTypeFielddef.Int: { result.Append(FielddefImpl.S_INT); } break; case EnumTypeFielddef.Bool: { result.Append(FielddefImpl.S_BOOL); } break; default: { // TODO エラー対応。 // 未定義の型があった場合、そのまま出力します。 // C#のメッセージになるかと思います。 result.Append(fielddefinition.ToString_Type()); } break; } result.Append(","); } }, log_Reports); result.Append( ToCsv_Table_RowColRegularImpl_.S_EOL //ToCsv_Table_Humaninput_RowColRegularImpl.S_END ); result.Append(Environment.NewLine);//改行 // フィールド定義部:コメント xTable.RecordFielddef.ForEach(delegate(Fielddef fielddefinition, ref bool isBreak, Log_Reports log_Reports2) { if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { result.Append(CsvLineParserImpl.EscapeCell(fielddefinition.Comment)); result.Append(","); } }, log_Reports); result.Append( ToCsv_Table_RowColRegularImpl_.S_EOL //ToCsv_Table_Humaninput_RowColRegularImpl.S_END ); result.Append(Environment.NewLine);//改行 // 0行目から数えて3行目以降はデータ・テーブル部。 // データ・テーブル部 DataTable dataTable = xTable.DataTable; // 各行について for (int nRowIndex = 0; nRowIndex < dataTable.Rows.Count; nRowIndex++) { DataRow dataRow = dataTable.Rows[nRowIndex]; // // 各フィールドについて // object[] itemArray = dataRow.ItemArray;// ItemArrayは1回の呼び出しが重い。 for (int indexColumn = 0; indexColumn < itemArray.Length; indexColumn++) { // TODO:範囲 リストサイズが0の時がある←プログラムミス? Fielddef fielddefinition; try { fielddefinition = xTable.RecordFielddef.ValueAt(indexColumn); } catch (Exception e) { // エラー。 err_Excep = e; error_RecordFielddef = xTable.RecordFielddef; error_IndexColumn = indexColumn; goto gt_Error_OutOfIndex; } if (this.ExceptedFields.TryExceptedField(fielddefinition.Name_Trimupper)) { // 出力しないフィールドの場合、無視します。 } else { string value_Cell; object item = itemArray[indexColumn]; if (item is Cell) { value_Cell = ((Cell)item).Text; } else if (item is string) { //フィールド定義部など。 value_Cell = (string)item; } else if (item is DBNull) { //空欄。 value_Cell = ""; } else { // エラー error_Item = item; error_Fielddef = fielddefinition; goto gt_Error_UndefinedFieldType; } result.Append(CsvLineParserImpl.EscapeCell(value_Cell)); result.Append(this.charSeparator); } } result.Append( ToCsv_Table_RowColRegularImpl_.S_EOL //ToCsv_Table_Humaninput_RowColRegularImpl.S_END ); result.Append(Environment.NewLine);//改行 } result.Append(ToCsv_Table_RowColRegularImpl_.S_EOF); // 最後に一応、改行を付けておきます。 result.Append(Environment.NewLine);//改行 goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_FieldZero: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー854!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)テーブルの列定義が0件です。 error_RecordFielddef.Count["); s.Append(error_RecordFielddef.Count); s.Append("] テーブル名=["); s.Append(xTable.Name); s.Append("]"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_OutOfIndex: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー853!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)err_NColIndex=["); s.Append(error_IndexColumn); s.Append("] error_RecordFielddef.Count["); s.Append(error_RecordFielddef.Count); s.Append("]"); s.Newline(); // ヒント s.Append(r.Message_SException(err_Excep)); r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_UndefinedFieldType: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー855!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)CSVを出力しようとしたとき、未定義のフィールド型=["); s.Append(error_Fielddef.ToString_Type()); s.Append("]がありました。"); s.Newline(); s.Append("型名=["); s.Append(error_Item.GetType().Name); s.Append("]"); s.Newline(); s.Append("型は["); s.Append(typeof(StringCellImpl)); s.Append("],["); s.Append(typeof(IntCellImpl)); s.Append("],["); s.Append(typeof(BoolCellImpl)); s.Append("]が使えます。"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── gt_Error_NullTable: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー852!", log_Method); Log_TextIndented s = new Log_TextIndentedImpl(); s.Append("(プログラム内部エラー)tableがヌルでした。"); s.Newline(); // ヒント r.Message = s.ToString(); log_Reports.EndCreateReport(); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); return(result.ToString()); }