Skip to content

Commit

Permalink
Generate signature late enough
Browse files Browse the repository at this point in the history
  • Loading branch information
BtbN committed Feb 16, 2019
1 parent a1ace0f commit 4d53fab
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
29 changes: 24 additions & 5 deletions FlagCarrierWin/Controls/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace FlagCarrierWin
/// </summary>
public partial class MainWindow : Window
{
Dictionary<string, string> dataToWrite;
NfcHandler nfcHandler;

public MainWindow()
Expand All @@ -27,13 +28,14 @@ public MainWindow()

nfcHandler = new NfcHandler();
nfcHandler.CardAdded += NfcHandler_CardAdded;
nfcHandler.CardRemoved += NfcHandler_CardRemoved;
nfcHandler.StatusMessage += StatusMessage;
nfcHandler.ErrorMessage += StatusMessage;
nfcHandler.ReceiveNdefMessage += NfcHandler_ReceiveNdefMessage;
nfcHandler.NewTagUid += NdefHandler.SetExtraSignData;
nfcHandler.NewTagUid += NfcHandler_NewTagUid;

writeControl.ManualLoginRequest += WriteControl_ManualLoginRequest;
writeControl.WriteMessageRequest += WriteControl_WriteMessageRequest;
writeControl.WriteDataRequest += WriteControl_WriteDataRequest;
writeControl.ErrorMessage += StatusMessage;

settingsControl.WriteToTagRequest += SettingsControl_WriteToTagRequest;
Expand All @@ -43,6 +45,22 @@ public MainWindow()
UpdatedSettings();
}

private void NfcHandler_CardRemoved(string name)
{
NdefHandler.ClearExtraSignData();
}

private void NfcHandler_NewTagUid(byte[] uid)
{
NdefHandler.SetExtraSignData(uid);

if (dataToWrite != null) {
var msg = NdefHandler.GenerateNdefMessage(dataToWrite);
nfcHandler.WriteNdefMessage(msg);
dataToWrite = null;
}
}

private void JumpToSettings(object sender, ExecutedRoutedEventArgs e)
{
mainTabControl.SelectedItem = settingsTab;
Expand Down Expand Up @@ -74,10 +92,11 @@ private void SettingsControl_WriteToTagRequest(Dictionary<string, string> settin
writeTab.IsSelected = true;
}

private void WriteControl_WriteMessageRequest(NdefMessage msg)
private void WriteControl_WriteDataRequest(Dictionary<string, string> msg)
{
nfcHandler.WriteNdefMessage(msg);
ClearOutput("Scan tag to write.");
dataToWrite = msg;
if (msg != null)
ClearOutput("Scan tag to write.");
}

private void WriteControl_ManualLoginRequest(Dictionary<string, string> data)
Expand Down
8 changes: 3 additions & 5 deletions FlagCarrierWin/Controls/WriteControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class WriteControl : UserControl
private TextBox lastChangedTextBox = null;

public event Action<Dictionary<string, string>> ManualLoginRequest;
public event Action<NdefMessage> WriteMessageRequest;
public event Action<Dictionary<string, string>> WriteDataRequest;
public event Action<string> ErrorMessage;

public WriteControl()
Expand Down Expand Up @@ -53,9 +53,7 @@ private void WriteButton_Click(object sender, RoutedEventArgs e)
if (data == null)
return;

var msg = NdefHandler.GenerateNdefMessage(data);

WriteMessageRequest?.Invoke(msg);
WriteDataRequest?.Invoke(data);
}

private void SendToLoginButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -211,7 +209,7 @@ private Dictionary<string, string> GetWriteData()

private void AnyBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox box = sender as TextBox;
var box = sender as TextBox;
if (box == null)
return;
lastChangedTextBox = box;
Expand Down

0 comments on commit 4d53fab

Please sign in to comment.