Skip to content

Commit a7d896c

Browse files
committed
* Added ability to export to JSON
1 parent fffde2a commit a7d896c

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

PK Finder/Classes/ExportManager.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ internal ExportManager(KeyInfo keyInfo)
3333
/// <param name="content">The content that should be stored in the file</param>
3434
private static void Export(string path, string content)
3535
{
36-
using (StreamWriter sw = new StreamWriter(path))
37-
{
38-
sw.Write(content);
39-
}
36+
using StreamWriter sw = new StreamWriter(path);
37+
sw.Write(content);
4038
}
4139

4240
/// <summary>
4341
/// Export the KeyInfo object to a storage device in plain text format
4442
/// </summary>
45-
/// <param name="path">The path where the KeyInfo object can be stored in plain text format</param>
43+
/// <param name="path">The path where the KeyInfo object should be stored in plain text format</param>
4644
internal void ExportToTxt(string path)
4745
{
4846
string content = "Product name: " + _keyInfo.GetProductName() + Environment.NewLine + "Product key: " +
@@ -53,7 +51,7 @@ internal void ExportToTxt(string path)
5351
/// <summary>
5452
/// Export the KeyInfo object to a storage device in CSV format
5553
/// </summary>
56-
/// <param name="path">The path where the KeyInfo object can be stored in CSV format</param>
54+
/// <param name="path">The path where the KeyInfo object should be stored in CSV format</param>
5755
internal void ExportToCsv(string path)
5856
{
5957
ExportDelimiter(path, ",");
@@ -62,16 +60,27 @@ internal void ExportToCsv(string path)
6260
/// <summary>
6361
/// Export the KeyInfo object to a storage device in CSV format using the Excel delimiter
6462
/// </summary>
65-
/// <param name="path">The path where the KeyInfo object can be stored in CSV format using the Excel delimiter</param>
63+
/// <param name="path">The path where the KeyInfo object should be stored in CSV format using the Excel delimiter</param>
6664
internal void ExportToExcel(string path)
6765
{
6866
ExportDelimiter(path, ";");
6967
}
68+
69+
/// <summary>
70+
/// Export the KeyInfo object to a storage device in JSON format
71+
/// </summary>
72+
/// <param name="path">The path where the KeyInfo object should be stored in JSON format</param>
73+
internal void ExportToJson(string path)
74+
{
75+
string content = "{\"productName\":\"" + _keyInfo.GetProductName() + "\",\"productKey\":\"" +
76+
_keyInfo.GetProductKey() + "\"}";
77+
Export(path, content);
78+
}
7079

7180
/// <summary>
7281
/// Export the KeyInfo object to a storage device using a specific delimiter character
7382
/// </summary>
74-
/// <param name="path">The path where the KeyInfo object can be stored</param>
83+
/// <param name="path">The path where the KeyInfo object should be stored</param>
7584
/// <param name="delimiter">The delimiter that should be used to split the data</param>
7685
private void ExportDelimiter(string path, string delimiter)
7786
{
@@ -83,12 +92,11 @@ private void ExportDelimiter(string path, string delimiter)
8392
/// <summary>
8493
/// Export the KeyInfo object to a storage device in HTML format
8594
/// </summary>
86-
/// <param name="path">The path where the KeyInfo object can be stored in HTML format</param>
95+
/// <param name="path">The path where the KeyInfo object should be stored in HTML format</param>
8796
internal void ExportToHtml(string path)
88-
{
89-
string content =
90-
"<html><head><title>PK Finder</title></head><body><table border='1'><tr><th>Product name</th><th>Product key</th></tr><tr><td>" +
91-
_keyInfo.GetProductName() + "</td><td>" + _keyInfo.GetProductKey() + "</td></tr></table></body></html>";
97+
{
98+
string content = "<html><head><meta charset=\"UTF-8\"><title>PK Finder</title></head><body><table border='1'><tbody><tr><th>Product name</th><th>Product key</th></tr><tr><td>" +
99+
_keyInfo.GetProductName() + "</td><td>" + _keyInfo.GetProductKey() + "</td></tr></tbody></table></body></html>";
92100
Export(path, content);
93101
}
94102
}

PK Finder/Windows/MainWindow.xaml.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private void ExportItem_OnClick(object sender, RoutedEventArgs e)
158158
if (_keyInfo == null) return;
159159

160160
SaveFileDialog sfd = new SaveFileDialog
161-
{Filter = "Text file (*.txt)|*.txt|HTML (*.html)|*.html|CSV (*.csv)|*.csv|Excel (*.csv)|*.csv"};
161+
{Filter = "Text file (*.txt)|*.txt|HTML (*.html)|*.html|CSV (*.csv)|*.csv|Excel (*.csv)|*.csv|JSON (*.json)|*.json"};
162162
ExportManager exportManager = new ExportManager(_keyInfo);
163163

164164
if (sfd.ShowDialog() != true) return;
@@ -178,6 +178,9 @@ private void ExportItem_OnClick(object sender, RoutedEventArgs e)
178178
case 4:
179179
exportManager.ExportToExcel(sfd.FileName);
180180
break;
181+
case 5:
182+
exportManager.ExportToJson(sfd.FileName);
183+
break;
181184
}
182185

183186
MessageBox.Show("Key exported!", "PK Finder", MessageBoxButton.OK, MessageBoxImage.Information);

0 commit comments

Comments
 (0)