From 6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 14:54:55 -0800 Subject: starts up to a toolbar icon with context menu. still much more to do --- windows/WinUI/MainWindow.xaml.cs | 97 +++++++--------------------------------- 1 file changed, 15 insertions(+), 82 deletions(-) (limited to 'windows/WinUI/MainWindow.xaml.cs') 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() { -- cgit v1.2.3