2016-01-29 16:59:09 -08:00
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic ;
using System.IO ;
using System.Linq ;
using Microsoft.DotNet.Cli.Compiler.Common ;
using Microsoft.DotNet.Cli.Utils ;
namespace Microsoft.DotNet.Tools.Resgen
{
public partial class ResgenCommand
{
public string OutputFileName = null ;
public string AssemblyCulture = null ;
public string AssemblyVersion = null ;
2016-04-19 22:51:32 -05:00
public IEnumerable < string > CompilationReferences = null ;
public IEnumerable < string > Args = null ;
2016-01-29 16:59:09 -08:00
public int Execute ( )
{
2016-02-16 10:57:11 -08:00
var inputResourceFiles = Args . Select ( ParseInputFile ) . ToArray ( ) ;
2016-02-17 16:32:33 -08:00
var outputResourceFile = ResourceFile . Create ( OutputFileName ) ;
2016-01-29 16:59:09 -08:00
switch ( outputResourceFile . Type )
{
case ResourceFileType . Dll :
using ( var outputStream = outputResourceFile . File . Create ( ) )
{
var metadata = new AssemblyInfoOptions
{
Culture = AssemblyCulture ,
AssemblyVersion = AssemblyVersion ,
} ;
2016-02-16 10:57:11 -08:00
ResourceAssemblyGenerator . Generate ( inputResourceFiles ,
2016-01-29 16:59:09 -08:00
outputStream ,
metadata ,
Path . GetFileNameWithoutExtension ( outputResourceFile . File . Name ) ,
2016-02-17 16:32:33 -08:00
CompilationReferences . ToArray ( )
2016-02-16 10:57:11 -08:00
) ;
2016-01-29 16:59:09 -08:00
}
break ;
case ResourceFileType . Resources :
using ( var outputStream = outputResourceFile . File . Create ( ) )
{
2016-02-16 10:57:11 -08:00
if ( inputResourceFiles . Length > 1 )
2016-01-29 16:59:09 -08:00
{
Reporter . Error . WriteLine ( "Only one input file required when generating .resource output" ) ;
return 1 ;
}
2016-02-16 10:57:11 -08:00
ResourcesFileGenerator . Generate ( inputResourceFiles . Single ( ) . Resource , outputStream ) ;
2016-01-29 16:59:09 -08:00
}
break ;
default :
Reporter . Error . WriteLine ( "Resx output type not supported" ) ;
return 1 ;
}
return 0 ;
}
private static ResourceSource ParseInputFile ( string arg )
{
2016-02-16 10:57:11 -08:00
var separatorIndex = arg . IndexOf ( ',' ) ;
2016-01-29 16:59:09 -08:00
string name ;
string metadataName ;
2016-02-16 10:57:11 -08:00
if ( separatorIndex > 0 )
2016-01-29 16:59:09 -08:00
{
2016-02-16 10:57:11 -08:00
name = arg . Substring ( 0 , separatorIndex ) ;
metadataName = arg . Substring ( separatorIndex + 1 ) ;
2016-01-29 16:59:09 -08:00
}
else
{
name = arg ;
metadataName = arg ;
}
return new ResourceSource ( ResourceFile . Create ( name ) , metadataName ) ;
}
}
}