Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d20a51c

Browse files
author
Ziga P
committedSep 12, 2019
Error handling + autodecode loaded JSON files
1 parent 0d64243 commit d20a51c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed
 

‎LogiTackerGUI/Form1.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ private void ButtonImportJson_Click(object sender,EventArgs e) {
293293

294294
listView1.Items.Clear();
295295
frameList.Clear();
296+
textBoxKeys.Text = "";
296297

297298
OpenFileDialog openFileDialog = new OpenFileDialog();
298299
openFileDialog.Filter = "JSON files (*.json)|*.json";
@@ -302,12 +303,27 @@ private void ButtonImportJson_Click(object sender,EventArgs e) {
302303
return;
303304

304305
List<AirFrameJSON> inputBuffer;
305-
using(StreamReader file = new StreamReader(openFileDialog.FileName))
306-
inputBuffer = new JavaScriptSerializer().Deserialize<List<AirFrameJSON>>(file.ReadToEnd());
306+
using(StreamReader file = new StreamReader(openFileDialog.FileName)) {
307+
try {
308+
inputBuffer = new JavaScriptSerializer().Deserialize<List<AirFrameJSON>>(file.ReadToEnd());
309+
} catch {
310+
MessageBox.Show("Invalid JSON file!","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
311+
return;
312+
}
313+
}
314+
315+
KeyboardLayout us_keyboard = new KeyboardLayout();
307316

308317
foreach(AirFrameJSON item in inputBuffer) {
309318
listView1.Items.Insert(0,new ListViewItem(new[] { item.Address,item.PID.ToString(),item.Ch.ToString(),item.Length.ToString(),item.Payload,item.DecryptedPayload }));
310-
frameList.Add(new AirFrame(item));
319+
320+
AirFrame af = new AirFrame(item);
321+
frameList.Add(af);
322+
323+
if(af.decryptedPayload == null || af.decryptedPayload.Length == 0)
324+
continue;
325+
326+
textBoxKeys.Text += us_keyboard.ToComboKeyPress(af.decryptedPayload);
311327
}
312328

313329
}

0 commit comments

Comments
 (0)
Please sign in to comment.