Set to LF line endings.
This commit is contained in:
parent
046475f7ab
commit
7371ed764d
|
@ -96,9 +96,9 @@ namespace ColorTool
|
|||
if (tableStrings[i].Length <= 0)
|
||||
{
|
||||
success = false;
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(string.Format(Resources.IniParseError, filename, name, tableStrings[i]));
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(string.Format(Resources.IniParseError, filename, name, tableStrings[i]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -116,22 +116,22 @@ namespace ColorTool
|
|||
}
|
||||
catch (Exception /*e*/)
|
||||
{
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(string.Format(Resources.IniLoadError, filename));
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(string.Format(Resources.IniLoadError, filename));
|
||||
}
|
||||
|
||||
colorTable = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (colorTable != null)
|
||||
{
|
||||
return new ColorScheme { colorTable = colorTable };
|
||||
if (colorTable != null)
|
||||
{
|
||||
return new ColorScheme { colorTable = colorTable };
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using static ColorTool.ConsoleAPI;
|
||||
|
||||
namespace ColorTool
|
||||
{
|
||||
class JsonParser : ISchemeParser
|
||||
{
|
||||
|
||||
namespace ColorTool
|
||||
{
|
||||
class JsonParser : ISchemeParser
|
||||
{
|
||||
static string[] CONCFG_COLOR_NAMES = {
|
||||
"black", // DARK_BLACK
|
||||
"dark_blue", // DARK_BLUE
|
||||
|
@ -29,64 +29,64 @@ namespace ColorTool
|
|||
"magenta", // BRIGHT_MAGENTA
|
||||
"yellow", // BRIGHT_YELLOW
|
||||
"white" // BRIGHT_WHITE
|
||||
};
|
||||
|
||||
public string Name => "concfg Parser";
|
||||
|
||||
static uint ParseColor(string arg)
|
||||
{
|
||||
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml(arg);
|
||||
return RGB(col.R, col.G, col.B);
|
||||
}
|
||||
|
||||
static XmlDocument loadJsonFile(string schemeName)
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
foreach (string path in Scheme.GetSearchPaths(schemeName, ".json")
|
||||
.Where(File.Exists))
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = File.ReadAllBytes(path);
|
||||
var reader = JsonReaderWriterFactory.CreateJsonReader(data, System.Xml.XmlDictionaryReaderQuotas.Max);
|
||||
xmlDoc.Load(reader);
|
||||
return xmlDoc;
|
||||
}
|
||||
};
|
||||
|
||||
public string Name => "concfg Parser";
|
||||
|
||||
static uint ParseColor(string arg)
|
||||
{
|
||||
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml(arg);
|
||||
return RGB(col.R, col.G, col.B);
|
||||
}
|
||||
|
||||
static XmlDocument loadJsonFile(string schemeName)
|
||||
{
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
foreach (string path in Scheme.GetSearchPaths(schemeName, ".json")
|
||||
.Where(File.Exists))
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = File.ReadAllBytes(path);
|
||||
var reader = JsonReaderWriterFactory.CreateJsonReader(data, System.Xml.XmlDictionaryReaderQuotas.Max);
|
||||
xmlDoc.Load(reader);
|
||||
return xmlDoc;
|
||||
}
|
||||
catch (XmlException /*e*/) { /* failed to parse */ }
|
||||
catch (IOException /*e*/) { /* failed to find */ }
|
||||
catch (UnauthorizedAccessException /*e*/) { /* unauthorized */ }
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ColorScheme ParseScheme(string schemeName, bool reportErrors = true)
|
||||
{
|
||||
XmlDocument xmlDoc = loadJsonFile(schemeName);
|
||||
if (xmlDoc == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
XmlNode root = xmlDoc.DocumentElement;
|
||||
XmlNodeList children = root.ChildNodes;
|
||||
uint[] colorTable = new uint[COLOR_TABLE_SIZE]; ;
|
||||
for (int i = 0; i < COLOR_TABLE_SIZE; i++)
|
||||
{
|
||||
string name = CONCFG_COLOR_NAMES[i];
|
||||
var node = children.OfType<XmlNode>().Where(n => n.Name == name).Single();
|
||||
colorTable[i] = ParseColor(node.InnerText);
|
||||
}
|
||||
return new ColorScheme { colorTable = colorTable };
|
||||
}
|
||||
catch (Exception /*e*/)
|
||||
{
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine("failes to load json scheme");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ColorScheme ParseScheme(string schemeName, bool reportErrors = true)
|
||||
{
|
||||
XmlDocument xmlDoc = loadJsonFile(schemeName);
|
||||
if (xmlDoc == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
XmlNode root = xmlDoc.DocumentElement;
|
||||
XmlNodeList children = root.ChildNodes;
|
||||
uint[] colorTable = new uint[COLOR_TABLE_SIZE]; ;
|
||||
for (int i = 0; i < COLOR_TABLE_SIZE; i++)
|
||||
{
|
||||
string name = CONCFG_COLOR_NAMES[i];
|
||||
var node = children.OfType<XmlNode>().Where(n => n.Name == name).Single();
|
||||
colorTable[i] = ParseColor(node.InnerText);
|
||||
}
|
||||
return new ColorScheme { colorTable = colorTable };
|
||||
}
|
||||
catch (Exception /*e*/)
|
||||
{
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine("failes to load json scheme");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,9 +124,9 @@ namespace ColorTool
|
|||
}
|
||||
if (colorsFound < COLOR_TABLE_SIZE)
|
||||
{
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(Resources.InvalidNumberOfColors);
|
||||
if (reportErrors)
|
||||
{
|
||||
Console.WriteLine(Resources.InvalidNumberOfColors);
|
||||
}
|
||||
success = false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue