Fixed issue #96.

Added a small application to fix future issues with embedded escape codes.
Also fixed some encoding issues with the pt-BR files.

git-svn-id: https://duplicati.googlecode.com/svn/trunk@298 59da171f-624f-0410-aa54-27559c288bec
This commit is contained in:
kenneth.skovhede@gmail.com
2009-09-26 09:43:02 +00:00
parent 5a75ae0ef6
commit 5010e4f094
44 changed files with 385 additions and 72 deletions
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ResXEscapeCodeFixer
{
class Program
{
static void Main(string[] args)
{
string startpath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (args.Length >= 1)
startpath = args[0];
Console.WriteLine("Root folder is: {0}", startpath);
Queue<string> folders = new Queue<string>();
folders.Enqueue(startpath);
while (folders.Count > 0)
{
string folder = folders.Dequeue();
Console.WriteLine("Processing folder: {0}", folder);
foreach (string s in Directory.GetDirectories(folder))
folders.Enqueue(s);
foreach (string s in Directory.GetFiles(folder, "*.resx"))
FixUpResX(s);
}
}
static void FixUpResX(string file)
{
bool modified = false;
Console.WriteLine("Examining file: {0}", Path.GetFileName(file));
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(file);
foreach (System.Xml.XmlNode n in doc.SelectNodes("root/data"))
{
//TODO: Make sure that xml:space="preserve" is present
System.Xml.XmlNode value = n["value"];
if (value != null)
{
if (value.InnerText.IndexOf('\\') > 0)
{
string newvalue = value.InnerText
.Replace("\\r\\n", "\r\n")
.Replace("\\n", "\r\n")
.Replace("\\r", "\r")
.Replace("\\t", "\t")
.Replace("\\\"", "\"");
if (newvalue != value.InnerText)
{
Console.WriteLine("Replacing: \r\n\t{0}\r\n\t{1}", value.InnerText, newvalue);
value.InnerText = newvalue;
modified = true;
}
}
}
}
if (modified)
doc.Save(file);
}
}
}