OSDN Git Service

improve encapsulation
[tdcgexplorer/tso2mqo.git] / Program.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.IO;\r
4 using System.Text;\r
5 using System.Windows.Forms;\r
6 \r
7 namespace Tso2MqoGui\r
8 {\r
9     static class Program\r
10     {\r
11         /// <summary>\r
12         /// アプリケーションのメイン エントリ ポイントです。\r
13         /// </summary>\r
14         [STAThread]\r
15         static int Main(string[] args)\r
16         {\r
17             if (args.Length != 0)\r
18             {\r
19                 // バッチで処理する\r
20                 try\r
21                 {\r
22                     string tso_file = null;\r
23                     string mqo_file = null;\r
24                     string tsoref_file = null;\r
25                     string out_path = null;\r
26 \r
27                     foreach (string arg in args)\r
28                     {\r
29                         string opt = arg.ToLower();\r
30 \r
31                         if (opt.StartsWith("-tso:"))\r
32                             tso_file = opt.Substring(5).Trim('\r', '\n');\r
33                         else if (opt.StartsWith("-mqo:"))\r
34                             mqo_file = opt.Substring(5).Trim('\r', '\n');\r
35                         else if (opt.StartsWith("-ref:"))\r
36                             tsoref_file = opt.Substring(5).Trim('\r', '\n');\r
37                         else if (opt.StartsWith("-out:"))\r
38                             out_path = opt.Substring(5).Trim('\r', '\n');\r
39                         else\r
40                             throw new ArgumentException("Invalid option: " + arg);\r
41                     }\r
42 \r
43                     if (tso_file == null)\r
44                         throw new ArgumentException("-tso:ファイル名 の形式で出力Tsoファイル名を指定してください");\r
45 \r
46                     if (out_path != null)\r
47                     {\r
48                         MqoGenerator gen = new MqoGenerator();\r
49                         gen.Generate(tso_file, out_path, MqoBoneMode.None);\r
50                     }\r
51                     else\r
52                     {\r
53                         if (mqo_file == null)\r
54                             throw new ArgumentException("-mso:ファイル名 の形式で入力Mqoファイル名を指定してください");\r
55                         if (tsoref_file == null)\r
56                             throw new ArgumentException("-ref:ファイル名 の形式で参照Tsoファイル名を指定してください");\r
57 \r
58                         TSOGeneratorConfig config = new TSOGeneratorConfig();\r
59                         config.cui = true;\r
60                         config.ShowMaterials = false;\r
61                         TSOGeneratorRefBone gen = new TSOGeneratorRefBone(config);\r
62 \r
63                         gen.Generate(mqo_file, tsoref_file, tso_file);\r
64                     }\r
65                 }\r
66                 catch (ArgumentException e)\r
67                 {\r
68                     System.Diagnostics.Debug.WriteLine(e.Message);\r
69                     System.Console.Out.WriteLine(e.Message);\r
70                     System.Console.Out.Flush();\r
71                     return 1;\r
72                 }\r
73                 catch (Exception exception)\r
74                 {\r
75                     System.Diagnostics.Debug.WriteLine(exception.Message);\r
76                     System.Console.Out.WriteLine(exception.Message);\r
77                     System.Console.Out.Flush();\r
78                     return 1;\r
79                 }\r
80 \r
81                 return 0;\r
82             }\r
83 \r
84             Application.EnableVisualStyles();\r
85             Application.SetCompatibleTextRenderingDefault(false);\r
86             Application.Run(new Form1());\r
87 \r
88             return 0;\r
89         }\r
90     }\r
91 }