You've already forked linux-packaging-mono
Imported Upstream version 5.4.0.167
Former-commit-id: 5624ac747d633e885131e8349322922b6a59baaa
This commit is contained in:
parent
e49d6f06c0
commit
536cd135cc
11
mcs/tools/resx2sr/Makefile
Normal file
11
mcs/tools/resx2sr/Makefile
Normal file
@@ -0,0 +1,11 @@
|
||||
thisdir = tools/resx2sr
|
||||
SUBDIRS =
|
||||
include ../../build/rules.make
|
||||
|
||||
PROGRAM = resx2sr.exe
|
||||
NO_INSTALL = yes
|
||||
|
||||
LIB_REFS = System System.Drawing System.Xml
|
||||
LOCAL_MCS_FLAGS = -unsafe
|
||||
|
||||
include ../../build/executable.make
|
159
mcs/tools/resx2sr/resx2sr.cs
Normal file
159
mcs/tools/resx2sr/resx2sr.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
//
|
||||
// resx2sr.cs
|
||||
//
|
||||
// Authors:
|
||||
// Marek Safar <marek.safar@gmail.com>
|
||||
//
|
||||
// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Resources;
|
||||
using System.ComponentModel.Design;
|
||||
using Mono.Options;
|
||||
|
||||
public class Program
|
||||
{
|
||||
class CmdOptions
|
||||
{
|
||||
public bool ShowHelp { get; set; }
|
||||
public string OutputFile { get; set; }
|
||||
}
|
||||
|
||||
public static int Main (string[] args)
|
||||
{
|
||||
var options = new CmdOptions ();
|
||||
|
||||
var p = new OptionSet () {
|
||||
{ "o|out=", "Specifies output file name",
|
||||
v => options.OutputFile = v },
|
||||
{ "h|help", "Display available options",
|
||||
v => options.ShowHelp = v != null },
|
||||
};
|
||||
|
||||
List<string> extra;
|
||||
try {
|
||||
extra = p.Parse (args);
|
||||
} catch (OptionException e) {
|
||||
Console.WriteLine (e.Message);
|
||||
Console.WriteLine ("Try 'resx2sr -help' for more information.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (options.ShowHelp) {
|
||||
ShowHelp (p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (extra.Count < 1) {
|
||||
ShowHelp (p);
|
||||
return 2;
|
||||
}
|
||||
|
||||
var resxStrings = new List<Tuple<string, string, string>> ();
|
||||
if (!LoadStrings (resxStrings, extra))
|
||||
return 3;
|
||||
|
||||
GenerateFile (resxStrings, options);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ShowHelp (OptionSet p)
|
||||
{
|
||||
Console.WriteLine ("Usage: resx2sr [options] input-files");
|
||||
Console.WriteLine ("Generates C# file with string constants from resource file");
|
||||
Console.WriteLine ();
|
||||
Console.WriteLine ("Options:");
|
||||
p.WriteOptionDescriptions (Console.Out);
|
||||
}
|
||||
|
||||
static void GenerateFile (List<Tuple<string, string, string>> txtStrings, CmdOptions options)
|
||||
{
|
||||
// var outputFile = options.OutputFile ?? "SR.cs";
|
||||
|
||||
using (var str = options.OutputFile == null ? Console.Out : new StreamWriter (options.OutputFile)) {
|
||||
str.WriteLine ("//");
|
||||
str.WriteLine ("// This file was generated by resx2sr tool");
|
||||
str.WriteLine ("//");
|
||||
str.WriteLine ();
|
||||
|
||||
str.WriteLine ("partial class SR");
|
||||
str.WriteLine ("{");
|
||||
|
||||
var dict = new Dictionary<string, string> ();
|
||||
|
||||
foreach (var entry in txtStrings) {
|
||||
|
||||
var value = ToCSharpString (entry.Item2);
|
||||
string found;
|
||||
if (dict.TryGetValue (entry.Item1, out found)) {
|
||||
if (found == value)
|
||||
continue;
|
||||
|
||||
str.WriteLine ($"\t// Constant value mismatch");
|
||||
} else {
|
||||
dict.Add (entry.Item1, value);
|
||||
}
|
||||
|
||||
str.Write ($"\tpublic const string {entry.Item1} = \"{value}\";");
|
||||
|
||||
if (!string.IsNullOrEmpty (entry.Item3))
|
||||
str.Write (" // {entry.Item3}");
|
||||
|
||||
str.WriteLine ();
|
||||
}
|
||||
str.WriteLine ("}");
|
||||
}
|
||||
}
|
||||
|
||||
static string ToCSharpString (string str)
|
||||
{
|
||||
str = str.Replace ("\n", "\\n");
|
||||
|
||||
return str.Replace ("\\", "\\\\").Replace ("\"", "\\\"");
|
||||
}
|
||||
|
||||
static bool LoadStrings (List<Tuple<string, string, string>> resourcesStrings, List<string> files)
|
||||
{
|
||||
var keys = new Dictionary<string, string> ();
|
||||
foreach (var fileName in files) {
|
||||
if (!File.Exists (fileName)) {
|
||||
Console.Error.WriteLine ($"Error reading resource file '{fileName}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
var rr = new ResXResourceReader (fileName);
|
||||
rr.UseResXDataNodes = true;
|
||||
var dict = rr.GetEnumerator ();
|
||||
while (dict.MoveNext ()) {
|
||||
var node = (ResXDataNode)dict.Value;
|
||||
|
||||
resourcesStrings.Add (Tuple.Create (node.Name, (string) node.GetValue ((ITypeResolutionService)null), node.Comment));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
21
mcs/tools/resx2sr/resx2sr.exe.sources
Normal file
21
mcs/tools/resx2sr/resx2sr.exe.sources
Normal file
@@ -0,0 +1,21 @@
|
||||
../../build/common/MonoTODOAttribute.cs
|
||||
resx2sr.cs
|
||||
../../class/Mono.Options/Mono.Options/Options.cs
|
||||
../../class/System.Windows.Forms/System.Resources/AssemblyNamesTypeResolutionService.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXDataNode.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXResourceSet.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ByteArrayFromResXHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXDataNodeHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXResourceWriter.cs
|
||||
../../class/System.Windows.Forms/System.Resources/FileRefHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXFileRef.cs
|
||||
../../class/System.Windows.Forms/System.Resources/SerializedFromResXHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/InMemoryHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXNullRef.cs
|
||||
../../class/System.Windows.Forms/System.Resources/TypeConverterFromResXHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/NullRefHandler.cs
|
||||
../../class/System.Windows.Forms/System.Resources/ResXResourceReader.cs
|
||||
../../class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapFormatter.cs
|
||||
../../class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapReader.cs
|
||||
../../class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapTypeMapper.cs
|
||||
../../class/System.Runtime.Serialization.Formatters.Soap/System.Runtime.Serialization.Formatters.Soap/SoapWriter.cs
|
Reference in New Issue
Block a user