Skip to content

Commit 7b85499

Browse files
committed
Update V0.03
+ Added Link for MarkWattTech Facebook Group + Added .csv Exporting + Added .txt Exporting + Added string cleaning (You can paste sting sourounded by quoutes - handy when using copy from file)
1 parent be64983 commit 7b85499

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed

TuyaKeyExtractor/ExtractedKey.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ namespace TuyaKeyExtractor
1313
///
1414
public class ExtractedKey
1515
{
16+
public ExtractedKey()
17+
{
18+
19+
}
20+
21+
public ExtractedKey(string deviceName, string localKey, string deviceId)
22+
{
23+
this.DeviceName = deviceName;
24+
this.LocalKey = localKey;
25+
this.DeviceID = deviceId;
26+
}
27+
1628
/// <summary>
1729
/// The name of the Device as listed in the Smart Life App.
1830
/// </summary>

TuyaKeyExtractor/KeyExtract.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using ConsoleTables;
22
using System;
33
using System.Collections.Generic;
4+
using System.IO;
45
using System.Linq;
56
using System.Xml;
67

@@ -29,6 +30,7 @@ public void ReadXml(string path, int option)
2930
string[] words = s.Split(delimiterChars);
3031

3132
List<ExtractedKey> keys = new List<ExtractedKey>();
33+
List<ExtractedKey> cleanList = new List<ExtractedKey>();
3234

3335
int i = 0;
3436
ExtractedKey key = new ExtractedKey();
@@ -107,6 +109,57 @@ public void ReadXml(string path, int option)
107109
}
108110
}
109111
}
112+
113+
// Generate .CSV List
114+
if (option == 4)
115+
{
116+
CleanList(keys, cleanList);
117+
118+
try
119+
{
120+
File.WriteAllLines("Tuya Local Keys.csv", cleanList.Select(x => string.Join(",", x.DeviceName, x.DeviceID, x.LocalKey)));
121+
Console.WriteLine("Successfully Generated Tuya Local Keys.csv");
122+
}
123+
catch(System.IO.IOException ie)
124+
{
125+
Console.WriteLine("ERROR - Can't update the File as it is in use. Have you got it open?\n\n" + ie.Message);
126+
}
127+
catch(Exception e)
128+
{
129+
Console.WriteLine(e.Message);
130+
}
131+
}
132+
133+
// Generate .txt
134+
if (option == 5)
135+
{
136+
CleanList(keys, cleanList);
137+
138+
try
139+
{
140+
File.WriteAllLines("Tuya Local Keys.txt", cleanList.Select(x => string.Join(",", x.DeviceName, x.DeviceID, x.LocalKey)));
141+
Console.WriteLine("Successfully Generated Tuya Local Keys.txt");
142+
}
143+
catch (System.IO.IOException ie)
144+
{
145+
Console.WriteLine("ERROR - Can't update the File as it is in use. Have you got it open?\n\n" + ie.Message);
146+
}
147+
catch (Exception e)
148+
{
149+
Console.WriteLine(e.Message);
150+
}
151+
}
152+
}
153+
154+
public void CleanList(List<ExtractedKey> inputList, List<ExtractedKey> outputList)
155+
{
156+
foreach (ExtractedKey k in inputList)
157+
{
158+
if (k.DeviceID != null && k.DeviceName != null && k.LocalKey != null)
159+
{
160+
outputList.Add(new ExtractedKey(k.DeviceName, k.LocalKey, k.DeviceID));
161+
}
162+
}
110163
}
111164
}
112165
}

TuyaKeyExtractor/Menu.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void InitialiseMenu()
3232
public void MenuEntry(string menutext, List<string> menuOptions, int menuToDisplay)
3333
{
3434
ClearConsole();
35-
Console.Title = $"Mark Watt Tech - Tuya Key Extractor (v0.02)";
35+
Console.Title = $"Mark Watt Tech - Tuya Key Extractor (v0.03)";
3636
Print.DisplayMenu(menuToDisplay);
3737
if (string.IsNullOrEmpty(menutext))
3838
{
@@ -68,7 +68,8 @@ public void ProcessInput(string input)
6868

6969
case "1":
7070
Console.WriteLine("Enter the file path for the Preference.xml file (e.g. C:\\Users\\MarkWattTech\\Desktop\\Preference.xml)");
71-
Print.configFilePath = Console.ReadLine();
71+
string readIn = Console.ReadLine();
72+
Print.configFilePath = readIn.Replace("\"", string.Empty).Replace("'", string.Empty);
7273

7374
if (Print.configFilePath == "" || Print.configFilePath == null)
7475
{
@@ -136,7 +137,32 @@ public void ProcessInput(string input)
136137

137138
break;
138139

139-
// Subscribe to Mark Watt Tech
140+
// Generate .CSV File
141+
case "5":
142+
if (Print.pathSet == false)
143+
{
144+
pathError();
145+
}
146+
else
147+
{
148+
extract.ReadXml(Print.configFilePath, 4);
149+
}
150+
break;
151+
152+
// Generate .TXT file
153+
case "6":
154+
if (Print.pathSet == false)
155+
{
156+
pathError();
157+
}
158+
else
159+
{
160+
extract.ReadXml(Print.configFilePath, 5);
161+
}
162+
break;
163+
164+
165+
// Subscribe to Mark Watt Tech
140166
case "S":
141167
UrlOpener("http://www.youtube.com/channel/UCQRm_z7seHnGsBiWDNEWr6A?sub_confirmation=1");
142168
break;
@@ -148,7 +174,11 @@ public void ProcessInput(string input)
148174
case "F":
149175
UrlOpener("https://www.facebook.com/MarkWattTech");
150176
break;
151-
// Reddit
177+
// Facebook Group
178+
case "FF":
179+
UrlOpener("hhttps://www.facebook.com/groups/2963936147172102/");
180+
break;
181+
// Reddit
152182
case "R":
153183
UrlOpener("https://www.reddit.com/r/MarkWattTech/");
154184
break;
@@ -179,6 +209,10 @@ public void ProcessInput(string input)
179209
System.Environment.Exit(0);
180210
break;
181211

212+
case "T":
213+
extract.ReadXml(Print.configFilePath, 4);
214+
break;
215+
182216
default:
183217

184218
ClearConsole();

TuyaKeyExtractor/MenuPrint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ private void BuildMenu()
3232
MenuOptions.Add( " 2 - Print All Keys | ");
3333
MenuOptions.Add( " 3 - Print All Keys Fancy | ");
3434
MenuOptions.Add( " 4 - Print Key by ID | ");
35+
MenuOptions.Add( " 5 - Generate .CSV | ");
36+
MenuOptions.Add( " 6 - Generate .TXT | ");
3537
MenuOptions.Add( " E - Extras | ");
3638
MenuOptions.Add( " S - SUBSCRIBE TO MarkWattTech | ");
3739
MenuOptions.Add( " Q - Quit |");
@@ -55,6 +57,7 @@ private void BuildAllCommands()
5557
AllCommands.Add(" Links for all My Socials |");
5658
AllCommands.Add(" I - Instagram | ");
5759
AllCommands.Add(" F - Facebook | ");
60+
AllCommands.Add(" FF - Facebook Group | ");
5861
AllCommands.Add(" R - Reddit | ");
5962
AllCommands.Add(" G - GitHub for this Tool | ");
6063
AllCommands.Add(" | ");

0 commit comments

Comments
 (0)