diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs
index 2968c963..92b83021 100644
--- a/windows/WinUI/APIHandler.cs
+++ b/windows/WinUI/APIHandler.cs
@@ -14,7 +14,7 @@ namespace WinUI
public class APIHandler
{
- static string authtoken = "p3ptrzds5jkr2hbx5ipbyf04"; // delete me!
+ private string authtoken;
private string url = null;
@@ -23,9 +23,10 @@ namespace WinUI
url = "http://127.0.0.1:9993";
}
- public APIHandler(string host, int port)
+ public APIHandler(int port, string authtoken)
{
- url = "http://" + host + ":" + port;
+ url = "http://localhost:" + port;
+ this.authtoken = authtoken;
}
public ZeroTierStatus GetStatus()
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs
index 103165b3..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,7 +24,7 @@ namespace WinUI
///
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]+$");
@@ -35,22 +36,63 @@ namespace WinUI
{
InitializeComponent();
- networksPage.SetAPIHandler(handler);
-
- updateStatus();
- if (!connected)
+ if (InitAPIHandler())
{
- MessageBox.Show("Unable to connect to ZeroTier Service.");
+ networksPage.SetAPIHandler(handler);
+
+ 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;
}
- updateNetworks();
- updatePeers();
+ 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
+ {
+ }
- DataObject.AddPastingHandler(joinNetworkID, OnPaste);
-
- timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer);
- timer.Interval = 2000;
- timer.Enabled = true;
+ handler = new APIHandler(port, authToken);
+ return true;
}
private void updateStatus()
diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj
index 5ebfedcf..c3eeaba4 100644
--- a/windows/WinUI/WinUI.csproj
+++ b/windows/WinUI/WinUI.csproj
@@ -63,6 +63,9 @@
false
+
+ app.manifest
+
@@ -161,6 +164,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
diff --git a/windows/WinUI/app.manifest b/windows/WinUI/app.manifest
new file mode 100644
index 00000000..b537bf49
--- /dev/null
+++ b/windows/WinUI/app.manifest
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+