summaryrefslogtreecommitdiff
path: root/windows/WinUI/MainWindow.xaml.cs
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-08 14:54:55 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-08 14:54:55 -0800
commit6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee (patch)
tree28dea243c77542335bf745882dd02e6c27b4e5eb /windows/WinUI/MainWindow.xaml.cs
parent54206fd44d5bda4b9fd0f5dacbaefdbe81e15b18 (diff)
downloadinfinitytier-6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee.tar.gz
infinitytier-6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee.zip
starts up to a toolbar icon with context menu. still much more to do
Diffstat (limited to 'windows/WinUI/MainWindow.xaml.cs')
-rw-r--r--windows/WinUI/MainWindow.xaml.cs97
1 files changed, 15 insertions, 82 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs
index 25534b46..a57ee4b9 100644
--- a/windows/WinUI/MainWindow.xaml.cs
+++ b/windows/WinUI/MainWindow.xaml.cs
@@ -36,102 +36,35 @@ namespace WinUI
public MainWindow()
{
InitializeComponent();
-
- if (InitAPIHandler())
- {
- 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 String readAuthToken(String path)
- {
- String authToken = "";
-
- if (File.Exists(path))
- {
- try
- {
- byte[] tmp = File.ReadAllBytes(path);
- authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim();
- }
- catch
- {
- MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One");
- }
- }
-
- return authToken;
- }
-
- private Int32 readPort(String path)
+ public void SetAPIHandler(APIHandler handler)
{
- Int32 port = 9993;
+ timer.Stop();
+ timer = new Timer();
- try
- {
- byte[] tmp = File.ReadAllBytes(path);
- port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
- if ((port <= 0) || (port > 65535))
- port = 9993;
- }
- catch
- {
- }
+ this.handler = handler;
- return port;
- }
+ networksPage.SetAPIHandler(handler);
- private bool InitAPIHandler()
- {
- String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One";
- String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One";
-
- String authToken = "";
- Int32 port = 9993;
+ updateStatus();
- if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port"))
+ if (!connected)
{
- // launch external process to copy file into place
- String curPath = System.Reflection.Assembly.GetEntryAssembly().Location;
- int index = curPath.LastIndexOf("\\");
- curPath = curPath.Substring(0, index);
- ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", globalZtDir + " " + localZtDir);
- startInfo.Verb = "runas";
-
-
- var process = Process.Start(startInfo);
- process.WaitForExit();
+ MessageBox.Show("Unable to connect to ZerOTier Service");
+ return;
}
- authToken = readAuthToken(localZtDir + "\\authtoken.secret");
+ updateNetworks();
- if ((authToken == null) || (authToken.Length <= 0))
- {
- MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One");
- this.Close();
- return false;
- }
+ DataObject.AddPastingHandler(joinNetworkID, OnPaste);
- port = readPort(localZtDir + "\\zerotier-one.port");
- handler = new APIHandler(port, authToken);
- return true;
+ timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer);
+ timer.Interval = 2000;
+ timer.Enabled = true;
}
+
private void updateStatus()
{