summaryrefslogtreecommitdiff
path: root/windows
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-10-26 18:08:44 -0700
committerGrant Limberg <glimberg@gmail.com>2015-10-26 18:08:44 -0700
commita0c3083af0821db0303c62dfae9ebc560c3c147a (patch)
treebe15d0bd03fa973c8bf474bd0085f1bc1d6eb447 /windows
parent55dcf4c65f7876a38e947b808449d4014c43ff17 (diff)
downloadinfinitytier-a0c3083af0821db0303c62dfae9ebc560c3c147a.tar.gz
infinitytier-a0c3083af0821db0303c62dfae9ebc560c3c147a.zip
disallow paste of non hex characters
Diffstat (limited to 'windows')
-rw-r--r--windows/WinUI/MainWindow.xaml.cs20
1 files changed, 18 insertions, 2 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs
index 3e00255c..afe6947c 100644
--- a/windows/WinUI/MainWindow.xaml.cs
+++ b/windows/WinUI/MainWindow.xaml.cs
@@ -22,6 +22,8 @@ namespace WinUI
public partial class MainWindow : Window
{
APIHandler handler = new APIHandler();
+ Regex charRegex = new Regex("[0-9a-fxA-FX]");
+ Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
public MainWindow()
{
@@ -29,6 +31,8 @@ namespace WinUI
updateStatus();
updateNetworks();
+
+ DataObject.AddPastingHandler(joinNetworkID, OnPaste);
}
private void updateStatus()
@@ -61,8 +65,20 @@ namespace WinUI
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
{
- Regex regex = new Regex("[0-9a-fxA-FX]");
- e.Handled = !regex.IsMatch(e.Text);
+ e.Handled = !charRegex.IsMatch(e.Text);
+ }
+
+ private void OnPaste(object sender, DataObjectPastingEventArgs e)
+ {
+ var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
+ if (!isText) return;
+
+ var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
+
+ if (!wholeStringRegex.IsMatch(text))
+ {
+ e.CancelCommand();
+ }
}
}
}