summaryrefslogtreecommitdiff
path: root/windows/WinUI/MainWindow.xaml.cs
diff options
context:
space:
mode:
authorGrant Limberg <grant.limberg@zerotier.com>2016-11-07 14:08:26 -0800
committerGrant Limberg <grant.limberg@zerotier.com>2016-11-07 14:09:01 -0800
commitc802811ad298d20315e358b0fc7964a16e591aa6 (patch)
treef6a34de8b2947f6ce73136de41e03ff2a014b2b3 /windows/WinUI/MainWindow.xaml.cs
parent5f63d5039bcca80241b12655c250a4238b936a74 (diff)
downloadinfinitytier-c802811ad298d20315e358b0fc7964a16e591aa6.tar.gz
infinitytier-c802811ad298d20315e358b0fc7964a16e591aa6.zip
Added a file copy util for Windows UI
Copies the authtoken.secret file into a private local folder for the user so that the UI doesnt have to be run with Admin privileges.
Diffstat (limited to 'windows/WinUI/MainWindow.xaml.cs')
-rw-r--r--windows/WinUI/MainWindow.xaml.cs74
1 files changed, 56 insertions, 18 deletions
diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs
index 47f00bfe..25534b46 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.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
@@ -57,40 +58,77 @@ namespace WinUI
}
}
- private bool InitAPIHandler()
+
+ private String readAuthToken(String path)
{
- String ztDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One";
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)
+ {
Int32 port = 9993;
+
try
{
- byte[] tmp = File.ReadAllBytes(ztDir + "\\authtoken.secret");
- authToken = System.Text.Encoding.ASCII.GetString(tmp).Trim();
+ byte[] tmp = File.ReadAllBytes(path);
+ port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
+ if ((port <= 0) || (port > 65535))
+ port = 9993;
}
catch
{
- MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One");
- this.Close();
- return false;
}
+ return port;
+ }
+
+ 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;
+
+ if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port"))
+ {
+ // 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();
+ }
+
+ authToken = readAuthToken(localZtDir + "\\authtoken.secret");
+
if ((authToken == null) || (authToken.Length <= 0))
{
- MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One");
+ MessageBox.Show("Unable to read ZeroTier One authtoken", "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
- {
- }
+ port = readPort(localZtDir + "\\zerotier-one.port");
handler = new APIHandler(port, authToken);
return true;
}