diff --git a/TuyaKeyExtractor/KeyExtract.cs b/TuyaKeyExtractor/KeyExtract.cs
index 4ac6ca7..4fb797e 100644
--- a/TuyaKeyExtractor/KeyExtract.cs
+++ b/TuyaKeyExtractor/KeyExtract.cs
@@ -4,6 +4,8 @@
using System.IO;
using System.Linq;
using System.Xml;
+using System.Text.RegularExpressions;
+using System.Web;
namespace TuyaKeyExtractor
{
@@ -14,64 +16,37 @@ namespace TuyaKeyExtractor
public class KeyExtract
{
// public string search;
- static readonly char[] delimiterChars = new[] { ',', '.', ':' };
+ static readonly char[] delimiterChars = new[] { ',', '.', ':', '?', '$', '[', '=', '*' };
- ///
- /// Parse the given data file and extract keys from it.
- ///
- /// The path to the XML file
- ///
- private IList ParseXmlFile ( string path )
+ public IList ParseXmlFile(string path)
{
- XmlDocument xmlDoc = new XmlDocument ();
- try
- {
- xmlDoc.Load ( path );
- var s = xmlDoc.InnerText;
-
- string[] words = s.Split ( delimiterChars );
-
- var keys = new List ();
- // var cleanList = new List ();
-
- int i = 0;
- ExtractedKey key = new ExtractedKey ();
- foreach ( var word in words )
- {
- i++;
-
- if ( word == "\"localKey\"" )
- {
- var replace = words[i].Replace ( "\"", "" );
- key.LocalKey = replace;
- }
-
- if ( word == "\"devId\"" )
- {
- var replace = words[i].Replace ( "\"", "" );
- key.DeviceID = replace;
- }
-
- if ( word == "\"name\"" )
- {
- var replace = words[i].Replace ( "\"", "" );
- key.DeviceName = replace;
-
- if ( key.LocalKey != null && key.DeviceName != null )
- {
- keys.Add ( key );
- key = new ExtractedKey ();
- }
- }
- }
-
- return keys;
- }
- catch ( System.IO.FileNotFoundException )
- {
- Console.WriteLine ( $"ERROR - It looks like your entered Path: \"{path}\" isn't valid. Try setting it again.\n\n" );
- }
- return null;
+ try
+ {
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.Load(path);
+ var xmlText = xmlDoc.InnerXml;
+
+ var localKeyMatches = Regex.Matches(xmlText, "\"localKey\"\\s*:\\s*\"([^\"]+)\"");
+ var devIdMatches = Regex.Matches(xmlText, "\"devId\"\\s*:\\s*\"([^\"]+)\"");
+ var nameMatches = Regex.Matches(xmlText, "\"name\"\\s*:\\s*\"([^\"]+)\"");
+
+ var keys = new List();
+ for (int i = 0; i < localKeyMatches.Count; i++)
+ {
+ var localKey = HttpUtility.HtmlDecode(localKeyMatches[i].Groups[1].Value);
+ var devId = HttpUtility.HtmlDecode(devIdMatches[i].Groups[1].Value);
+ var name = HttpUtility.HtmlDecode(nameMatches[i].Groups[1].Value);
+
+ keys.Add(new ExtractedKey { LocalKey = localKey, DeviceID = devId, DeviceName = name });
+ }
+
+ return keys;
+ }
+ catch (FileNotFoundException)
+ {
+ Console.WriteLine($"ERROR - It looks like your entered Path: \"{path}\" isn't valid. Try setting it again.\n\n");
+ }
+ return null;
}
///
diff --git a/TuyaKeyExtractor/TuyaKeyExtractor.csproj b/TuyaKeyExtractor/TuyaKeyExtractor.csproj
index c7f9421..82d0bde 100644
--- a/TuyaKeyExtractor/TuyaKeyExtractor.csproj
+++ b/TuyaKeyExtractor/TuyaKeyExtractor.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.1
+ netcoreapp8.0
6.ico
1.0.0.0
1.0.0.0