summaryrefslogtreecommitdiff
path: root/windows/WinUI/MainWindow.xaml.cs
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-05 12:23:06 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-11-05 12:23:06 -0800
commit5ec5911e1bbed6e0dfd649f78b6b38afd181b5f1 (patch)
tree06a05b5f710ffd5ca359981bbcb887eeba9320f0 /windows/WinUI/MainWindow.xaml.cs
parent8ef4edebbfeead53e5b2b454086e21e42e809aab (diff)
parent86c74d8a65ae45d6ff0433da7d4d4acb6cba8fcb (diff)
downloadinfinitytier-5ec5911e1bbed6e0dfd649f78b6b38afd181b5f1.tar.gz
infinitytier-5ec5911e1bbed6e0dfd649f78b6b38afd181b5f1.zip
Merge branch 'edge' of http://10.6.6.2/zerotier/ZeroTierOne into edge
Diffstat (limited to 'windows/WinUI/MainWindow.xaml.cs')
-rw-r--r--windows/WinUI/MainWindow.xaml.cs109
1 files changed, 90 insertions, 19 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs
index f6cb4f44..535cb386 100644
--- a/windows/WinUI/MainWindow.xaml.cs
+++ b/windows/WinUI/MainWindow.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -23,45 +24,115 @@ namespace WinUI
/// </summary>
public partial class MainWindow : Window
{
- APIHandler handler = new APIHandler();
+ APIHandler handler;
Regex charRegex = new Regex("[0-9a-fxA-FX]");
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
Timer timer = new Timer();
+ bool connected = false;
+
public MainWindow()
{
InitializeComponent();
- networksPage.SetAPIHandler(handler);
+ if (InitAPIHandler())
+ {
+ networksPage.SetAPIHandler(handler);
- updateStatus();
- updateNetworks();
- updatePeers();
+ updateStatus();
+ if (!connected)
+ {
+ MessageBox.Show("Unable to connect to ZeroTier Service.");
+ }
+
+ updateNetworks();
+ updatePeers();
+
+ DataObject.AddPastingHandler(joinNetworkID, OnPaste);
+
+ timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer);
+ timer.Interval = 2000;
+ timer.Enabled = true;
+ }
+ }
+
+ private bool InitAPIHandler()
+ {
+ String ztDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One";
+ String authToken = "";
+ Int32 port = 9993;
+ try
+ {
+ byte[] tmp = File.ReadAllBytes(ztDir + "\\authtoken.secret");
+ authToken = System.Text.Encoding.ASCII.GetString(tmp).Trim();
+ }
+ catch
+ {
+ MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One");
+ this.Close();
+ return false;
+ }
- DataObject.AddPastingHandler(joinNetworkID, OnPaste);
+ if ((authToken == null) || (authToken.Length <= 0))
+ {
+ MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One");
+ this.Close();
+ return false;
+ }
+ try
+ {
+ byte[] tmp = File.ReadAllBytes(ztDir + "\\zerotier-one.port");
+ port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
+ if ((port <= 0) || (port > 65535))
+ port = 9993;
+ }
+ catch
+ {
+ }
- timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer);
- timer.Interval = 2000;
- timer.Enabled = true;
+ handler = new APIHandler(port, authToken);
+ return true;
}
private void updateStatus()
{
var status = handler.GetStatus();
- networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- this.networkId.Content = status.Address;
- }));
- versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ if (status != null)
{
- this.versionString.Content = status.Version;
- }));
- onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ connected = true;
+
+ networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.networkId.Content = status.Address;
+ }));
+ versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.versionString.Content = status.Version;
+ }));
+ onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE");
+ }));
+ }
+ else
{
- this.onlineStatus.Content = (status.Online ? "ONLINE" : "OFFLINE");
- }));
+ connected = false;
+
+ networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.networkId.Content = "";
+ }));
+ versionString.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.versionString.Content = "0";
+ }));
+ onlineStatus.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
+ {
+ this.onlineStatus.Content = "OFFLINE";
+ }));
+ }
}
private void updateNetworks()