forked from zhangqi-ulua/XlsxToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
1236 lines (1124 loc) · 82 KB
/
MainForm.cs
File metadata and controls
1236 lines (1124 loc) · 82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace XlsxToLuaGUI
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
// 部分文本框填入默认值
tbClientFolderPath.Text = AppValues.NO_CLIENT_PATH_STRING;
tbLangFilePath.Text = AppValues.NO_LANG_PARAM_STRING;
// 查找本程序所在目录下是否含有XlsxToLua工具,如果有直接填写路径到“工具所在目录”文本框中
string defaultPath = Utils.CombinePath(AppValues.PROGRAM_FOLDER_PATH, AppValues.PROGRAM_NAME);
if (File.Exists(defaultPath))
tbProgramPath.Text = defaultPath;
}
private void btnChooseExcelFolderPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择Excel文件所在目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExcelFolderPath.Text = folderPath;
}
}
private void btnChooseExportLuaFolderPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择lua文件导出目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExportLuaFolderPath.Text = folderPath;
}
}
private void btnChooseClientFolderPath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择项目Client所在目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbClientFolderPath.Text = folderPath;
}
}
private void btnChooseLangFilePath_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "请选择lang文件所在路径";
dialog.Multiselect = false;
dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
if (dialog.ShowDialog() == DialogResult.OK)
{
string filePath = dialog.FileName;
tbLangFilePath.Text = filePath;
}
}
private void btnChoosePartExcel_Click(object sender, EventArgs e)
{
string errorString = null;
string chooseExcelNames = _GetChoosePartExcelFile(tbPartExcelNames.Text, out errorString);
if (errorString == null)
{
if (chooseExcelNames != null)
tbPartExcelNames.Text = chooseExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseExceptExcel_Click(object sender, EventArgs e)
{
string errorString = null;
string exceptExcelNames = _GetChoosePartExcelFile(tbExceptExcelNames.Text, out errorString);
if (errorString == null)
{
if (exceptExcelNames != null)
tbExceptExcelNames.Text = exceptExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseProgramPath_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "请选择XlsxToLua工具所在路径";
dialog.Multiselect = false;
dialog.Filter = "Exe files (*.exe)|*.exe";
if (dialog.ShowDialog() == DialogResult.OK)
{
string filePath = dialog.FileName;
tbProgramPath.Text = filePath;
}
}
private void cbUnchecked_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
_WarnWhenChooseDangerousParam(cb);
}
private void cbAllowedNullNumber_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
_WarnWhenChooseDangerousParam(cb);
}
private void btnChooseExportCsvFile_Click(object sender, EventArgs e)
{
string errorString = null;
string chooseExcelNames = _GetChoosePartExcelFile(tbExportCsvTableNames.Text, out errorString);
if (errorString == null)
{
if (chooseExcelNames != null)
tbExportCsvTableNames.Text = chooseExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseExportCsvFilePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择csv文件导出目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExportCsvFilePath.Text = folderPath;
}
}
private void btnChooseExportCsClassFile_Click(object sender, EventArgs e)
{
string errorString = null;
string chooseExcelNames = _GetChoosePartExcelFile(tbExportCsClassTableNames.Text, out errorString);
if (errorString == null)
{
if (chooseExcelNames != null)
tbExportCsClassTableNames.Text = chooseExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseExportCsClassFilePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择csv对应C#类文件导出目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExportCsClassFilePath.Text = folderPath;
}
}
private void btnChooseExportJavaClassFile_Click(object sender, EventArgs e)
{
string errorString = null;
string chooseExcelNames = _GetChoosePartExcelFile(tbExportJavaClassTableNames.Text, out errorString);
if (errorString == null)
{
if (chooseExcelNames != null)
tbExportJavaClassTableNames.Text = chooseExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseExportJavaClassFilePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择csv对应Java类文件导出目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExportJavaClassFilePath.Text = folderPath;
}
}
private void btnChooseExportJsonFile_Click(object sender, EventArgs e)
{
string errorString = null;
string chooseExcelNames = _GetChoosePartExcelFile(tbExportJsonTableNames.Text, out errorString);
if (errorString == null)
{
if (chooseExcelNames != null)
tbExportJsonTableNames.Text = chooseExcelNames;
}
else
MessageBox.Show(errorString, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnChooseExportJsonFilePath_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择json文件导出目录";
dialog.ShowNewFolderButton = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
string folderPath = dialog.SelectedPath;
tbExportJsonFilePath.Text = folderPath;
}
}
private void btnExecute_Click(object sender, EventArgs e)
{
if (_CheckConfig() == true)
{
string programPath = tbProgramPath.Text.Trim();
string batContent = _GetExecuteParamString();
// System.Diagnostics.Process.Start函数无法识别用/分层的相对路径,故需进行转换
System.Diagnostics.Process.Start(programPath.Replace('/', '\\'), batContent.Substring(batContent.IndexOf(programPath) + programPath.Length + 1));
}
}
private void btnGenerateBat_Click(object sender, EventArgs e)
{
if (_CheckConfig() == true)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "请选择要生成的bat批处理脚本所在路径";
dialog.InitialDirectory = Path.GetDirectoryName(tbProgramPath.Text.Trim());
dialog.Filter = "Bat files (*.bat)|*.bat";
if (dialog.ShowDialog() == DialogResult.OK)
{
string filePath = dialog.FileName;
string batContent = _GetExecuteParamString();
string errorString = null;
Utils.SaveFile(filePath, batContent, out errorString);
if (string.IsNullOrEmpty(errorString))
MessageBox.Show("生成bat批处理脚本成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show(string.Format("保存bat批处理脚本失败:{0}", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnSaveConfig_Click(object sender, EventArgs e)
{
if (_CheckConfig() == true)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Title = "请选择配置文件的保存路径";
dialog.InitialDirectory = AppValues.PROGRAM_FOLDER_PATH;
dialog.Filter = "Config files (*.txt)|*.txt";
if (dialog.ShowDialog() == DialogResult.OK)
{
StringBuilder configStringBuilder = new StringBuilder();
Uri programUri = new Uri(AppValues.PROGRAM_PATH);
string programPath = tbProgramPath.Text.Trim();
string excelFolderPath = tbExcelFolderPath.Text.Trim();
string exportLuaFolderPath = tbExportLuaFolderPath.Text.Trim();
string clientFolderPath = tbClientFolderPath.Text.Trim();
string langFilePath = tbLangFilePath.Text.Trim();
if (cbIsUseRelativePath.Checked == true)
{
if (Path.IsPathRooted(programPath))
programPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(programPath)).ToString());
if (Path.IsPathRooted(excelFolderPath))
excelFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(excelFolderPath)).ToString());
if (Path.IsPathRooted(exportLuaFolderPath))
exportLuaFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportLuaFolderPath)).ToString());
if (!clientFolderPath.Equals(AppValues.NO_CLIENT_PATH_STRING, StringComparison.CurrentCultureIgnoreCase) && Path.IsPathRooted(clientFolderPath))
clientFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(clientFolderPath)).ToString());
if (!langFilePath.Equals(AppValues.NO_LANG_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase) && Path.IsPathRooted(langFilePath))
langFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(langFilePath)).ToString());
}
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_PROGRAM_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(programPath);
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_EXCEL_FOLDER_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(excelFolderPath);
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_EXPORT_LUA_FOLDER_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportLuaFolderPath);
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_CLIENT_FOLDER_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(clientFolderPath);
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_LANG_FILE_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(langFilePath);
string partExcelNames = tbPartExcelNames.Text.Trim();
if (!string.IsNullOrEmpty(partExcelNames))
configStringBuilder.Append(AppValues.PART_EXPORT_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(partExcelNames);
string exceptExcelNames = tbExceptExcelNames.Text.Trim();
if (!string.IsNullOrEmpty(exceptExcelNames))
configStringBuilder.Append(AppValues.EXCEPT_EXPORT_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exceptExcelNames);
string exportCsvExcelNames = tbExportCsvTableNames.Text.Trim();
if (!string.IsNullOrEmpty(exportCsvExcelNames))
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportCsvExcelNames);
string exportCsvFilePath = tbExportCsvFilePath.Text.Trim();
if (!string.IsNullOrEmpty(exportCsvFilePath))
{
if (cbIsUseRelativePath.Checked == true && Path.IsPathRooted(exportCsvFilePath))
exportCsvFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportCsvFilePath)).ToString());
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CSV_PARAM_SUBTYPE_EXPORT_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportCsvFilePath);
}
string csvFileExtension = tbCsvFileExtension.Text.Trim();
if (!string.IsNullOrEmpty(csvFileExtension))
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CSV_PARAM_SUBTYPE_EXTENSION).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csvFileExtension);
string csvFileSplitString = tbCsvFileSplitString.Text;
if (!string.IsNullOrEmpty(csvFileSplitString))
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CSV_PARAM_SUBTYPE_SPLIT_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csvFileSplitString);
string exportCsClassExcelNames = tbExportCsClassTableNames.Text.Trim();
if (!string.IsNullOrEmpty(exportCsClassExcelNames))
configStringBuilder.Append(AppValues.EXPORT_CS_CLASS_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportCsClassExcelNames);
string exportCsClassFilePath = tbExportCsClassFilePath.Text.Trim();
if (!string.IsNullOrEmpty(exportCsClassFilePath))
{
if (cbIsUseRelativePath.Checked == true && Path.IsPathRooted(exportCsClassFilePath))
exportCsClassFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportCsClassFilePath)).ToString());
configStringBuilder.Append(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_EXPORT_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportCsClassFilePath);
}
string csClassNamespace = tbExportCsClassNamespace.Text.Trim();
if (!string.IsNullOrEmpty(csClassNamespace))
configStringBuilder.Append(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_NAMESPACE).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csClassNamespace);
string csClassUsing = tbExportCsClassUsing.Text.Trim();
if (!string.IsNullOrEmpty(csClassUsing))
configStringBuilder.Append(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_USING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csClassUsing);
string exportJavaClassExcelNames = tbExportJavaClassTableNames.Text.Trim();
if (!string.IsNullOrEmpty(exportJavaClassExcelNames))
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportJavaClassExcelNames);
string exportJavaClassFilePath = tbExportJavaClassFilePath.Text.Trim();
if (!string.IsNullOrEmpty(exportJavaClassFilePath))
{
if (cbIsUseRelativePath.Checked == true && Path.IsPathRooted(exportJavaClassFilePath))
exportJavaClassFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportJavaClassFilePath)).ToString());
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_EXPORT_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportJavaClassFilePath);
}
string javaClassPackage = tbExportJavaClassPackage.Text.Trim();
if (!string.IsNullOrEmpty(javaClassPackage))
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_PACKAGE).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(javaClassPackage);
string javaClassImport = tbExportJavaClassImport.Text.Trim();
if (!string.IsNullOrEmpty(javaClassImport))
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IMPORT).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(javaClassImport);
string csvClassNamePrefix = tbExportCsvClassNamePrefix.Text.Trim();
if (!string.IsNullOrEmpty(csvClassNamePrefix))
configStringBuilder.Append(AppValues.AUTO_NAME_CSV_CLASS_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.AUTO_NAME_CSV_CLASS_PARAM_SUBTYPE_CLASS_NAME_PREFIX).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csvClassNamePrefix);
string csvClassNamePostfix = tbExportCsvClassNamePostfix.Text.Trim();
if (!string.IsNullOrEmpty(csvClassNamePostfix))
configStringBuilder.Append(AppValues.AUTO_NAME_CSV_CLASS_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.AUTO_NAME_CSV_CLASS_PARAM_SUBTYPE_CLASS_NAME_POSTFIX).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(csvClassNamePostfix);
string exportJsonExcelNames = tbExportJsonTableNames.Text.Trim();
if (!string.IsNullOrEmpty(exportJsonExcelNames))
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportJsonExcelNames);
string exportJsonFilePath = tbExportJsonFilePath.Text.Trim();
if (!string.IsNullOrEmpty(exportJsonFilePath))
{
if (cbIsUseRelativePath.Checked == true && Path.IsPathRooted(exportJsonFilePath))
exportJsonFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportJsonFilePath)).ToString());
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JSON_PARAM_SUBTYPE_EXPORT_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(exportJsonFilePath);
}
string jsonFileExtension = tbJsonFileExtension.Text.Trim();
if (!string.IsNullOrEmpty(jsonFileExtension))
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JSON_PARAM_SUBTYPE_EXTENSION).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(jsonFileExtension);
const string TRUE_STRING = "true";
if (cbExportIncludeSubfolder.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_INCLUDE_SUBFOLDER_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportKeepDirectoryStructure.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_KEEP_DIRECTORY_STRUCTURE_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbColumnInfo.Checked == true)
configStringBuilder.Append(AppValues.NEED_COLUMN_INFO_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbUnchecked.Checked == true)
configStringBuilder.Append(AppValues.UNCHECKED_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbPrintEmptyStringWhenLangNotMatching.Checked == true)
configStringBuilder.Append(AppValues.LANG_NOT_MATCHING_PRINT_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportMySQL.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_MYSQL_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbAllowedNullNumber.Checked == true)
configStringBuilder.Append(AppValues.ALLOWED_NULL_NUMBER_PARAM_STRING).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbPart.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_PART).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExcept.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXCEPT).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportCsv.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_CSV).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsExportCsvColumnName.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CSV_PARAM_SUBTYPE_IS_EXPORT_COLUMN_NAME).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsExportCsvColumnDataType.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_CSV_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_CSV_PARAM_SUBTYPE_IS_EXPORT_COLUMN_DATA_TYPE).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportCsClass.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_CS_CLASS).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportJavaClass.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_JAVA_CLASS).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportJson.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_JSON).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsExportJsonWithFormat.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_FORMAT).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsExportJsonArrayFormat.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_EXPORT_JSON_ARRAY_FORMAT).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsExportJsonMapIncludeKeyColumnValue.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JSON_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_MAP_INCLUDE_KEY_COLUMN_VALUE).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportJavaClassIsUseDate.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_USE_DATE).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportJavaClassIsGenerateConstructorWithoutFields.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_GENERATE_CONSTRUCTOR_WITHOUT_FIELDS).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbExportJavaClassIsGenerateConstructorWithAllFields.Checked == true)
configStringBuilder.Append(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING).Append(AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR).Append(AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_GENERATE_CONSTRUCTOR_WITH_ALL_FIELDS).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
if (cbIsUseRelativePath.Checked == true)
configStringBuilder.Append(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_USE_RELATIVE_PATH).Append(AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR).AppendLine(TRUE_STRING);
string errorString = null;
Utils.SaveFile(dialog.FileName, configStringBuilder.ToString(), out errorString);
if (string.IsNullOrEmpty(errorString))
MessageBox.Show("保存配置文件成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show(string.Format("保存配置文件失败:{0}", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void btnLoadConfig_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "请选择配置文件所在路径";
dialog.InitialDirectory = AppValues.PROGRAM_FOLDER_PATH;
dialog.Multiselect = false;
dialog.Filter = "Config files (*.txt)|*.txt";
if (dialog.ShowDialog() == DialogResult.OK)
{
string errorString = null;
Dictionary<string, string> config = TxtConfigReader.ParseTxtConfigFile(dialog.FileName, AppValues.SAVE_CONFIG_KEY_VALUE_SEPARATOR, out errorString);
if (!string.IsNullOrEmpty(errorString))
{
MessageBox.Show(string.Format("打开配置文件失败:\n{0}", errorString), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (config.ContainsKey(AppValues.SAVE_CONFIG_KEY_PROGRAM_PATH))
tbProgramPath.Text = config[AppValues.SAVE_CONFIG_KEY_PROGRAM_PATH];
if (config.ContainsKey(AppValues.SAVE_CONFIG_KEY_EXCEL_FOLDER_PATH))
tbExcelFolderPath.Text = config[AppValues.SAVE_CONFIG_KEY_EXCEL_FOLDER_PATH];
if (config.ContainsKey(AppValues.SAVE_CONFIG_KEY_EXPORT_LUA_FOLDER_PATH))
tbExportLuaFolderPath.Text = config[AppValues.SAVE_CONFIG_KEY_EXPORT_LUA_FOLDER_PATH];
if (config.ContainsKey(AppValues.SAVE_CONFIG_KEY_CLIENT_FOLDER_PATH))
tbClientFolderPath.Text = config[AppValues.SAVE_CONFIG_KEY_CLIENT_FOLDER_PATH];
if (config.ContainsKey(AppValues.SAVE_CONFIG_KEY_LANG_FILE_PATH))
tbLangFilePath.Text = config[AppValues.SAVE_CONFIG_KEY_LANG_FILE_PATH];
if (config.ContainsKey(AppValues.EXPORT_INCLUDE_SUBFOLDER_PARAM_STRING))
cbExportIncludeSubfolder.Checked = true;
if (config.ContainsKey(AppValues.EXPORT_KEEP_DIRECTORY_STRUCTURE_PARAM_STRING))
cbExportKeepDirectoryStructure.Checked = true;
if (config.ContainsKey(AppValues.NEED_COLUMN_INFO_PARAM_STRING))
cbColumnInfo.Checked = true;
if (config.ContainsKey(AppValues.UNCHECKED_PARAM_STRING))
cbUnchecked.Checked = true;
if (config.ContainsKey(AppValues.LANG_NOT_MATCHING_PRINT_PARAM_STRING))
cbPrintEmptyStringWhenLangNotMatching.Checked = true;
if (config.ContainsKey(AppValues.EXPORT_MYSQL_PARAM_STRING))
cbExportMySQL.Checked = true;
if (config.ContainsKey(AppValues.ALLOWED_NULL_NUMBER_PARAM_STRING))
cbAllowedNullNumber.Checked = true;
if (config.ContainsKey(AppValues.PART_EXPORT_PARAM_STRING))
tbPartExcelNames.Text = config[AppValues.PART_EXPORT_PARAM_STRING];
if (config.ContainsKey(AppValues.EXCEPT_EXPORT_PARAM_STRING))
tbExceptExcelNames.Text = config[AppValues.EXCEPT_EXPORT_PARAM_STRING];
if (config.ContainsKey(AppValues.EXPORT_CSV_PARAM_STRING))
tbExportCsvTableNames.Text = config[AppValues.EXPORT_CSV_PARAM_STRING];
if (config.ContainsKey(AppValues.EXPORT_CS_CLASS_PARAM_STRING))
tbExportCsClassTableNames.Text = config[AppValues.EXPORT_CS_CLASS_PARAM_STRING];
if (config.ContainsKey(AppValues.EXPORT_JAVA_CLASS_PARAM_STRING))
tbExportJavaClassTableNames.Text = config[AppValues.EXPORT_JAVA_CLASS_PARAM_STRING];
if (config.ContainsKey(AppValues.EXPORT_JSON_PARAM_STRING))
tbExportJsonTableNames.Text = config[AppValues.EXPORT_JSON_PARAM_STRING];
string exportCsvFilePathKey = string.Concat(AppValues.EXPORT_CSV_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CSV_PARAM_SUBTYPE_EXPORT_PATH);
if (config.ContainsKey(exportCsvFilePathKey))
tbExportCsvFilePath.Text = config[exportCsvFilePathKey];
string csvFileExtensionKey = string.Concat(AppValues.EXPORT_CSV_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CSV_PARAM_SUBTYPE_EXTENSION);
if (config.ContainsKey(csvFileExtensionKey))
tbCsvFileExtension.Text = config[csvFileExtensionKey];
string csvFileSplitStringKey = string.Concat(AppValues.EXPORT_CSV_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CSV_PARAM_SUBTYPE_SPLIT_STRING);
if (config.ContainsKey(csvFileSplitStringKey))
tbCsvFileSplitString.Text = config[csvFileSplitStringKey];
string exportCsClassFilePathKey = string.Concat(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_EXPORT_PATH);
if (config.ContainsKey(exportCsClassFilePathKey))
tbExportCsClassFilePath.Text = config[exportCsClassFilePathKey];
string exportCsClassNamespace = string.Concat(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_NAMESPACE);
if (config.ContainsKey(exportCsClassNamespace))
tbExportCsClassNamespace.Text = config[exportCsClassNamespace];
string exportCsClassUsing = string.Concat(AppValues.EXPORT_CS_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CS_CLASS_PARAM_SUBTYPE_USING);
if (config.ContainsKey(exportCsClassUsing))
tbExportCsClassUsing.Text = config[exportCsClassUsing];
string exportJavaClassFilePathKey = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_EXPORT_PATH);
if (config.ContainsKey(exportJavaClassFilePathKey))
tbExportJavaClassFilePath.Text = config[exportJavaClassFilePathKey];
string exportJavaClassPackage = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_PACKAGE);
if (config.ContainsKey(exportJavaClassPackage))
tbExportJavaClassPackage.Text = config[exportJavaClassPackage];
string exportJavaClassImport = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IMPORT);
if (config.ContainsKey(exportJavaClassImport))
tbExportJavaClassImport.Text = config[exportJavaClassImport];
string exportCsvClassNamePrefix = string.Concat(AppValues.AUTO_NAME_CSV_CLASS_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.AUTO_NAME_CSV_CLASS_PARAM_SUBTYPE_CLASS_NAME_PREFIX);
if (config.ContainsKey(exportCsvClassNamePrefix))
tbExportCsvClassNamePrefix.Text = config[exportCsvClassNamePrefix];
string exportCsvClassNamePostfix = string.Concat(AppValues.AUTO_NAME_CSV_CLASS_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.AUTO_NAME_CSV_CLASS_PARAM_SUBTYPE_CLASS_NAME_POSTFIX);
if (config.ContainsKey(exportCsvClassNamePostfix))
tbExportCsvClassNamePostfix.Text = config[exportCsvClassNamePostfix];
string exportJsonFilePathKey = string.Concat(AppValues.EXPORT_JSON_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JSON_PARAM_SUBTYPE_EXPORT_PATH);
if (config.ContainsKey(exportJsonFilePathKey))
tbExportJsonFilePath.Text = config[exportJsonFilePathKey];
string jsonFileExtensionKey = string.Concat(AppValues.EXPORT_JSON_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JSON_PARAM_SUBTYPE_EXTENSION);
if (config.ContainsKey(jsonFileExtensionKey))
tbJsonFileExtension.Text = config[jsonFileExtensionKey];
cbPart.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_PART);
cbExcept.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXCEPT);
cbExportCsv.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_CSV);
cbExportCsClass.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_CS_CLASS);
cbExportJavaClass.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_JAVA_CLASS);
cbExportJson.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_EXPORT_JSON);
cbIsUseRelativePath.Checked = config.ContainsKey(AppValues.SAVE_CONFIG_KEY_IS_CHECKED_USE_RELATIVE_PATH);
string isExportCsvColumnNameKey = string.Concat(AppValues.EXPORT_CSV_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CSV_PARAM_SUBTYPE_IS_EXPORT_COLUMN_NAME);
cbIsExportCsvColumnName.Checked = config.ContainsKey(isExportCsvColumnNameKey);
string isExportCsvColumnDataTypeKey = string.Concat(AppValues.EXPORT_CSV_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_CSV_PARAM_SUBTYPE_IS_EXPORT_COLUMN_DATA_TYPE);
cbIsExportCsvColumnDataType.Checked = config.ContainsKey(isExportCsvColumnDataTypeKey);
string isExportJsonWithFormatKey = string.Concat(AppValues.EXPORT_JSON_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_FORMAT);
cbIsExportJsonWithFormat.Checked = config.ContainsKey(isExportJsonWithFormatKey);
string isExportJsonArrayFormat = string.Concat(AppValues.EXPORT_JSON_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_EXPORT_JSON_ARRAY_FORMAT);
cbIsExportJsonArrayFormat.Checked = config.ContainsKey(isExportJsonArrayFormat);
string isExportJsonMapIncludeKeyColumnValue = string.Concat(AppValues.EXPORT_JSON_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JSON_PARAM_SUBTYPE_IS_MAP_INCLUDE_KEY_COLUMN_VALUE);
cbIsExportJsonMapIncludeKeyColumnValue.Checked = config.ContainsKey(isExportJsonMapIncludeKeyColumnValue);
string exportJavaClassIsUseDate = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_USE_DATE);
cbExportJavaClassIsUseDate.Checked = config.ContainsKey(exportJavaClassIsUseDate);
string exportJavaClassIsGenerateConstructorWithoutFields = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_GENERATE_CONSTRUCTOR_WITHOUT_FIELDS);
cbExportJavaClassIsGenerateConstructorWithoutFields.Checked = config.ContainsKey(exportJavaClassIsGenerateConstructorWithoutFields);
string exportJavaClassIsGenerateConstructorWithAllFields = string.Concat(AppValues.EXPORT_JAVA_CLASS_PARAM_PARAM_STRING, AppValues.SAVE_CONFIG_PARAM_SUBTYPE_SEPARATOR, AppValues.EXPORT_JAVA_CLASS_PARAM_SUBTYPE_IS_GENERATE_CONSTRUCTOR_WITH_ALL_FIELDS);
cbExportJavaClassIsGenerateConstructorWithAllFields.Checked = config.ContainsKey(exportJavaClassIsGenerateConstructorWithAllFields);
MessageBox.Show("载入配置文件成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private bool _CheckConfig()
{
// 检查工具所在路径是否填写正确
string programPath = tbProgramPath.Text.Trim();
if (string.IsNullOrEmpty(programPath))
{
MessageBox.Show("必须指定XlsxToLua工具所在路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (programPath.Contains(AppValues.GUI_PROGRAM_NAME))
{
MessageBox.Show(string.Format("需要指定的是{0}所在路径而不是{1}所在路径", AppValues.PROGRAM_NAME, AppValues.GUI_PROGRAM_NAME), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!File.Exists(programPath))
{
MessageBox.Show("指定的XlsxToLua工具所在路径不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!".exe".Equals(Path.GetExtension(programPath), StringComparison.CurrentCultureIgnoreCase))
{
MessageBox.Show("指定的XlsxToLua工具错误,不是一个有效的exe程序", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查Excel文件所在目录是否填写正确
string excelFolderPath = tbExcelFolderPath.Text.Trim();
if (string.IsNullOrEmpty(excelFolderPath))
{
MessageBox.Show("必须指定Excel文件所在目录", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(excelFolderPath))
{
MessageBox.Show("指定的Excel文件所在目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查Excel文件夹及其下属子文件夹中是否存在同名文件
// 记录Excel文件夹及其子文件夹中的文件名对应的所在路径(key:表名, value:文件所在路径)
Dictionary<string, string> tableNameAndPath = new Dictionary<string, string>();
// 记录重名文件所在目录
Dictionary<string, List<string>> sameExcelNameInfo = new Dictionary<string, List<string>>();
if (cbExportIncludeSubfolder.Checked == true)
{
foreach (string filePath in Directory.GetFiles(excelFolderPath, "*.xlsx", SearchOption.AllDirectories))
{
string fileName = Path.GetFileNameWithoutExtension(filePath);
if (fileName.StartsWith(AppValues.EXCEL_TEMP_FILE_FILE_NAME_START_STRING))
continue;
if (tableNameAndPath.ContainsKey(fileName))
{
if (!sameExcelNameInfo.ContainsKey(fileName))
{
sameExcelNameInfo.Add(fileName, new List<string>());
sameExcelNameInfo[fileName].Add(tableNameAndPath[fileName]);
}
sameExcelNameInfo[fileName].Add(filePath);
}
else
tableNameAndPath.Add(fileName, filePath);
}
if (sameExcelNameInfo.Count > 0)
{
StringBuilder sameExcelNameErrorStringBuilder = new StringBuilder();
sameExcelNameErrorStringBuilder.AppendLine("错误:Excel文件夹及其子文件夹中不允许出现同名文件,重名文件如下:");
foreach (var item in sameExcelNameInfo)
{
string fileName = item.Key;
List<string> filePath = item.Value;
sameExcelNameErrorStringBuilder.AppendFormat("以下路径中存在同名文件({0}):\n", fileName);
foreach (string oneFilePath in filePath)
sameExcelNameErrorStringBuilder.AppendLine(oneFilePath);
}
MessageBox.Show(sameExcelNameErrorStringBuilder.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 检查如果设置了-exportKeepDirectoryStructure参数,是否也设置了-exportIncludeSubfolder参数
if (cbExportKeepDirectoryStructure.Checked == true && cbExportIncludeSubfolder.Checked == false)
{
MessageBox.Show(string.Format("只有通过设置{0}参数,将要导出的Excel文件夹下的各级子文件夹中的Excel文件也进行导出时,指定{1}参数设置将生成的文件按原Excel文件所在的目录结构进行存储才有意义,请检查是否遗漏设置{0}参数", AppValues.EXPORT_INCLUDE_SUBFOLDER_PARAM_STRING, AppValues.EXPORT_KEEP_DIRECTORY_STRUCTURE_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查lua文件导出目录是否填写正确
string exportLuaFolderPath = tbExportLuaFolderPath.Text.Trim();
if (string.IsNullOrEmpty(exportLuaFolderPath))
{
MessageBox.Show("必须指定lua文件导出目录", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(exportLuaFolderPath))
{
MessageBox.Show("指定的lua文件导出目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查项目Client所在目录是否填写正确
string clientFolderPath = tbClientFolderPath.Text.Trim();
if (string.IsNullOrEmpty(clientFolderPath))
{
MessageBox.Show(string.Format("未指定Client所在目录(若无需指定,请填写{0})", AppValues.NO_CLIENT_PATH_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbClientFolderPath.Text = AppValues.NO_CLIENT_PATH_STRING;
return false;
}
if (!clientFolderPath.Equals(AppValues.NO_CLIENT_PATH_STRING, StringComparison.CurrentCultureIgnoreCase))
{
if (!Directory.Exists(clientFolderPath))
{
MessageBox.Show("指定的项目Client所在目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 检查lang文件所在路径是否填写正确
string langFilePath = tbLangFilePath.Text.Trim();
if (string.IsNullOrEmpty(langFilePath))
{
MessageBox.Show(string.Format("未指定lang文件所在路径(若无需指定,请填写{0})", AppValues.NO_LANG_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
tbLangFilePath.Text = AppValues.NO_LANG_PARAM_STRING;
return false;
}
if (!langFilePath.Equals(AppValues.NO_LANG_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase))
{
if (!File.Exists(langFilePath))
{
MessageBox.Show("指定的lang文件所在路径不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 若设置导出部分Excel文件,检查文件名声明是否正确
List<string> exportTableNames = new List<string>();
if (cbPart.Checked == true)
{
string partExcelNames = tbPartExcelNames.Text.Trim();
if (string.IsNullOrEmpty(partExcelNames))
{
MessageBox.Show("勾选了导出部分Excel文件的选项,就必须在文本框中填写要导出的Excel文件名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
string[] fileNames = partExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string fileName in fileNames)
exportTableNames.Add(fileName.Trim());
// 检查指定导出的Excel文件是否存在
foreach (string exportExcelFileName in exportTableNames)
{
if (!tableNameAndPath.ContainsKey(exportExcelFileName))
{
MessageBox.Show(string.Format("指定要导出的Excel文件({0})不存在,请检查后重试并注意区分大小写", string.Concat(exportExcelFileName, ".xlsx")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 若设置忽略导出部分Excel文件,检查文件名声明是否正确
List<string> exceptTableNames = new List<string>();
if (cbExcept.Checked == true)
{
string exceptExcelNames = tbExceptExcelNames.Text.Trim();
if (string.IsNullOrEmpty(exceptExcelNames))
{
MessageBox.Show("勾选了忽略导出部分Excel文件的选项,就必须在文本框中填写要忽略的Excel文件名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
string[] fileNames = exceptExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string fileName in fileNames)
exceptTableNames.Add(fileName.Trim());
// 检查指定忽略导出的Excel文件是否存在
foreach (string exceptTableName in exceptTableNames)
{
if (!tableNameAndPath.ContainsKey(exceptTableName))
{
MessageBox.Show(string.Format("指定要忽略导出的Excel文件({0})不存在,请检查后重试并注意区分大小写", string.Concat(exceptTableName, ".xlsx")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 同一张表格不能既设置为-part又设置为-except
foreach (string exportTableName in exportTableNames)
{
if (exceptTableNames.Contains(exportTableName))
{
MessageBox.Show(string.Format("对表格{0}既设置了-part参数,又设置了-except参数", exportTableNames), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 若设置额外导出部分Excel表格为csv文件,检查声明的各种参数是否正确
if (cbExportCsv.Checked == true)
{
// 检查设置的要额外导出为csv文件的Excel表格名是否正确
string exportCsvExcelNames = tbExportCsvTableNames.Text.Trim();
if (string.IsNullOrEmpty(exportCsvExcelNames))
{
MessageBox.Show(string.Format("勾选了额外导出部分Excel表格为csv文件的选项,就必须指定要额外导出为csv文件的Excel文件名,若要全部导出,请指定{0}参数", AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!exportCsvExcelNames.Equals(AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase))
{
string[] fileNames = exportCsvExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
List<string> exportCsvTableNames = new List<string>();
foreach (string fileName in fileNames)
exportCsvTableNames.Add(fileName.Trim());
// 检查指定要额外导出为csv文件的Excel表格是否存在
foreach (string exportCsvExcelFileName in exportCsvTableNames)
{
if (!tableNameAndPath.ContainsKey(exportCsvExcelFileName))
{
MessageBox.Show(string.Format("指定要额外导出出csv文件的Excel表格({0})不存在,请检查后重试并注意区分大小写", string.Concat(exportCsvExcelFileName, ".xlsx")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 检查设置的导出csv文件的存储路径是否正确
string exportCsvFilePath = tbExportCsvFilePath.Text.Trim();
if (string.IsNullOrEmpty(exportCsvFilePath))
{
MessageBox.Show("勾选了额外导出部分Excel表格为csv文件的选项,就必须指定导出csv文件的存储路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(exportCsvFilePath))
{
MessageBox.Show("指定的csv文件导出目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查设置的导出csv文件的扩展名是否正确
string csvFileExtension = tbCsvFileExtension.Text.Trim();
if (string.IsNullOrEmpty(csvFileExtension))
{
MessageBox.Show("要额外导出为csv文件,就必须指定csv文件的扩展名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查设置的导出csv文件的字段分隔符是否正确
string csvFileSplitString = tbCsvFileSplitString.Text;
if (string.IsNullOrEmpty(csvFileSplitString))
{
MessageBox.Show("要额外导出为csv文件,就必须指定csv文件的字段分隔符", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 若设置额外导出部分Excel表格为csv对应C#类文件,检查声明的各种参数是否正确
if (cbExportCsClass.Checked == true)
{
// 检查设置的要额外导出为csv对应C#类文件的Excel表格名是否正确
string exportCsClassExcelNames = tbExportCsClassTableNames.Text.Trim();
if (string.IsNullOrEmpty(exportCsClassExcelNames))
{
MessageBox.Show(string.Format("勾选了额外导出部分Excel表格为csv对应C#类文件的选项,就必须指定要额外导出为csv对应C#类文件的Excel文件名,若要全部导出,请指定{0}参数", AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!exportCsClassExcelNames.Equals(AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase))
{
string[] fileNames = exportCsClassExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
List<string> exportCsClassTableNames = new List<string>();
foreach (string fileName in fileNames)
exportCsClassTableNames.Add(fileName.Trim());
// 检查指定要额外导出为csv对应C#类文件的Excel表格是否存在
foreach (string exportCsClassExcelFileName in exportCsClassTableNames)
{
if (!tableNameAndPath.ContainsKey(exportCsClassExcelFileName))
{
MessageBox.Show(string.Format("指定要额外导出csv对应C#类文件的Excel表格({0})不存在,请检查后重试并注意区分大小写", string.Concat(exportCsClassExcelFileName, ".xlsx")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 检查设置的导出csv对应C#类文件的存储路径是否正确
string exportCsClassFilePath = tbExportCsClassFilePath.Text.Trim();
if (string.IsNullOrEmpty(exportCsClassFilePath))
{
MessageBox.Show("勾选了额外导出部分Excel表格为csv对应C#类文件的选项,就必须指定导出csv对应C#类文件的存储路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(exportCsClassFilePath))
{
MessageBox.Show("指定的csv对应C#类文件导出目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 若设置额外导出部分Excel表格为csv对应Java类文件,检查声明的各种参数是否正确
if (cbExportJavaClass.Checked == true)
{
// 检查设置的要额外导出为csv对应Java类文件的Excel表格名是否正确
string exportJavaClassExcelNames = tbExportJavaClassTableNames.Text.Trim();
if (string.IsNullOrEmpty(exportJavaClassExcelNames))
{
MessageBox.Show(string.Format("勾选了额外导出部分Excel表格为csv对应Java类文件的选项,就必须指定要额外导出为csv对应Java类文件的Excel文件名,若要全部导出,请指定{0}参数", AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!exportJavaClassExcelNames.Equals(AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase))
{
string[] fileNames = exportJavaClassExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
List<string> exportJavaClassTableNames = new List<string>();
foreach (string fileName in fileNames)
exportJavaClassTableNames.Add(fileName.Trim());
// 检查指定要额外导出为csv对应C#类文件的Excel表格是否存在
foreach (string exportJavaClassExcelFileName in exportJavaClassTableNames)
{
if (!tableNameAndPath.ContainsKey(exportJavaClassExcelFileName))
{
MessageBox.Show(string.Format("指定要额外导出csv对应Java类文件的Excel表格({0})不存在,请检查后重试并注意区分大小写", string.Concat(exportJavaClassExcelFileName, ".xlsx")), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 检查设置的导出csv对应Java类文件的存储路径是否正确
string exportJavaClassFilePath = tbExportJavaClassFilePath.Text.Trim();
if (string.IsNullOrEmpty(exportJavaClassFilePath))
{
MessageBox.Show("勾选了额外导出部分Excel表格为csv对应Java类文件的选项,就必须指定导出csv对应Java类文件的存储路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(exportJavaClassFilePath))
{
MessageBox.Show("指定的csv对应Java类文件导出目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查导出csv对应Java类文件的包名是否填写
string exportJavaClassPackage = tbExportJavaClassPackage.Text.Trim();
if (string.IsNullOrEmpty(exportJavaClassPackage))
{
MessageBox.Show("勾选了额外导出部分Excel表格为csv对应Java类文件的选项,就必须指定导出csv对应Java类文件的包名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
// 若设置额外导出部分Excel表格为json文件,检查声明的各种参数是否正确
if (cbExportJson.Checked == true)
{
// 检查设置的要额外导出为json文件的Excel表格名是否正确
string exportJsonExcelNames = tbExportJsonTableNames.Text.Trim();
if (string.IsNullOrEmpty(exportJsonExcelNames))
{
MessageBox.Show(string.Format("勾选了额外导出部分Excel表格为json文件的选项,就必须指定要额外导出为json文件的Excel文件名,若要全部导出,请指定{0}参数", AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!exportJsonExcelNames.Equals(AppValues.EXPORT_ALL_TO_EXTRA_FILE_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase))
{
string[] fileNames = exportJsonExcelNames.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
List<string> exportJsonTableNames = new List<string>();
foreach (string fileName in fileNames)
exportJsonTableNames.Add(fileName.Trim());
// 检查指定要额外导出为json文件的Excel表格是否存在
foreach (string exportJsonExcelFileName in exportJsonTableNames)
{
if (!tableNameAndPath.ContainsKey(exportJsonExcelFileName))
{
MessageBox.Show(string.Format("指定要额外导出出json文件的Excel表格({0})不存在,请检查后重试并注意区分大小写", Utils.CombinePath(excelFolderPath, string.Concat(exportJsonExcelFileName, ".xlsx"))), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
}
// 检查设置的导出json文件的存储路径是否正确
string exportJsonFilePath = tbExportJsonFilePath.Text.Trim();
if (string.IsNullOrEmpty(exportJsonFilePath))
{
MessageBox.Show("勾选了额外导出部分Excel表格为json文件的选项,就必须指定导出json文件的存储路径", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
if (!Directory.Exists(exportJsonFilePath))
{
MessageBox.Show("指定的json文件导出目录不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
// 检查设置的导出json文件的扩展名是否正确
string jsonFileExtension = tbJsonFileExtension.Text.Trim();
if (string.IsNullOrEmpty(jsonFileExtension))
{
MessageBox.Show("要额外导出为json文件,就必须指定json文件的扩展名", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
return true;
}
private string _GetExecuteParamString()
{
StringBuilder stringBuilder = new StringBuilder();
Uri programUri = new Uri(AppValues.PROGRAM_PATH);
string programPath = tbProgramPath.Text.Trim();
string excelFolderPath = tbExcelFolderPath.Text.Trim();
string exportLuaFolderPath = tbExportLuaFolderPath.Text.Trim();
string clientFolderPath = tbClientFolderPath.Text.Trim();
string langFilePath = tbLangFilePath.Text.Trim();
if (cbIsUseRelativePath.Checked == true)
{
if (Path.IsPathRooted(programPath))
programPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(programPath)).ToString());
if (Path.IsPathRooted(excelFolderPath))
excelFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(excelFolderPath)).ToString());
if (Path.IsPathRooted(exportLuaFolderPath))
exportLuaFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(exportLuaFolderPath)).ToString());
if (!clientFolderPath.Equals(AppValues.NO_CLIENT_PATH_STRING, StringComparison.CurrentCultureIgnoreCase) && Path.IsPathRooted(clientFolderPath))
clientFolderPath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(clientFolderPath)).ToString());
if (!langFilePath.Equals(AppValues.NO_LANG_PARAM_STRING, StringComparison.CurrentCultureIgnoreCase) && Path.IsPathRooted(langFilePath))
langFilePath = Uri.UnescapeDataString(programUri.MakeRelativeUri(new Uri(langFilePath)).ToString());
}