1111using System . Globalization ;
1212using System . Collections . Generic ;
1313using System . Text . RegularExpressions ;
14+ using System . Data ;
1415
1516namespace ThermoRawFileParser
1617{
@@ -52,6 +53,8 @@ private static void XicParametersParsing(string[] args)
5253 XicParameters parameters = new XicParameters ( ) ;
5354 string singleFile = null ;
5455 string fileDirectory = null ;
56+ string outputFile = null ;
57+ string outputDirectory = null ;
5558 string logFormatString = null ;
5659
5760 var optionSet = new OptionSet
@@ -82,10 +85,15 @@ private static void XicParametersParsing(string[] args)
8285 {
8386 "o=|output=" ,
8487 "The output directory. If not specified, the output is written to the input directory" ,
85- v => parameters . outputDirectory = v
88+ v => outputDirectory = v
8689 } ,
8790 {
88- "b|base64" ,
91+ "b=|output_file" ,
92+ "The output file. Specify this or an output directory -o. Specifying neither writes to the input directory." ,
93+ v => outputFile = v
94+ } ,
95+ {
96+ "6|base64" ,
8997 "Encodes the content of the xic vectors as base 64 encoded string." ,
9098 v => parameters . base64 = v != null
9199 } ,
@@ -163,7 +171,7 @@ private static void XicParametersParsing(string[] args)
163171 }
164172
165173
166- if ( parameters . outputDirectory != null && ! Directory . Exists ( parameters . outputDirectory ) )
174+ if ( outputDirectory != null && ! Directory . Exists ( outputDirectory ) )
167175 {
168176 throw new OptionException (
169177 "specify a valid output location" ,
@@ -177,18 +185,55 @@ private static void XicParametersParsing(string[] args)
177185 "-i, --input xor -d, --input_directory" ) ;
178186 }
179187
188+ if ( outputFile != null && outputDirectory != null )
189+ {
190+ throw new OptionException (
191+ "cannot use an output file and an output directory simultaneously" ,
192+ "-b, --output_file; -o, --output" ) ;
193+ }
194+
180195 if ( singleFile != null )
181196 {
182197 parameters . rawFileList . Add ( Path . GetFullPath ( singleFile ) ) ;
198+
199+ if ( outputFile != null )
200+ {
201+ parameters . outputFileList . Add ( Path . GetFullPath ( outputFile ) ) ;
202+ }
203+ else if ( outputDirectory != null )
204+ {
205+ parameters . outputFileList . Add ( Path . Combine ( outputDirectory ?? throw new NoNullAllowedException ( "Output directory cannot be null" ) ,
206+ Path . GetFileNameWithoutExtension ( singleFile ) + ".json" ) ) ;
207+ }
208+ else
209+ {
210+ parameters . outputFileList . Add ( Path . Combine ( Path . GetDirectoryName ( Path . GetFullPath ( singleFile ) ) ,
211+ Path . GetFileNameWithoutExtension ( singleFile ) + ".json" ) ) ;
212+ }
183213 }
184214 else
185215 {
216+ if ( outputFile != null )
217+ {
218+ throw new OptionException ( "Cannot use single output file to proceess a directory, use directory output instead" , "-o, --output" ) ;
219+ }
220+ else if ( outputDirectory != null )
221+ {
222+ outputDirectory = Path . GetFullPath ( outputDirectory ) ;
223+ }
224+ else
225+ {
226+ outputDirectory = Path . GetFullPath ( fileDirectory ) ;
227+ }
228+
186229 var directoryInfo = new DirectoryInfo ( Path . GetFullPath ( fileDirectory ) ) ;
187230 var files = directoryInfo . GetFiles ( "*" , SearchOption . TopDirectoryOnly )
188231 . Where ( f => f . Extension . ToLower ( ) == ".raw" ) . ToArray < FileInfo > ( ) ;
189232 foreach ( var file in files )
190233 {
191234 parameters . rawFileList . Add ( file . FullName ) ;
235+ parameters . outputFileList . Add ( Path . Combine ( outputDirectory ?? throw new NoNullAllowedException ( "Output directory cannot be null" ) ,
236+ Path . GetFileNameWithoutExtension ( file . Name ) + ".json" ) ) ;
192237 }
193238 }
194239
0 commit comments