1- namespace GameFrameX . ProtoExport ;
2-
3- public static class ProtoBufMessageHandler
4- {
5- private static IProtoGenerateHelper ProtoGenerateHelper ;
6-
7- public static void Start ( LauncherOptions launcherOptions , ModeType modeType )
8- {
9- if ( ! Directory . Exists ( launcherOptions . OutputPath ) )
10- {
11- Directory . CreateDirectory ( launcherOptions . OutputPath ) ;
12- }
13-
14- var types = typeof ( IProtoGenerateHelper ) . Assembly . GetTypes ( ) ;
15- foreach ( var type in types )
16- {
17- var attrs = type . GetCustomAttributes ( typeof ( ModeAttribute ) , true ) ;
18- if ( attrs ? . Length > 0 && ( attrs [ 0 ] is ModeAttribute modeAttribute ) && modeAttribute . Mode == modeType )
19- {
20- ProtoGenerateHelper = ( IProtoGenerateHelper ) Activator . CreateInstance ( type ) ;
21- break ;
22- }
23- }
24-
25- var files = Directory . GetFiles ( launcherOptions . InputPath , "*.proto" , SearchOption . AllDirectories ) ;
26-
27- var messageInfoLists = new List < MessageInfoList > ( files . Length ) ;
28- foreach ( var file in files )
29- {
30- var operationCodeInfo = MessageHelper . Parse ( File . ReadAllText ( file ) , Path . GetFileNameWithoutExtension ( file ) , launcherOptions . OutputPath , launcherOptions . IsGenerateErrorCode ) ;
31- messageInfoLists . Add ( operationCodeInfo ) ;
32- switch ( modeType )
33- {
34- case ModeType . Server :
35- case ModeType . Unity :
36- ProtoGenerateHelper ? . Run ( operationCodeInfo , launcherOptions . OutputPath , launcherOptions . NamespaceName ) ;
37- break ;
38- case ModeType . TypeScript :
39- ProtoGenerateHelper ? . Run ( operationCodeInfo , launcherOptions . OutputPath , Path . GetFileNameWithoutExtension ( file ) ) ;
40- break ;
41- default :
42- throw new ArgumentOutOfRangeException ( ) ;
43- }
44- }
45-
46- ProtoGenerateHelper ? . Post ( messageInfoLists , launcherOptions . OutputPath ) ;
47- }
1+ namespace GameFrameX . ProtoExport ;
2+
3+ public static class ProtoBufMessageHandler
4+ {
5+ private static IProtoGenerateHelper ProtoGenerateHelper ;
6+
7+ public static void Start ( LauncherOptions launcherOptions , ModeType modeType )
8+ {
9+ var outputDirectoryInfo = new DirectoryInfo ( launcherOptions . OutputPath ) ;
10+ if ( outputDirectoryInfo . Exists )
11+ {
12+ outputDirectoryInfo . Delete ( true ) ;
13+ }
14+
15+ outputDirectoryInfo . Create ( ) ;
16+
17+ launcherOptions . OutputPath = outputDirectoryInfo . FullName ;
18+
19+ var types = typeof ( IProtoGenerateHelper ) . Assembly . GetTypes ( ) ;
20+ foreach ( var type in types )
21+ {
22+ var attrs = type . GetCustomAttributes ( typeof ( ModeAttribute ) , true ) ;
23+ if ( attrs ? . Length > 0 && ( attrs [ 0 ] is ModeAttribute modeAttribute ) && modeAttribute . Mode == modeType )
24+ {
25+ ProtoGenerateHelper = ( IProtoGenerateHelper ) Activator . CreateInstance ( type ) ;
26+ break ;
27+ }
28+ }
29+
30+ var files = Directory . GetFiles ( launcherOptions . InputPath , "*.proto" , SearchOption . AllDirectories ) ;
31+
32+ var messageInfoLists = new List < MessageInfoList > ( files . Length ) ;
33+ foreach ( var file in files )
34+ {
35+ var operationCodeInfo = MessageHelper . Parse ( File . ReadAllText ( file ) , Path . GetFileNameWithoutExtension ( file ) , launcherOptions . OutputPath , launcherOptions . IsGenerateErrorCode ) ;
36+ messageInfoLists . Add ( operationCodeInfo ) ;
37+ switch ( modeType )
38+ {
39+ case ModeType . Server :
40+ case ModeType . Unity :
41+ ProtoGenerateHelper ? . Run ( operationCodeInfo , launcherOptions . OutputPath , launcherOptions . NamespaceName ) ;
42+ break ;
43+ case ModeType . TypeScript :
44+ ProtoGenerateHelper ? . Run ( operationCodeInfo , launcherOptions . OutputPath , Path . GetFileNameWithoutExtension ( file ) ) ;
45+ break ;
46+ default :
47+ throw new ArgumentOutOfRangeException ( ) ;
48+ }
49+ }
50+
51+ ProtoGenerateHelper ? . Post ( messageInfoLists , launcherOptions . OutputPath ) ;
52+ }
4853}
0 commit comments