11using System ;
22using System . IO ;
33using System . Reflection ;
4+ using System . Text . RegularExpressions ;
45
56namespace RadiantMapToWavefrontObj
67{
78 internal class Program
89 {
10+ private static double _scale = 0.01 ;
11+ private static bool _autoclose = false ;
12+
913 static void Main ( string [ ] args )
1014 {
1115 Version version = Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version ;
1216 Console . WriteLine ( "RadiantMapToWavefrontObj version " + version . Major + '.' + version . Minor + '.' + version . Build ) ;
1317
14- // Check if the file exists.
15- if ( args . Length > 0 && File . Exists ( args [ 0 ] ) )
16- ConvertFile ( args [ 0 ] ) ;
17- else
18+ bool success = false ;
19+
20+ // Check for each argument if it is a .map we should convert.
21+ foreach ( string arg in args )
22+ {
23+ if ( File . Exists ( arg ) && Path . GetExtension ( arg ) == ".map" )
24+ {
25+ ConvertFile ( arg ) ;
26+ success = true ;
27+ }
28+ else
29+ HandleArgument ( arg ) ;
30+ }
31+
32+ if ( ! success )
1833 Console . WriteLine ( "Invalid file." ) ;
1934
2035 // Wait for console input before closing.
2136 Console . WriteLine ( "\n Press any key to close this window..." ) ;
22- Console . ReadKey ( ) ;
37+
38+ if ( ! _autoclose )
39+ Console . ReadKey ( ) ;
2340 }
2441
2542 // Convert .map file to .obj file.
@@ -32,10 +49,37 @@ private static void ConvertFile(string path)
3249 RadiantMap map = RadiantMap . Parse ( path ) ;
3350 WavefrontObj obj = WavefrontObj . CreateFromRadiantMap ( map ) ;
3451
35- obj . SaveFile ( Path . GetFileNameWithoutExtension ( path ) + ".obj" , 0.01 ) ;
52+ obj . SaveFile ( Path . Combine ( Path . GetDirectoryName ( path ) , Path . GetFileNameWithoutExtension ( path ) ) + ".obj" , _scale ) ;
3653
3754 DateTime endTime = DateTime . Now ;
3855 Console . WriteLine ( "Finished in: " + ( endTime - startTime ) . Milliseconds + "ms." ) ;
3956 }
57+
58+ // Handle a settings argument.
59+ private static void HandleArgument ( string arg )
60+ {
61+ string pattern = @"-(\w+)=(\w+)" ;
62+ Regex regex = new Regex ( pattern , RegexOptions . IgnoreCase ) ;
63+ Match m = regex . Match ( arg ) ;
64+ if ( m . Success )
65+ {
66+ string type = m . Groups [ 1 ] . ToString ( ) ;
67+ string mode = m . Groups [ 2 ] . ToString ( ) ;
68+
69+ if ( type == "autoclose" )
70+ {
71+ if ( mode == "false" || mode == "0" )
72+ _autoclose = false ;
73+ else if ( mode == "true" || mode == "1" )
74+ _autoclose = true ;
75+ }
76+ else if ( type == "scale" )
77+ {
78+ double scale ;
79+ if ( Double . TryParse ( mode , out scale ) )
80+ _scale = scale ;
81+ }
82+ }
83+ }
4084 }
4185}
0 commit comments