commit
389781592e
1 changed files with 23 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// 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.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
using Microsoft.Dnx.Runtime.Common.CommandLine;
|
||||||
|
@ -26,32 +28,42 @@ namespace Microsoft.DotNet.Tools.Resgen
|
||||||
|
|
||||||
app.OnExecute(() =>
|
app.OnExecute(() =>
|
||||||
{
|
{
|
||||||
WriteResourcesFile(inputFile.Value, outputFile.Value);
|
WriteResourcesFileIfNotEmpty(inputFile.Value, outputFile.Value);
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
return app.Execute(args);
|
return app.Execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WriteResourcesFile(string resxFilePath, string outputFile)
|
private static void WriteResourcesFileIfNotEmpty(string resxFilePath, string outputFile)
|
||||||
{
|
{
|
||||||
using (var fs = File.OpenRead(resxFilePath))
|
using (var fs = File.OpenRead(resxFilePath))
|
||||||
using (var outfs = File.Create(outputFile))
|
using (var outfs = File.Create(outputFile))
|
||||||
{
|
{
|
||||||
var document = XDocument.Load(fs);
|
var document = XDocument.Load(fs);
|
||||||
|
|
||||||
var rw = new ResourceWriter(outfs);
|
var data = document.Root.Elements("data");
|
||||||
|
|
||||||
foreach (var e in document.Root.Elements("data"))
|
if (data.Any())
|
||||||
{
|
{
|
||||||
string name = e.Attribute("name").Value;
|
WriteResourcesFile(outfs, data);
|
||||||
string value = e.Element("value").Value;
|
|
||||||
|
|
||||||
rw.AddResource(name, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rw.Generate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void WriteResourcesFile(Stream outfs, IEnumerable<XElement> data)
|
||||||
|
{
|
||||||
|
var rw = new ResourceWriter(outfs);
|
||||||
|
|
||||||
|
foreach (var e in data)
|
||||||
|
{
|
||||||
|
var name = e.Attribute("name").Value;
|
||||||
|
var value = e.Element("value").Value;
|
||||||
|
|
||||||
|
rw.AddResource(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.Generate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue