Throw old WinUI in attic
This commit is contained in:
parent
4eb3b762d4
commit
6fd45c1f9d
51 changed files with 0 additions and 0 deletions
|
@ -1,459 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
|
||||
|
||||
public class APIHandler
|
||||
{
|
||||
private string authtoken;
|
||||
|
||||
private string url = null;
|
||||
|
||||
private static volatile APIHandler instance;
|
||||
private static object syncRoot = new Object();
|
||||
|
||||
public delegate void NetworkListCallback(List<ZeroTierNetwork> networks);
|
||||
public delegate void StatusCallback(ZeroTierStatus status);
|
||||
|
||||
private string ZeroTierAddress = "";
|
||||
|
||||
public static APIHandler Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
if (!initHandler())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool initHandler(bool resetToken = false)
|
||||
{
|
||||
String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One";
|
||||
String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One";
|
||||
|
||||
String authToken = "";
|
||||
Int32 port = 9993;
|
||||
|
||||
if (resetToken)
|
||||
{
|
||||
instance = null;
|
||||
if (File.Exists(localZtDir + "\\authtoken.secret"))
|
||||
{
|
||||
File.Delete(localZtDir + "\\authtoken.secret");
|
||||
}
|
||||
|
||||
if (File.Exists(localZtDir + "\\zerotier-one.port"))
|
||||
{
|
||||
File.Delete(localZtDir + "\\zerotier-one.port");
|
||||
}
|
||||
}
|
||||
|
||||
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", "ZeroTier One");
|
||||
return false;
|
||||
}
|
||||
|
||||
port = readPort(localZtDir + "\\zerotier-one.port");
|
||||
instance = new APIHandler(port, authToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static 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 static Int32 readPort(String path)
|
||||
{
|
||||
Int32 port = 9993;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] tmp = File.ReadAllBytes(path);
|
||||
port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
|
||||
if ((port <= 0) || (port > 65535))
|
||||
port = 9993;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
private APIHandler()
|
||||
{
|
||||
url = "http://127.0.0.1:9993";
|
||||
}
|
||||
|
||||
public APIHandler(int port, string authtoken)
|
||||
{
|
||||
url = "http://127.0.0.1:" + port;
|
||||
this.authtoken = authtoken;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void GetStatus(StatusCallback cb)
|
||||
{
|
||||
var request = WebRequest.Create(url + "/status" + "?auth=" + authtoken) as HttpWebRequest;
|
||||
if (request != null)
|
||||
{
|
||||
request.Method = "GET";
|
||||
request.ContentType = "application/json";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var httpResponse = (HttpWebResponse)request.GetResponse();
|
||||
if (httpResponse.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
||||
{
|
||||
var responseText = streamReader.ReadToEnd();
|
||||
|
||||
ZeroTierStatus status = null;
|
||||
try
|
||||
{
|
||||
status = JsonConvert.DeserializeObject<ZeroTierStatus>(responseText);
|
||||
|
||||
if (ZeroTierAddress != status.Address)
|
||||
{
|
||||
ZeroTierAddress = status.Address;
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
cb(status);
|
||||
}
|
||||
}
|
||||
else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
catch (System.Net.WebException e)
|
||||
{
|
||||
HttpWebResponse res = (HttpWebResponse)e.Response;
|
||||
if (res != null && res.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void GetNetworks(NetworkListCallback cb)
|
||||
{
|
||||
var request = WebRequest.Create(url + "/network" + "?auth=" + authtoken) as HttpWebRequest;
|
||||
if (request == null)
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
|
||||
request.Method = "GET";
|
||||
request.ContentType = "application/json";
|
||||
request.Timeout = 10000;
|
||||
|
||||
try
|
||||
{
|
||||
var httpResponse = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
if (httpResponse.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
||||
{
|
||||
var responseText = streamReader.ReadToEnd();
|
||||
|
||||
List<ZeroTierNetwork> networkList = null;
|
||||
try
|
||||
{
|
||||
networkList = JsonConvert.DeserializeObject<List<ZeroTierNetwork>>(responseText);
|
||||
foreach (ZeroTierNetwork n in networkList)
|
||||
{
|
||||
// all networks received via JSON are connected by definition
|
||||
n.IsConnected = true;
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
cb(networkList);
|
||||
}
|
||||
}
|
||||
else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
catch (System.Net.WebException e)
|
||||
{
|
||||
HttpWebResponse res = (HttpWebResponse)e.Response;
|
||||
if (res != null && res.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinNetwork(Dispatcher d, string nwid, bool allowManaged = true, bool allowGlobal = false, bool allowDefault = false, bool allowDNS = false)
|
||||
{
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest;
|
||||
if (request == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
request.Method = "POST";
|
||||
request.ContentType = "applicaiton/json";
|
||||
request.Timeout = 30000;
|
||||
try
|
||||
{
|
||||
using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream()))
|
||||
{
|
||||
string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," +
|
||||
"\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," +
|
||||
"\"allowDefault\":" + (allowDefault ? "true" : "false") + "," +
|
||||
"\"allowDNS\":" + (allowDNS ? "true" : "false") + "}";
|
||||
streamWriter.Write(json);
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
}
|
||||
}
|
||||
catch (System.Net.WebException)
|
||||
{
|
||||
d.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service.");
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var httpResponse = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
else if (httpResponse.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
Console.WriteLine("Error sending join network message");
|
||||
}
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
d.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service.");
|
||||
}));
|
||||
}
|
||||
catch (System.Net.WebException e)
|
||||
{
|
||||
HttpWebResponse res = (HttpWebResponse)e.Response;
|
||||
if (res != null && res.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
d.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
MessageBox.Show("Error Joining Network: Cannot connect to ZeroTier service.");
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void LeaveNetwork(Dispatcher d, string nwid)
|
||||
{
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest;
|
||||
if (request == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
request.Method = "DELETE";
|
||||
request.Timeout = 30000;
|
||||
|
||||
try
|
||||
{
|
||||
var httpResponse = (HttpWebResponse)request.GetResponse();
|
||||
|
||||
if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
else if (httpResponse.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
Console.WriteLine("Error sending leave network message");
|
||||
}
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
d.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service.");
|
||||
}));
|
||||
}
|
||||
catch (System.Net.WebException e)
|
||||
{
|
||||
HttpWebResponse res = (HttpWebResponse)e.Response;
|
||||
if (res != null && res.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
d.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
MessageBox.Show("Error Leaving Network: Cannot connect to ZeroTier service.");
|
||||
}));
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Error leaving network: Unknown error");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public delegate void PeersCallback(List<ZeroTierPeer> peers);
|
||||
|
||||
public void GetPeers(PeersCallback cb)
|
||||
{
|
||||
var request = WebRequest.Create(url + "/peer" + "?auth=" + authtoken) as HttpWebRequest;
|
||||
if (request == null)
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
|
||||
request.Method = "GET";
|
||||
request.ContentType = "application/json";
|
||||
|
||||
try
|
||||
{
|
||||
var httpResponse = (HttpWebResponse)request.GetResponse();
|
||||
if (httpResponse.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
|
||||
{
|
||||
var responseText = streamReader.ReadToEnd();
|
||||
//Console.WriteLine(responseText);
|
||||
List<ZeroTierPeer> peerList = null;
|
||||
try
|
||||
{
|
||||
peerList = JsonConvert.DeserializeObject<List<ZeroTierPeer>>(responseText);
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
cb(peerList);
|
||||
}
|
||||
}
|
||||
else if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
catch (System.Net.WebException e)
|
||||
{
|
||||
HttpWebResponse res = (HttpWebResponse)e.Response;
|
||||
if (res != null && res.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
APIHandler.initHandler(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
cb(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string NodeAddress()
|
||||
{
|
||||
return ZeroTierAddress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<Window x:Class="WinUI.AboutView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WinUI"
|
||||
mc:Ignorable="d"
|
||||
Title="AboutView" Height="368.267" Width="300" Icon="ZeroTierIcon.ico">
|
||||
<Grid>
|
||||
<Image x:Name="image" HorizontalAlignment="Center" Height="100" Margin="0,10,0,0" VerticalAlignment="Top" Width="100" Source="ZeroTierIcon.ico"/>
|
||||
<RichTextBox x:Name="richTextBox" HorizontalAlignment="Left" Height="209" Margin="10,123,0,0" VerticalAlignment="Top" Width="275" IsReadOnly="True" IsDocumentEnabled="True" BorderThickness="0" FontSize="18" RenderTransformOrigin="0.506,0.63">
|
||||
<RichTextBox.Resources>
|
||||
<Style TargetType="Hyperlink">
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
</Style>
|
||||
</RichTextBox.Resources>
|
||||
<FlowDocument>
|
||||
<Paragraph TextAlignment="Center">
|
||||
<Run Text="ZeroTier One"/>
|
||||
</Paragraph>
|
||||
<Paragraph TextAlignment="Center">
|
||||
<Run FontSize="14" Text="Version 1.6.5"/>
|
||||
<LineBreak/>
|
||||
<Run FontSize="14" Text="(c) 2011-2021 ZeroTier, Inc."/>
|
||||
<LineBreak/>
|
||||
<Run FontSize="14" Text="www.zerotier.com"/>
|
||||
</Paragraph>
|
||||
<Paragraph TextAlignment="Center">
|
||||
<Run FontSize="14" Text="ZeroTier One allows your computer to join virtual networks. Just select "join" and enter a network's 16-digit ID. Each network appears on your computer as a new network port."/>
|
||||
</Paragraph>
|
||||
</FlowDocument>
|
||||
</RichTextBox>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,35 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AboutView.xaml
|
||||
/// </summary>
|
||||
public partial class AboutView : Window
|
||||
{
|
||||
public AboutView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void Hyperlink_MouseLeftButtonDown(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
var hyperlink = (Hyperlink)sender;
|
||||
Process.Start(hyperlink.NavigateUri.ToString());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -1,14 +0,0 @@
|
|||
<Application x:Class="WinUI.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="ToolbarItem.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="Simple Styles.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -1,25 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Hardcodet.Wpf.TaskbarNotification;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
private TaskbarIcon tb;
|
||||
|
||||
private void InitApplication()
|
||||
{
|
||||
tb = (TaskbarIcon)FindResource("NotifyIcon");
|
||||
tb.Visibility = Visibility.Visible;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,256 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralAPI
|
||||
{
|
||||
private static volatile CentralAPI instance;
|
||||
private static object syncRoot = new Object();
|
||||
|
||||
private CookieContainer cookieContainer;
|
||||
private HttpClientHandler clientHandler;
|
||||
private HttpClient client;
|
||||
|
||||
private CentralServer server;
|
||||
public CentralServer Central
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.server;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.server = value;
|
||||
WriteCentralConfig();
|
||||
UpdateRequestHeaders();
|
||||
}
|
||||
}
|
||||
|
||||
public static CentralAPI Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new CentralAPI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private CentralAPI()
|
||||
{
|
||||
#if DEBUG
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
|
||||
#endif
|
||||
cookieContainer = new CookieContainer();
|
||||
clientHandler = new HttpClientHandler
|
||||
{
|
||||
AllowAutoRedirect = true,
|
||||
UseCookies = true,
|
||||
CookieContainer = cookieContainer
|
||||
};
|
||||
|
||||
client = new HttpClient(clientHandler);
|
||||
|
||||
string centralConfigPath = CentralConfigFile();
|
||||
if (File.Exists(centralConfigPath))
|
||||
{
|
||||
byte[] tmp = File.ReadAllBytes(centralConfigPath);
|
||||
string json = Encoding.UTF8.GetString(tmp).Trim();
|
||||
CentralServer ctmp = JsonConvert.DeserializeObject<CentralServer>(json);
|
||||
if (ctmp != null)
|
||||
{
|
||||
Central = ctmp;
|
||||
}
|
||||
else
|
||||
{
|
||||
Central = new CentralServer();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Central = new CentralServer();
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasAccessToken()
|
||||
{
|
||||
if (Central == null)
|
||||
return false;
|
||||
|
||||
return !string.IsNullOrEmpty(Central.APIKey);
|
||||
}
|
||||
|
||||
private string ZeroTierDir()
|
||||
{
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One";
|
||||
}
|
||||
|
||||
private string CentralConfigFile()
|
||||
{
|
||||
return ZeroTierDir() + "\\central.conf";
|
||||
}
|
||||
|
||||
public void WriteCentralConfig()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(Central);
|
||||
byte[] tmp = Encoding.UTF8.GetBytes(json);
|
||||
if (tmp != null)
|
||||
{
|
||||
File.WriteAllBytes(CentralConfigFile(), tmp);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateRequestHeaders()
|
||||
{
|
||||
if (client.DefaultRequestHeaders.Contains("Authorization"))
|
||||
{
|
||||
client.DefaultRequestHeaders.Remove("Authorization");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Central.APIKey))
|
||||
{
|
||||
client.DefaultRequestHeaders.Add("Authorization", "bearer " + Central.APIKey);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> Login(string email, string password, bool isNewUser)
|
||||
{
|
||||
string postURL = Central.ServerURL + "/api/_auth/local";
|
||||
CentralLogin login = new CentralLogin(email, password, isNewUser);
|
||||
var content = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(postURL, content);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string resContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
CentralUser user = JsonConvert.DeserializeObject<CentralUser>(resContent);
|
||||
|
||||
if (user.Tokens.Count == 0)
|
||||
{
|
||||
// create token
|
||||
user = await CreateAuthToken(user);
|
||||
}
|
||||
|
||||
Central.APIKey = user.Tokens[0];
|
||||
|
||||
UpdateRequestHeaders();
|
||||
WriteCentralConfig();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<CentralUser> CreateAuthToken(CentralUser user)
|
||||
{
|
||||
string randomTokenURL = Central.ServerURL + "/api/randomToken";
|
||||
HttpResponseMessage response = await client.GetAsync(randomTokenURL);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
// TODO: throw an error
|
||||
return null;
|
||||
}
|
||||
|
||||
string resContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
CentralToken t = JsonConvert.DeserializeObject<CentralToken>(resContent);
|
||||
|
||||
user.Tokens.Add(t.Token);
|
||||
|
||||
string tokenObj = "{ \"tokens\": " + JsonConvert.SerializeObject(user.Tokens) + " } ";
|
||||
|
||||
string postURL = Central.ServerURL + "/api/user/" + user.Id;
|
||||
var postContent = new StringContent(tokenObj, Encoding.UTF8, "application/json");
|
||||
response = await client.PostAsync(postURL, postContent);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
// TODO: thrown an error
|
||||
return null;
|
||||
}
|
||||
|
||||
resContent = await response.Content.ReadAsStringAsync();
|
||||
user = JsonConvert.DeserializeObject<CentralUser>(resContent);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public async Task<List<CentralNetwork>> GetNetworkList()
|
||||
{
|
||||
string networkURL = Central.ServerURL + "/api/network";
|
||||
|
||||
HttpResponseMessage response = await client.GetAsync(networkURL);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
// TODO: Throw Error
|
||||
return new List<CentralNetwork>();
|
||||
}
|
||||
|
||||
string resContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
List<CentralNetwork> networkList = JsonConvert.DeserializeObject<List<CentralNetwork>>(resContent);
|
||||
|
||||
return networkList;
|
||||
}
|
||||
|
||||
public async Task<CentralNetwork> CreateNewNetwork()
|
||||
{
|
||||
string networkURL = Central.ServerURL + "/api/network?easy=1";
|
||||
CentralNetwork network = new CentralNetwork();
|
||||
network.Config = new CentralNetwork.CentralNetworkConfig();
|
||||
network.Config.Name = NetworkNameGenerator.GenerateName();
|
||||
string jsonNetwork = JsonConvert.SerializeObject(network);
|
||||
var postContent = new StringContent(jsonNetwork, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(networkURL, postContent);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string resContent = await response.Content.ReadAsStringAsync();
|
||||
|
||||
CentralNetwork newNetwork = JsonConvert.DeserializeObject<CentralNetwork>(resContent);
|
||||
|
||||
return newNetwork;
|
||||
}
|
||||
|
||||
public async Task<bool> AuthorizeNode(string nodeAddress, string networkId)
|
||||
{
|
||||
string json = "{ \"config\": { \"authorized\": true } }";
|
||||
string postURL = Central.ServerURL + "/api/network/" + networkId + "/member/" + nodeAddress;
|
||||
var postContent = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
HttpResponseMessage response = await client.PostAsync(postURL, postContent);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralLogin
|
||||
{
|
||||
|
||||
|
||||
public CentralLogin(string email, string password, bool isNew)
|
||||
{
|
||||
Login = email;
|
||||
Password = password;
|
||||
IsNew = isNew;
|
||||
}
|
||||
|
||||
[JsonProperty("login")]
|
||||
public string Login { get; set; }
|
||||
|
||||
[JsonProperty("password")]
|
||||
public string Password { get; set; }
|
||||
|
||||
[JsonProperty("register")]
|
||||
public bool IsNew { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralNetwork
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("clock")]
|
||||
public UInt64 Clock { get; set; }
|
||||
|
||||
[JsonProperty("rulesSource")]
|
||||
public string RulesSource { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonProperty("ownerId")]
|
||||
public string OwnerID { get; set; }
|
||||
|
||||
[JsonProperty("onlineMemberCount")]
|
||||
public int OnlineMemberCount { get; set; }
|
||||
|
||||
[JsonProperty("config")]
|
||||
public CentralNetworkConfig Config { get; set; }
|
||||
|
||||
public class CentralNetworkConfig
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty("nwid")]
|
||||
public string NetworkID { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralServer
|
||||
{
|
||||
public CentralServer()
|
||||
{
|
||||
ServerURL = "https://my.zerotier.com";
|
||||
}
|
||||
|
||||
[JsonProperty("server_url")]
|
||||
public string ServerURL { get; set; }
|
||||
|
||||
[JsonProperty("api_key")]
|
||||
public string APIKey { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralToken
|
||||
{
|
||||
[JsonProperty("token")]
|
||||
public string Token { get; set; }
|
||||
|
||||
[JsonProperty("clock")]
|
||||
public UInt64 Clock { get; set; }
|
||||
|
||||
[JsonProperty("raw")]
|
||||
public string Raw { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class CentralUser
|
||||
{
|
||||
public class CentralGlobalPermissions
|
||||
{
|
||||
[JsonProperty("a")]
|
||||
public bool Administrator { get; set; }
|
||||
|
||||
[JsonProperty("d")]
|
||||
public bool Delete { get; set; }
|
||||
|
||||
[JsonProperty("m")]
|
||||
public bool Modify { get; set; }
|
||||
|
||||
[JsonProperty("r")]
|
||||
public bool Read { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[JsonProperty("clock")]
|
||||
public UInt64 Clock { get; set; }
|
||||
|
||||
[JsonProperty("globalPermissions")]
|
||||
public CentralGlobalPermissions GlobalPermissions { get; set; }
|
||||
|
||||
[JsonProperty("displayName")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[JsonProperty("smsNumber")]
|
||||
public string SmsNumber { get; set; }
|
||||
|
||||
[JsonProperty("tokens")]
|
||||
public List<string> Tokens { get; set; }
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,13 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
interface ISwitchable
|
||||
{
|
||||
void UtilizeState(object state);
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
<Window x:Class="WinUI.JoinNetworkView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WinUI"
|
||||
mc:Ignorable="d"
|
||||
Title="Join a Network" SizeToContent="WidthAndHeight" Height="Auto" Width="Auto" Icon="ZeroTierIcon.ico">
|
||||
<Grid HorizontalAlignment="Left" Margin="0,0,0,0" Width="315">
|
||||
<TextBox x:Name="joinNetworkBox" HorizontalAlignment="Left" Height="23" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="291" PreviewTextInput="joinNetworkBox_OnTextEntered" PreviewKeyDown="joinNetworkBox_OnKeyDown"/>
|
||||
<CheckBox x:Name="allowManagedCheckbox" Content="Allow Managed" HorizontalAlignment="Left" Margin="10,38,0,0" VerticalAlignment="Top" IsChecked="True"/>
|
||||
<CheckBox x:Name="allowGlobalCheckbox" Content="Allow Global" HorizontalAlignment="Left" Margin="118,38,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="allowDefaultCheckbox" Content="Allow Default" HorizontalAlignment="Left" Margin="10,58,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="allowDNSCheckbox" Content="Allow DNS" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="118,58,0,0"/>
|
||||
<Button x:Name="joinButton" Content="Join" HorizontalAlignment="Left" Margin="226,58,0,10" Background="#FFFFB354" VerticalAlignment="Top" Width="75" Click="joinButton_Click" IsEnabled="False"/>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,127 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for JoinNetworkView.xaml
|
||||
/// </summary>
|
||||
public partial class JoinNetworkView : Window
|
||||
{
|
||||
Regex charRegex = new Regex("[0-9a-fxA-FX]");
|
||||
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
|
||||
|
||||
public JoinNetworkView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataObject.AddPastingHandler(joinNetworkBox, onPaste);
|
||||
DataObject.AddCopyingHandler(joinNetworkBox, onCopyCut);
|
||||
}
|
||||
|
||||
private void joinNetworkBox_OnTextEntered(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !charRegex.IsMatch(e.Text);
|
||||
|
||||
if ( (joinNetworkBox.Text.Length + e.Text.Length) == 16)
|
||||
{
|
||||
joinButton.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
joinButton.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void joinNetworkBox_OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
|
||||
{
|
||||
if (e.Key == Key.X && joinNetworkBox.IsSelectionActive)
|
||||
{
|
||||
// handle ctrl-x removing characters
|
||||
joinButton.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
else if (e.Key == Key.Delete || e.Key == Key.Back)
|
||||
{
|
||||
if ((joinNetworkBox.Text.Length - 1) == 16)
|
||||
{
|
||||
joinButton.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
joinButton.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((joinNetworkBox.Text.Length + 1) > 16)
|
||||
{
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onPaste(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
||||
if (!isText)
|
||||
{
|
||||
joinButton.IsEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
||||
|
||||
if (!wholeStringRegex.IsMatch(text))
|
||||
{
|
||||
e.Handled = true;
|
||||
e.CancelCommand();
|
||||
}
|
||||
|
||||
if (text.Length == 16 || (joinNetworkBox.Text.Length + text.Length) == 16)
|
||||
{
|
||||
joinButton.IsEnabled = true;
|
||||
}
|
||||
else if (text.Length > 16 || (joinNetworkBox.Text.Length + text.Length) > 16)
|
||||
{
|
||||
e.Handled = true;
|
||||
e.CancelCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
joinButton.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void onCopyCut(object sender, DataObjectCopyingEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void joinButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
bool allowDefault = allowDefaultCheckbox.IsChecked.Value;
|
||||
bool allowGlobal = allowGlobalCheckbox.IsChecked.Value;
|
||||
bool allowManaged = allowManagedCheckbox.IsChecked.Value;
|
||||
bool allowDNS = allowDNSCheckbox.IsChecked.Value;
|
||||
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, joinNetworkBox.Text, allowManaged, allowGlobal, allowDefault, allowDNS);
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,233 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Timers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
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();
|
||||
|
||||
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)
|
||||
{
|
||||
Int32 port = 9993;
|
||||
|
||||
try
|
||||
{
|
||||
byte[] tmp = File.ReadAllBytes(path);
|
||||
port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim());
|
||||
if ((port <= 0) || (port > 65535))
|
||||
port = 9993;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
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", "ZeroTier One");
|
||||
this.Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
port = readPort(localZtDir + "\\zerotier-one.port");
|
||||
handler = new APIHandler(port, authToken);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateStatus()
|
||||
{
|
||||
var status = handler.GetStatus();
|
||||
|
||||
if (status != null)
|
||||
{
|
||||
connected = true;
|
||||
|
||||
networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
this.networkId.Text = 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
|
||||
{
|
||||
connected = false;
|
||||
|
||||
networkId.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
this.networkId.Text = "";
|
||||
}));
|
||||
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()
|
||||
{
|
||||
var networks = handler.GetNetworks();
|
||||
|
||||
networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
networksPage.setNetworks(networks);
|
||||
}));
|
||||
}
|
||||
|
||||
private void updatePeers()
|
||||
{
|
||||
//var peers = handler.GetPeers();
|
||||
|
||||
//peersPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
//{
|
||||
// peersPage.SetPeers(peers);
|
||||
//}));
|
||||
}
|
||||
|
||||
private void OnUpdateTimer(object source, ElapsedEventArgs e)
|
||||
{
|
||||
updateStatus();
|
||||
updateNetworks();
|
||||
//updatePeers();
|
||||
}
|
||||
|
||||
private void joinButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (joinNetworkID.Text.Length < 16)
|
||||
{
|
||||
MessageBox.Show("Invalid Network ID");
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.JoinNetwork(joinNetworkID.Text);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !charRegex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
||||
if (!isText) return;
|
||||
|
||||
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
||||
|
||||
if (!wholeStringRegex.IsMatch(text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
<UserControl Background="LightGray" x:Class="WinUI.NetworkInfoView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
>
|
||||
|
||||
<Border Background="GhostWhite" BorderBrush="Gainsboro" BorderThickness="1" CornerRadius="8,8,8,8">
|
||||
<Grid Background="GhostWhite" Margin="10,10,10,10">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="10"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
<RowDefinition Height="auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBox x:Name="networkId" Text="8056c2e21c000001" HorizontalAlignment="Left" Grid.Column="0" Foreground="#FF91A2A3" FontFamily="Lucida Console" BorderThickness="0" IsReadOnly="true" Background="Transparent"/>
|
||||
<TextBox x:Name="networkName" Text="earth.zerotier.net" HorizontalAlignment="Right" Grid.Column="1" Foreground="#FF000000" BorderThickness="0" IsReadOnly="true" Background="Transparent"/>
|
||||
</Grid>
|
||||
|
||||
<Separator Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3"/>
|
||||
|
||||
<TextBlock TextWrapping="Wrap" Text="Status" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="2" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Type" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="3" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="MAC" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="4" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="MTU" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="5" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Broadcast" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="6" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Bridging" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="7" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Device" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="8" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Managed IPs" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="9" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Allow Global IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="10" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Allow Managed IP" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="11" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Allow Default Route" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="12" Foreground="#FF000000"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Allow DNS" HorizontalAlignment="Right" Grid.Column="0" Grid.Row="13" Foreground="#FF000000"/>
|
||||
|
||||
<Rectangle Grid.Column="2" Grid.Row="2" Grid.RowSpan="12" Fill="#FFEEEEEE"/>
|
||||
|
||||
<TextBlock x:Name="networkStatus" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Text="OK" TextAlignment="Right" Grid.Column="2" Grid.Row="2" Foreground="#FF000000"/>
|
||||
<TextBlock x:Name="networkType" FontFamily="Lucida Console" TextWrapping="Wrap" Text="PUBLIC" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="3" Foreground="#FF000000"/>
|
||||
<TextBlock x:Name="macAddress" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="4" Foreground="#FF000000"><Span><Run Text="02:83:4a:1e:4b:3a"/></Span></TextBlock>
|
||||
<TextBlock x:Name="mtu" FontFamily="Lucida Console" TextWrapping="Wrap" Text="2800" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="5" Foreground="#FF000000"/>
|
||||
<TextBlock x:Name="broadcastEnabled" FontFamily="Lucida Console" TextWrapping="Wrap" Text="ENABLED" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="6" Foreground="#FF000000"/>
|
||||
<TextBlock x:Name="bridgingEnabled" FontFamily="Lucida Console" TextWrapping="Wrap" Text="DISABLED" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="7" Background="#FFEEEEEE" Foreground="#FF000000"/>
|
||||
<TextBlock x:Name="deviceName" FontFamily="Lucida Console" TextWrapping="Wrap" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="8" Foreground="#FF000000"><Span><Run Text="ethernet_32771"/></Span></TextBlock>
|
||||
<TextBox x:Name="managedIps" TextWrapping="Wrap" FontFamily="Lucida Console" HorizontalAlignment="Right" TextAlignment="Right" Grid.Column="2" Grid.Row="9" Foreground="#FF000000" IsReadOnly="True" BorderThickness="0" Background="#FFEEEEEE" Text="28.2.169.248/7
fd80:56c2:e21c:0000:0199:9383:4a02:a9f8/88"/>
|
||||
<CheckBox x:Name="allowGlobal" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="10" />
|
||||
<CheckBox x:Name="allowManaged" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="11" />
|
||||
<CheckBox x:Name="allowDefault" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="12" />
|
||||
<CheckBox x:Name="allowDNS" HorizontalAlignment="Right" Grid.Column="2" Grid.Row="13"/>
|
||||
|
||||
<Separator Grid.Column="0" Grid.Row="14" Grid.ColumnSpan="3"/>
|
||||
|
||||
<Grid Grid.Column="0" Grid.Row="15" Grid.ColumnSpan="3" Background="GhostWhite">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button x:Name="deleteButton" Grid.Column="0" Content="Delete" HorizontalAlignment="Left" VerticalAlignment="Center" Width="75" Background="#FFFFB354" Click="deleteButton_Click"/>
|
||||
<CheckBox x:Name="connectedCheckBox" Grid.Column="2" Content="Connected" HorizontalAlignment="Right" VerticalAlignment="Center" Checked="connectedCheckBox_Checked" Unchecked="connectedCheckbox_Unchecked"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
|
@ -1,183 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for NetworkInfoView.xaml
|
||||
/// </summary>
|
||||
public partial class NetworkInfoView : UserControl
|
||||
{
|
||||
public ZeroTierNetwork network;
|
||||
|
||||
public NetworkInfoView(ZeroTierNetwork network)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.network = network;
|
||||
|
||||
UpdateNetworkData();
|
||||
|
||||
allowDefault.Checked += AllowDefault_CheckStateChanged;
|
||||
allowDefault.Unchecked += AllowDefault_CheckStateChanged;
|
||||
allowGlobal.Checked += AllowGlobal_CheckStateChanged;
|
||||
allowGlobal.Unchecked += AllowGlobal_CheckStateChanged;
|
||||
allowManaged.Checked += AllowManaged_CheckStateChanged;
|
||||
allowManaged.Unchecked += AllowManaged_CheckStateChanged;
|
||||
allowDNS.Checked += AllowDNS_CheckStateChanged;
|
||||
allowDNS.Unchecked += AllowDNS_CheckStateChanged;
|
||||
}
|
||||
|
||||
private void UpdateNetworkData()
|
||||
{
|
||||
|
||||
if (this.networkId.Text != network.NetworkId)
|
||||
this.networkId.Text = network.NetworkId;
|
||||
|
||||
if (this.networkName.Text != network.NetworkName)
|
||||
this.networkName.Text = network.NetworkName;
|
||||
|
||||
if (this.networkStatus.Text != network.NetworkStatus)
|
||||
this.networkStatus.Text = network.NetworkStatus;
|
||||
|
||||
if (this.networkType.Text != network.NetworkType)
|
||||
this.networkType.Text = network.NetworkType;
|
||||
|
||||
if (this.macAddress.Text != network.MacAddress)
|
||||
this.macAddress.Text = network.MacAddress;
|
||||
|
||||
if (this.mtu.Text != network.MTU.ToString())
|
||||
this.mtu.Text = network.MTU.ToString();
|
||||
|
||||
this.broadcastEnabled.Text = (network.BroadcastEnabled ? "ENABLED" : "DISABLED");
|
||||
this.bridgingEnabled.Text = (network.Bridge ? "ENABLED" : "DISABLED");
|
||||
|
||||
if (this.deviceName.Text != network.DeviceName)
|
||||
this.deviceName.Text = network.DeviceName;
|
||||
|
||||
string iplist = "";
|
||||
for (int i = 0; i < network.AssignedAddresses.Length; ++i)
|
||||
{
|
||||
iplist += network.AssignedAddresses[i];
|
||||
if (i < (network.AssignedAddresses.Length - 1))
|
||||
iplist += "\n";
|
||||
}
|
||||
|
||||
if (this.managedIps.Text != iplist)
|
||||
this.managedIps.Text = iplist;
|
||||
|
||||
this.allowDefault.IsChecked = network.AllowDefault;
|
||||
this.allowGlobal.IsChecked = network.AllowGlobal;
|
||||
this.allowManaged.IsChecked = network.AllowManaged;
|
||||
this.allowDNS.IsChecked = network.AllowDNS;
|
||||
|
||||
this.connectedCheckBox.Checked -= connectedCheckBox_Checked;
|
||||
this.connectedCheckBox.Unchecked -= connectedCheckbox_Unchecked;
|
||||
|
||||
this.connectedCheckBox.IsChecked = network.IsConnected;
|
||||
|
||||
this.connectedCheckBox.Checked += connectedCheckBox_Checked;
|
||||
this.connectedCheckBox.Unchecked += connectedCheckbox_Unchecked;
|
||||
}
|
||||
|
||||
public bool HasNetwork(ZeroTierNetwork network)
|
||||
{
|
||||
if (this.network.NetworkId.Equals(network.NetworkId))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SetNetworkInfo(ZeroTierNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
|
||||
UpdateNetworkData();
|
||||
}
|
||||
|
||||
private void deleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
APIHandler.Instance.LeaveNetwork(this.Dispatcher, network.NetworkId);
|
||||
NetworkMonitor.Instance.RemoveNetwork(network.NetworkId);
|
||||
}
|
||||
|
||||
private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, network.NetworkId,
|
||||
allowManaged.IsChecked ?? false,
|
||||
allowGlobal.IsChecked ?? false,
|
||||
allowDefault.IsChecked ?? false,
|
||||
allowDNS.IsChecked ?? false);
|
||||
}
|
||||
|
||||
private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, network.NetworkId,
|
||||
allowManaged.IsChecked ?? false,
|
||||
allowGlobal.IsChecked ?? false,
|
||||
allowDefault.IsChecked ?? false,
|
||||
allowDNS.IsChecked ?? false);
|
||||
}
|
||||
|
||||
private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, network.NetworkId,
|
||||
allowManaged.IsChecked ?? false,
|
||||
allowGlobal.IsChecked ?? false,
|
||||
allowDefault.IsChecked ?? false,
|
||||
allowDNS.IsChecked ?? false);
|
||||
}
|
||||
|
||||
private void AllowDNS_CheckStateChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cb = sender as CheckBox;
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, network.NetworkId,
|
||||
allowManaged.IsChecked ?? false,
|
||||
allowGlobal.IsChecked ?? false,
|
||||
allowDefault.IsChecked ?? false,
|
||||
allowDNS.IsChecked ?? false);
|
||||
}
|
||||
|
||||
private void connectedCheckBox_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
onConnectedCheckboxUpdated(true);
|
||||
}
|
||||
|
||||
private void connectedCheckbox_Unchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
onConnectedCheckboxUpdated(false);
|
||||
}
|
||||
|
||||
private void onConnectedCheckboxUpdated(bool isChecked)
|
||||
{
|
||||
if (isChecked)
|
||||
{
|
||||
bool global = allowGlobal.IsChecked.Value;
|
||||
bool managed = allowManaged.IsChecked.Value;
|
||||
bool defRoute = allowDefault.IsChecked.Value;
|
||||
bool dns = allowDNS.IsChecked.Value;
|
||||
|
||||
APIHandler.Instance.JoinNetwork(this.Dispatcher, networkId.Text, managed, global, defRoute, dns);
|
||||
}
|
||||
else
|
||||
{
|
||||
APIHandler.Instance.LeaveNetwork(this.Dispatcher, networkId.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
<Window
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WinUI"
|
||||
mc:Ignorable="d" x:Class="WinUI.NetworkListView"
|
||||
Title="ZeroTier One" SizeToContent="Width" Height="500" Width="Auto" Icon="ZeroTierIcon.ico">
|
||||
|
||||
<Window.Resources>
|
||||
<SolidColorBrush x:Key="GreenBrush" Color="#ff91a2a3"/>
|
||||
|
||||
<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />
|
||||
|
||||
<SolidColorBrush x:Key="GreenDisabledBrush" Color="#FF234447" />
|
||||
|
||||
<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />
|
||||
|
||||
<SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />
|
||||
|
||||
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
|
||||
|
||||
<Style TargetType="{x:Type DataGrid}">
|
||||
<Setter Property="Background" Value="#FFF" />
|
||||
<Setter Property="AlternationCount" Value="2" />
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#EEE"></Setter>
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF"></Setter>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<Style TargetType="{x:Type TabItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type TabItem}">
|
||||
<Grid>
|
||||
<Border
|
||||
Name="Border"
|
||||
Margin="0,0,-4,0"
|
||||
Background="{StaticResource GreenBrush}"
|
||||
BorderBrush="{StaticResource SolidBorderBrush}"
|
||||
BorderThickness="1,1,1,1"
|
||||
CornerRadius="2,12,0,0" >
|
||||
<ContentPresenter x:Name="ContentSite"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
ContentSource="Header"
|
||||
Margin="12,2,12,2"
|
||||
RecognizesAccessKey="True"/>
|
||||
</Border>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Panel.ZIndex" Value="100" />
|
||||
<Setter TargetName="Border" Property="Background" Value="{StaticResource GreenDisabledBrush}" />
|
||||
<Setter TargetName="Border" Property="BorderThickness" Value="1,1,1,0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
|
||||
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
|
||||
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<DockPanel>
|
||||
<Grid Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<local:NetworksPage x:Name="networksPage" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" Grid.Row="0" Margin="0,0,0,0"/>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Window>
|
|
@ -1,85 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Timers;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.Windows.Threading;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class NetworkListView : Window
|
||||
{
|
||||
Regex charRegex = new Regex("[0-9a-fxA-FX]");
|
||||
Regex wholeStringRegex = new Regex("^[0-9a-fxA-FX]+$");
|
||||
|
||||
public NetworkListView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Closed += onClosed;
|
||||
|
||||
NetworkMonitor.Instance.SubscribeNetworkUpdates(updateNetworks);
|
||||
}
|
||||
|
||||
~NetworkListView()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void onClosed(object sender, System.EventArgs e)
|
||||
{
|
||||
NetworkMonitor.Instance.UnsubscribeNetworkUpdates(updateNetworks);
|
||||
}
|
||||
|
||||
private void updateNetworks(List<ZeroTierNetwork> networks)
|
||||
{
|
||||
if (networks != null)
|
||||
{
|
||||
networksPage.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
networksPage.setNetworks(networks);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNetworkEntered(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !charRegex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
var isText = e.SourceDataObject.GetDataPresent(DataFormats.UnicodeText, true);
|
||||
if (!isText) return;
|
||||
|
||||
var text = e.SourceDataObject.GetData(DataFormats.UnicodeText) as string;
|
||||
|
||||
if (!wholeStringRegex.IsMatch(text))
|
||||
{
|
||||
e.CancelCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,203 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class NetworkMonitor
|
||||
{
|
||||
public delegate void NetworkListCallback(List<ZeroTierNetwork> networks);
|
||||
public delegate void StatusCallback(ZeroTierStatus status);
|
||||
|
||||
private Thread runThread;
|
||||
private NetworkListCallback _nwCb;
|
||||
private StatusCallback _stCb;
|
||||
|
||||
|
||||
private List<ZeroTierNetwork> _knownNetworks = new List<ZeroTierNetwork>();
|
||||
|
||||
private static NetworkMonitor instance;
|
||||
private static object syncRoot = new object();
|
||||
|
||||
public static NetworkMonitor Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new NetworkMonitor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkMonitor()
|
||||
{
|
||||
runThread = new Thread(new ThreadStart(run));
|
||||
loadNetworks();
|
||||
|
||||
runThread.Start();
|
||||
}
|
||||
|
||||
~NetworkMonitor()
|
||||
{
|
||||
runThread.Interrupt();
|
||||
}
|
||||
|
||||
private void loadNetworks()
|
||||
{
|
||||
String dataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One";
|
||||
String dataFile = Path.Combine(dataPath, "networks.dat");
|
||||
|
||||
if (File.Exists(dataFile))
|
||||
{
|
||||
List<ZeroTierNetwork> netList;
|
||||
|
||||
using (Stream stream = File.Open(dataFile, FileMode.Open))
|
||||
{
|
||||
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
netList = (List<ZeroTierNetwork>)bformatter.Deserialize(stream);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
lock (_knownNetworks)
|
||||
{
|
||||
_knownNetworks = netList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeNetworks()
|
||||
{
|
||||
String dataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One";
|
||||
String dataFile = Path.Combine(dataPath, "networks.dat");
|
||||
|
||||
if (!Directory.Exists(dataPath))
|
||||
{
|
||||
Directory.CreateDirectory(dataPath);
|
||||
}
|
||||
|
||||
using (Stream stream = File.Open(dataFile, FileMode.OpenOrCreate))
|
||||
{
|
||||
lock (_knownNetworks)
|
||||
{
|
||||
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
|
||||
bformatter.Serialize(stream, _knownNetworks);
|
||||
stream.Flush();
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void apiNetworkCallback(List<ZeroTierNetwork> networks)
|
||||
{
|
||||
if (networks == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_knownNetworks)
|
||||
{
|
||||
_knownNetworks = _knownNetworks.Union(networks, new NetworkEqualityComparer()).ToList();
|
||||
|
||||
foreach (ZeroTierNetwork n in _knownNetworks)
|
||||
{
|
||||
if (networks.Contains(n))
|
||||
{
|
||||
n.IsConnected = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
n.IsConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
_knownNetworks.Sort();
|
||||
_nwCb(_knownNetworks);
|
||||
}
|
||||
|
||||
writeNetworks();
|
||||
}
|
||||
|
||||
private void apiStatusCallback(ZeroTierStatus status)
|
||||
{
|
||||
_stCb(status);
|
||||
}
|
||||
|
||||
private void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (runThread.IsAlive)
|
||||
{
|
||||
APIHandler handler = APIHandler.Instance;
|
||||
|
||||
if (handler != null)
|
||||
{
|
||||
handler.GetNetworks(apiNetworkCallback);
|
||||
handler.GetStatus(apiStatusCallback);
|
||||
}
|
||||
|
||||
Thread.Sleep(2000);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Monitor Thread Exception: " + "\n" + e.StackTrace);
|
||||
}
|
||||
Console.WriteLine("Monitor Thread Ended");
|
||||
}
|
||||
|
||||
public void SubscribeStatusUpdates(StatusCallback cb)
|
||||
{
|
||||
_stCb += cb;
|
||||
}
|
||||
|
||||
public void UnsubscribeStatusUpdates(StatusCallback cb)
|
||||
{
|
||||
_stCb -= cb;
|
||||
}
|
||||
|
||||
public void SubscribeNetworkUpdates(NetworkListCallback cb)
|
||||
{
|
||||
_nwCb += cb;
|
||||
}
|
||||
|
||||
public void UnsubscribeNetworkUpdates(NetworkListCallback cb)
|
||||
{
|
||||
_nwCb -= cb;
|
||||
}
|
||||
|
||||
public void RemoveNetwork(String networkID)
|
||||
{
|
||||
lock(_knownNetworks)
|
||||
{
|
||||
foreach (ZeroTierNetwork n in _knownNetworks)
|
||||
{
|
||||
if (n.NetworkId.Equals(networkID))
|
||||
{
|
||||
_knownNetworks.Remove(n);
|
||||
writeNetworks();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMonitor()
|
||||
{
|
||||
runThread.Abort();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
class NetworkNameGenerator
|
||||
{
|
||||
public static string GenerateName()
|
||||
{
|
||||
Random r = new Random(DateTime.Now.Millisecond);
|
||||
int firstIndex = r.Next(0, FIRST.Length);
|
||||
int secondIndex = r.Next(0, SECOND.Length);
|
||||
return FIRST[firstIndex] + "_" + SECOND[secondIndex];
|
||||
}
|
||||
|
||||
private static string[] FIRST =
|
||||
{
|
||||
"admiring",
|
||||
"adoring",
|
||||
"agitated",
|
||||
"amazing",
|
||||
"angry",
|
||||
"awesome",
|
||||
"berserk",
|
||||
"big",
|
||||
"clever",
|
||||
"compassionate",
|
||||
"cranky",
|
||||
"crazy",
|
||||
"desperate",
|
||||
"determined",
|
||||
"distracted",
|
||||
"dreamy",
|
||||
"ecstatic",
|
||||
"elated",
|
||||
"elegant",
|
||||
"fervent",
|
||||
"focused",
|
||||
"furious",
|
||||
"gigantic",
|
||||
"gloomy",
|
||||
"goofy",
|
||||
"grave",
|
||||
"happy",
|
||||
"high",
|
||||
"hopeful",
|
||||
"hungry",
|
||||
"insane",
|
||||
"jolly",
|
||||
"jovial",
|
||||
"lonely",
|
||||
"loving",
|
||||
"modest",
|
||||
"nostalgic",
|
||||
"pedantic",
|
||||
"pensive",
|
||||
"prickly",
|
||||
"reverent",
|
||||
"romantic",
|
||||
"sad",
|
||||
"serene",
|
||||
"sharp",
|
||||
"silly",
|
||||
"sleepy",
|
||||
"stoic",
|
||||
"stupefied",
|
||||
"suspicious",
|
||||
"tender",
|
||||
"thirsty",
|
||||
"tiny",
|
||||
"trusting"
|
||||
};
|
||||
|
||||
private static string[] SECOND =
|
||||
{
|
||||
// constructed telephone-like devices in 1854
|
||||
"meucci",
|
||||
|
||||
// prototype make-or-break telephones in 1860
|
||||
"reis",
|
||||
|
||||
// Alexander Graham Bell
|
||||
"bell",
|
||||
|
||||
// designed telephone using water microphone in 1876
|
||||
"gray",
|
||||
|
||||
// Tivadar Puskás invented the telephone switchboard exchange in 1876.
|
||||
"puskas",
|
||||
|
||||
// Thomas Edison, invented the carbon microphone which produced a strong telephone signal.
|
||||
"edison",
|
||||
|
||||
// 1950s, Paul Baran developed the concept Distributed Adaptive Message Block Switching
|
||||
"baran",
|
||||
|
||||
// Donald Davies coined the phrase 'packet switching network'
|
||||
"davies",
|
||||
|
||||
// Robert Licklider helped get ARPANET funded
|
||||
"licklider",
|
||||
|
||||
// Robert Taylor, ARPANET pioneer
|
||||
"taylor",
|
||||
|
||||
// Lawrence Roberts, ARPANET
|
||||
"roberts",
|
||||
|
||||
// Vint Cerf, TCP
|
||||
"cerf",
|
||||
|
||||
// Bob Kahn, TCP
|
||||
"kahn",
|
||||
|
||||
// David P Reed, UDP
|
||||
"reed",
|
||||
|
||||
// Community Memory was created by Efrem Lipkin, Mark Szpakowski, and Lee Felsenstein, acting as The Community Memory Project within the Resource One computer center at Project One in San Francisco.
|
||||
"lipkin",
|
||||
"szpakowski",
|
||||
"felsenstein",
|
||||
|
||||
// The first public dial-up BBS was developed by Ward Christensen and Randy Suess.
|
||||
"christensen",
|
||||
"suess",
|
||||
|
||||
// Joybubbles (May 25, 1949 – August 8, 2007), born Josef Carl Engressia, Jr. in Richmond, Virginia, USA, was an early phone phreak.
|
||||
"engressia",
|
||||
"joybubbles",
|
||||
|
||||
// John Thomas Draper (born 1943), also known as Captain Crunch, Crunch or Crunchman (after Cap'n Crunch breakfast cereal mascot), is an American computer programmer and former phone phreak
|
||||
"draper",
|
||||
|
||||
// Dennis C. Hayes, founder of Hayes Microcomputer Products
|
||||
// "The Modem of Dennis Hayes and Dale Heatherington."
|
||||
"hayes",
|
||||
"heatherington",
|
||||
|
||||
// "Ethernet was developed at Xerox PARC between 1973 and 1974.[7][8] It was inspired by ALOHAnet, which Robert Metcalfe had studied as part of his PhD dissertation."
|
||||
"metcalfe",
|
||||
|
||||
// William Bradford Shockley Jr. (February 13, 1910 – August 12, 1989) was an American physicist and inventor. Shockley was the manager of a research group that included John Bardeen and Walter Brattain. The three scientists invented the point contact transistor in 1947
|
||||
"shockley",
|
||||
"bardeen",
|
||||
"brattain",
|
||||
|
||||
// "Randall Erck invented the modern modem as we know it today. There were devices similar to modems used by the military, but they were designed more for the purpose of sending encripted nuclear launch codes to various bases around the world."
|
||||
"erck",
|
||||
|
||||
// Leonard Kleinrock, packet switching network pioneer
|
||||
"kleinrock",
|
||||
|
||||
// Tim Berners-Lee, WWW
|
||||
"berners_lee",
|
||||
|
||||
// Steve Wozniak, early phone phreak
|
||||
"wozniak",
|
||||
|
||||
// James Fields Smathers of Kansas City invented what is considered the first practical power-operated typewriter in 1914.
|
||||
"smathers",
|
||||
|
||||
// The teleprinter evolved through a series of inventions by a number of engineers, including Royal Earl House, David Edward Hughes, Emile Baudot, Donald Murray, Charles L. Krum, Edward Kleinschmidt and Frederick G. Creed.
|
||||
"house",
|
||||
"hughes",
|
||||
"baudot",
|
||||
"murray",
|
||||
"krum",
|
||||
"kleinschmidt",
|
||||
"creed",
|
||||
|
||||
// Ron Rosenbaum, author of "Secrets of the Little Blue Box" which mainstreamed phone phreaking
|
||||
"rosenbaum",
|
||||
|
||||
// Bram Cohen. Bram Cohen (born October 12, 1975) is an American computer programmer, best known as the author of the peer-to-peer (P2P) BitTorrent protocol,
|
||||
"cohen",
|
||||
|
||||
// Jarkko Oikarinen (born 16 August 1967, in Kuusamo, Finland) is the inventor of the first Internet chat network, called Internet Relay Chat (IRC), where he is known as WiZ.
|
||||
"oikarinen",
|
||||
|
||||
// "What you probably didn't know is that the author of Trumpet Winsock — Peter Tattam from Tasmania, Australia — didn't see much money for his efforts."
|
||||
"tattam",
|
||||
|
||||
// Satoshi Nakamoto
|
||||
"nakamoto",
|
||||
|
||||
// Philo Farnsworth, inventor of the first practical TV tube
|
||||
"farnsworth",
|
||||
|
||||
// Scottish inventor John Logie Baird employed the Nipkow disk in his prototype video systems. On 25 March 1925, Baird gave the first public demonstration of televised silhouette images in motion, at Selfridge's Department Store in London.
|
||||
"baird",
|
||||
|
||||
// Beginning in 1836, the American artist Samuel F. B. Morse, the American physicist Joseph Henry, and Alfred Vail developed an electrical telegraph system.
|
||||
"morse",
|
||||
"henry",
|
||||
"vail"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
[Serializable]
|
||||
public class NetworkRoute : ISerializable
|
||||
{
|
||||
protected NetworkRoute(SerializationInfo info, StreamingContext ctx)
|
||||
{
|
||||
Target = info.GetString("target");
|
||||
Via = info.GetString("via");
|
||||
Flags = info.GetInt32("flags");
|
||||
Metric = info.GetInt32("metric");
|
||||
}
|
||||
|
||||
public virtual void GetObjectData(SerializationInfo info, StreamingContext ctx)
|
||||
{
|
||||
info.AddValue("target", Target);
|
||||
info.AddValue("via", Via);
|
||||
info.AddValue("flags", Flags);
|
||||
info.AddValue("metric", Metric);
|
||||
}
|
||||
|
||||
[JsonProperty("target")]
|
||||
public string Target { get; set; }
|
||||
|
||||
[JsonProperty("via")]
|
||||
public string Via { get; set; }
|
||||
|
||||
[JsonProperty("flags")]
|
||||
public int Flags { get; set; }
|
||||
|
||||
[JsonProperty("metric")]
|
||||
public int Metric { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
<UserControl x:Class="WinUI.NetworksPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
|
||||
<UniformGrid x:Name="wrapPanel" Background="#FFDDDDDD" HorizontalAlignment="Stretch" VerticalAlignment="Top" Columns="1">
|
||||
|
||||
</UniformGrid>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
|
@ -1,99 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for NetworksPage.xaml
|
||||
/// </summary>
|
||||
public partial class NetworksPage : UserControl
|
||||
{
|
||||
public NetworksPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void setNetworks(List<ZeroTierNetwork> networks)
|
||||
{
|
||||
if (networks == null)
|
||||
{
|
||||
this.wrapPanel.Children.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ZeroTierNetwork network in networks)
|
||||
{
|
||||
NetworkInfoView view = ChildWithNetwork(network);
|
||||
if (view != null)
|
||||
{
|
||||
view.SetNetworkInfo(network);
|
||||
}
|
||||
else
|
||||
{
|
||||
wrapPanel.Children.Add(
|
||||
new NetworkInfoView(
|
||||
network));
|
||||
}
|
||||
}
|
||||
|
||||
// remove networks we're no longer joined to.
|
||||
List<ZeroTierNetwork> tmpList = GetNetworksFromChildren();
|
||||
foreach (ZeroTierNetwork n in networks)
|
||||
{
|
||||
if (tmpList.Contains(n))
|
||||
{
|
||||
tmpList.Remove(n);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ZeroTierNetwork n in tmpList)
|
||||
{
|
||||
NetworkInfoView view = ChildWithNetwork(n);
|
||||
if (view != null)
|
||||
{
|
||||
wrapPanel.Children.Remove(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkInfoView ChildWithNetwork(ZeroTierNetwork network)
|
||||
{
|
||||
List<NetworkInfoView> list = wrapPanel.Children.OfType<NetworkInfoView>().ToList();
|
||||
|
||||
foreach (NetworkInfoView view in list)
|
||||
{
|
||||
if (view.HasNetwork(network))
|
||||
{
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<ZeroTierNetwork> GetNetworksFromChildren()
|
||||
{
|
||||
List<ZeroTierNetwork> networks = new List<ZeroTierNetwork>(wrapPanel.Children.Count);
|
||||
|
||||
List<NetworkInfoView> list = wrapPanel.Children.OfType<NetworkInfoView>().ToList();
|
||||
foreach (NetworkInfoView n in list)
|
||||
{
|
||||
networks.Add(n.network);
|
||||
}
|
||||
|
||||
return networks;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
<UserControl x:Class="WinUI.PeersPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300" Background="White" Foreground="Black">
|
||||
|
||||
<DataGrid x:Name="dataGrid" GridLinesVisibility="None" AutoGenerateColumns="False" CanUserResizeColumns="True" Margin="0,0,0,0" CanUserReorderColumns="False" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Auto" CanUserSortColumns="False">
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="Address" Binding="{Binding Address}"/>
|
||||
<DataGridTextColumn Header="Version" Binding="{Binding VersionString}"/>
|
||||
<DataGridTextColumn Header="Latency" Binding="{Binding Latency}"/>
|
||||
<DataGridTextColumn Header="Data Paths" Binding="{Binding DataPaths}"/>
|
||||
<DataGridTextColumn Header="Last Unicast" Binding="{Binding LastUnicastFrame}"/>
|
||||
<DataGridTextColumn Header="Last Multicast" Binding="{Binding LastMulticastFrame}"/>
|
||||
<DataGridTextColumn Width="*" Header="Role" Binding="{Binding Role}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</UserControl>
|
|
@ -1,54 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PeersPage.xaml
|
||||
/// </summary>
|
||||
public partial class PeersPage : UserControl
|
||||
{
|
||||
private List<ZeroTierPeer> peersList = new List<ZeroTierPeer>();
|
||||
|
||||
public PeersPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
dataGrid.ItemsSource = peersList;
|
||||
}
|
||||
|
||||
public void SetPeers(List<ZeroTierPeer> list)
|
||||
{
|
||||
if (list == null)
|
||||
return;
|
||||
|
||||
|
||||
foreach(ZeroTierPeer p in list)
|
||||
{
|
||||
ZeroTierPeer curPeer = peersList.Find(peer => peer.Equals(p));
|
||||
if (curPeer == null)
|
||||
{
|
||||
peersList.Add(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
curPeer.Update(p);
|
||||
}
|
||||
}
|
||||
|
||||
dataGrid.Items.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<Window x:Class="WinUI.PreferencesView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WinUI"
|
||||
mc:Ignorable="d"
|
||||
Title="PreferencesView" SizeToContent="WidthAndHeight" Height="Auto" Width="Auto" Icon="ZeroTierIcon.ico">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<CheckBox x:Name="startupCheckbox" Content="Launch ZeroTier On Startup" HorizontalAlignment="Left" Margin="10" VerticalAlignment="Top" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="0"/>
|
||||
|
||||
<TextBlock Text="Central Instance:" Grid.Row="1" Grid.Column="0" Margin="10"/>
|
||||
<TextBox x:Name="CentralInstanceTextBox" Grid.Row="1" Grid.Column="1" MinWidth="200" Margin="10"/>
|
||||
|
||||
<TextBlock Text="API Key:" Grid.Row="2" Grid.Column="0" Margin="10"/>
|
||||
<TextBox x:Name="APIKeyTextBox" Grid.Row="2" Grid.Column="1" MinWidth="200" Margin="10"/>
|
||||
|
||||
<Button x:Name="OKButton" Grid.Row="3" Grid.Column="1" Background="#FFFFB354" Content="OK" Margin="10" Width="90" HorizontalAlignment="Right" Click="OKButton_Clicked"/>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,74 +0,0 @@
|
|||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for PreferencesView.xaml
|
||||
/// </summary>
|
||||
public partial class PreferencesView : Window
|
||||
{
|
||||
public static string AppName = "ZeroTier One";
|
||||
private RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||
private string AppLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
public PreferencesView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
string keyValue = rk.GetValue(AppName) as string;
|
||||
|
||||
if (keyValue != null && keyValue.Equals(AppLocation))
|
||||
{
|
||||
startupCheckbox.IsChecked = true;
|
||||
}
|
||||
|
||||
CentralAPI api = CentralAPI.Instance;
|
||||
CentralInstanceTextBox.Text = api.Central.ServerURL;
|
||||
APIKeyTextBox.Text = api.Central.APIKey;
|
||||
}
|
||||
|
||||
private void OKButton_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CentralAPI api = CentralAPI.Instance;
|
||||
|
||||
if (api.Central.ServerURL != CentralInstanceTextBox.Text ||
|
||||
api.Central.APIKey != APIKeyTextBox.Text)
|
||||
{
|
||||
CentralServer newServer = new CentralServer();
|
||||
newServer.ServerURL = CentralInstanceTextBox.Text;
|
||||
newServer.APIKey = APIKeyTextBox.Text;
|
||||
|
||||
api.Central = newServer;
|
||||
}
|
||||
|
||||
if (startupCheckbox.IsChecked.HasValue && (bool)startupCheckbox.IsChecked)
|
||||
{
|
||||
rk.SetValue(AppName, AppLocation);
|
||||
}
|
||||
else
|
||||
{
|
||||
string keyValue = rk.GetValue(AppName) as string;
|
||||
|
||||
if (keyValue != null && keyValue.Equals(AppLocation))
|
||||
{
|
||||
rk.DeleteValue(AppName);
|
||||
}
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ZeroTier One")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("ZeroTier, Inc")]
|
||||
[assembly: AssemblyProduct("ZeroTier One")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: NeutralResourcesLanguageAttribute("en-US")]
|
73
windows/WinUI/Properties/Resources.Designer.cs
generated
73
windows/WinUI/Properties/Resources.Designer.cs
generated
|
@ -1,73 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WinUI.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WinUI.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||
/// </summary>
|
||||
internal static System.Drawing.Icon ZeroTierIcon {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("ZeroTierIcon", resourceCulture);
|
||||
return ((System.Drawing.Icon)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="ZeroTierIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\ZeroTierIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
30
windows/WinUI/Properties/Settings.Designer.cs
generated
30
windows/WinUI/Properties/Settings.Designer.cs
generated
|
@ -1,30 +0,0 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace WinUI.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
Binary file not shown.
Before Width: | Height: | Size: 44 KiB |
File diff suppressed because it is too large
Load diff
|
@ -1,6 +0,0 @@
|
|||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:WinUI">
|
||||
|
||||
</ResourceDictionary>
|
|
@ -1,65 +0,0 @@
|
|||
<Window x:Class="WinUI.ToolbarItem"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:WinUI"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
|
||||
mc:Ignorable="d"
|
||||
Height="300" Width="300" Visibility="Hidden" Name="Toolbar">
|
||||
|
||||
<Window.Resources>
|
||||
<CollectionViewSource Source="{Binding ElementName=Toolbar, Path=NetworkCollection}" x:Key="KnownNetworks">
|
||||
<CollectionViewSource.SortDescriptions>
|
||||
<scm:SortDescription PropertyName="Header" Direction="Ascending"/>
|
||||
</CollectionViewSource.SortDescriptions>
|
||||
</CollectionViewSource>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<tb:TaskbarIcon x:Name="MyNotifyIcon"
|
||||
IconSource="ZeroTierIcon.ico"
|
||||
ToolTipText="ZeroTier One"
|
||||
MenuActivation="LeftOrRightClick">
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<ContextMenu.ItemsSource>
|
||||
<CompositeCollection>
|
||||
<MenuItem Header="Node ID: unknown"
|
||||
Click="ToolbarItem_NodeIDClicked"
|
||||
x:Name="nodeIdMenuItem"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Join Network..."
|
||||
Click="ToolbarItem_JoinNetworkClicked"/>
|
||||
<MenuItem Header="Show Networks..."
|
||||
Click="ToolbarItem_ShowNetworksClicked"/>
|
||||
<Separator/>
|
||||
|
||||
<CollectionContainer Collection="{Binding Source={StaticResource KnownNetworks}}">
|
||||
|
||||
</CollectionContainer>
|
||||
|
||||
<Separator/>
|
||||
<MenuItem Header="ZeroTier Central"
|
||||
Click="ToolbarItem_CentralClicked"/>
|
||||
<MenuItem Header="Create and Join Network"
|
||||
Click="ToolbarItem_NewNetwork"
|
||||
x:Name="newNetworkItem"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="About..."
|
||||
Click="ToolbarItem_AboutClicked"/>
|
||||
<MenuItem Header="Preferences..."
|
||||
Click="ToolbarItem_PreferencesClicked"/>
|
||||
<Separator/>
|
||||
<MenuItem Header="Quit"
|
||||
Click="ToolbarItem_QuitClicked"/>
|
||||
|
||||
</CompositeCollection>
|
||||
</ContextMenu.ItemsSource>
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -1,353 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Timers;
|
||||
using System.Windows.Threading;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ToolbarItem.xaml
|
||||
/// </summary>
|
||||
public partial class ToolbarItem : Window, INotifyPropertyChanged
|
||||
{
|
||||
private APIHandler handler = APIHandler.Instance;
|
||||
|
||||
private Point netListLocation = new Point(0, 0);
|
||||
private Point joinNetLocation = new Point(0, 0);
|
||||
private Point aboutViewLocation = new Point(0, 0);
|
||||
private Point prefsViewLocation = new Point(0, 0);
|
||||
|
||||
private NetworkListView netListView = new NetworkListView();
|
||||
private JoinNetworkView joinNetView = null;
|
||||
private AboutView aboutView = null;
|
||||
private PreferencesView prefsView = null;
|
||||
|
||||
private NetworkMonitor mon = NetworkMonitor.Instance;
|
||||
|
||||
private ObservableCollection<MenuItem> _networkCollection = new ObservableCollection<MenuItem>();
|
||||
|
||||
|
||||
public ObservableCollection<MenuItem> NetworkCollection
|
||||
{
|
||||
get { return _networkCollection; }
|
||||
set { _networkCollection = value; }
|
||||
}
|
||||
|
||||
private string nodeId;
|
||||
|
||||
public ToolbarItem()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
mon.SubscribeNetworkUpdates(updateNetworks);
|
||||
mon.SubscribeStatusUpdates(updateStatus);
|
||||
|
||||
SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
|
||||
}
|
||||
|
||||
~ToolbarItem()
|
||||
{
|
||||
mon.UnsubscribeNetworkUpdates(updateNetworks);
|
||||
mon.UnsubscribeStatusUpdates(updateStatus);
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void updateNetworks(List<ZeroTierNetwork> networks)
|
||||
{
|
||||
if (networks != null)
|
||||
{
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
NetworkCollection.Clear();
|
||||
foreach (ZeroTierNetwork n in networks)
|
||||
{
|
||||
MenuItem item = new MenuItem();
|
||||
item.Header = n.Title.Replace("_", "__");
|
||||
item.DataContext = n;
|
||||
item.IsChecked = n.IsConnected;
|
||||
item.Click += ToolbarItem_NetworkClicked;
|
||||
|
||||
NetworkCollection.Add(item);
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatus(ZeroTierStatus status)
|
||||
{
|
||||
if (status != null)
|
||||
{
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
|
||||
{
|
||||
nodeIdMenuItem.Header = "Node ID: " + status.Address;
|
||||
nodeIdMenuItem.IsEnabled = true;
|
||||
nodeId = status.Address;
|
||||
|
||||
if (CentralAPI.Instance.HasAccessToken())
|
||||
{
|
||||
newNetworkItem.IsEnabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
newNetworkItem.IsEnabled = false;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void ToolbarItem_NodeIDClicked(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
Clipboard.SetDataObject(nodeId);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
// tried to copy a null nodeId
|
||||
Console.WriteLine("ArgumentNullException");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void ToolbarItem_ShowNetworksClicked(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
if (netListView == null)
|
||||
{
|
||||
netListView = new WinUI.NetworkListView();
|
||||
netListView.Closed += ShowNetworksClosed;
|
||||
}
|
||||
|
||||
bool netListNeedsMoving = true;
|
||||
if (netListLocation.X > 0 && netListLocation.Y > 0)
|
||||
{
|
||||
netListView.Left = netListLocation.X;
|
||||
netListView.Top = netListLocation.Y;
|
||||
netListNeedsMoving = false;
|
||||
}
|
||||
|
||||
netListView.Show();
|
||||
|
||||
if (netListNeedsMoving)
|
||||
{
|
||||
setWindowPosition(netListView);
|
||||
netListLocation.X = netListView.Left;
|
||||
netListLocation.Y = netListView.Top;
|
||||
}
|
||||
|
||||
netListView.Activate();
|
||||
}
|
||||
|
||||
private void ShowNetworksClosed(object sender, System.EventArgs e)
|
||||
{
|
||||
netListView = null;
|
||||
}
|
||||
|
||||
private void ToolbarItem_JoinNetworkClicked(object sender, System.EventArgs e)
|
||||
{
|
||||
if (joinNetView == null)
|
||||
{
|
||||
joinNetView = new JoinNetworkView();
|
||||
joinNetView.Closed += JoinNetworkClosed;
|
||||
|
||||
bool needsMove = true;
|
||||
if (joinNetLocation.X > 0 && joinNetLocation.Y > 0)
|
||||
{
|
||||
joinNetView.Left = joinNetLocation.X;
|
||||
joinNetView.Top = joinNetLocation.Y;
|
||||
needsMove = false;
|
||||
}
|
||||
|
||||
joinNetView.Show();
|
||||
|
||||
if (needsMove)
|
||||
{
|
||||
setWindowPosition(joinNetView);
|
||||
joinNetLocation.X = joinNetView.Left;
|
||||
joinNetLocation.Y = joinNetView.Top;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
joinNetView.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
private void JoinNetworkClosed(object sender, System.EventArgs e)
|
||||
{
|
||||
joinNetView = null;
|
||||
}
|
||||
|
||||
private void ToolbarItem_CentralClicked(object sender, System.EventArgs e)
|
||||
{
|
||||
Process.Start("https://my.zerotier.com");
|
||||
}
|
||||
|
||||
private void ToolbarItem_AboutClicked(object sender, System.EventArgs e)
|
||||
{
|
||||
if (aboutView == null)
|
||||
{
|
||||
aboutView = new AboutView();
|
||||
aboutView.Closed += AboutClosed;
|
||||
|
||||
bool needsMove = true;
|
||||
if (aboutViewLocation.X > 0 && aboutViewLocation.Y > 0)
|
||||
{
|
||||
aboutView.Left = aboutViewLocation.X;
|
||||
aboutView.Top = aboutViewLocation.Y;
|
||||
needsMove = false;
|
||||
}
|
||||
|
||||
aboutView.Show();
|
||||
|
||||
if (needsMove)
|
||||
{
|
||||
setWindowPosition(aboutView);
|
||||
aboutViewLocation.X = aboutView.Left;
|
||||
aboutViewLocation.Y = aboutView.Top;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
aboutView.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
private void AboutClosed(object sender, System.EventArgs e)
|
||||
{
|
||||
aboutView = null;
|
||||
}
|
||||
|
||||
private void ToolbarItem_PreferencesClicked(object sender, System.EventArgs e)
|
||||
{
|
||||
if (prefsView == null)
|
||||
{
|
||||
prefsView = new PreferencesView();
|
||||
prefsView.Closed += PreferencesClosed;
|
||||
|
||||
bool needsMove = true;
|
||||
if (prefsViewLocation.X > 0 && prefsViewLocation.Y > 0)
|
||||
{
|
||||
prefsView.Left = prefsViewLocation.X;
|
||||
prefsView.Top = prefsViewLocation.Y;
|
||||
needsMove = false;
|
||||
}
|
||||
|
||||
prefsView.Show();
|
||||
|
||||
if (needsMove)
|
||||
{
|
||||
setWindowPosition(prefsView);
|
||||
prefsViewLocation.X = prefsView.Left;
|
||||
prefsViewLocation.Y = prefsView.Top;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
prefsView.Activate();
|
||||
}
|
||||
}
|
||||
|
||||
private void PreferencesClosed(object sender, System.EventArgs e)
|
||||
{
|
||||
prefsView = null;
|
||||
}
|
||||
|
||||
private void ToolbarItem_QuitClicked(object sender, System.EventArgs e)
|
||||
{
|
||||
NetworkMonitor.Instance.StopMonitor();
|
||||
Close();
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
|
||||
private void ToolbarItem_NetworkClicked(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
if(sender.GetType() == typeof(MenuItem))
|
||||
{
|
||||
MenuItem item = e.Source as MenuItem;
|
||||
if (item.DataContext != null)
|
||||
{
|
||||
ZeroTierNetwork network = item.DataContext as ZeroTierNetwork;
|
||||
if (item.IsChecked)
|
||||
{
|
||||
APIHandler.Instance.LeaveNetwork(Dispatcher, network.NetworkId);
|
||||
}
|
||||
else
|
||||
{
|
||||
APIHandler.Instance.JoinNetwork(Dispatcher, network.NetworkId, network.AllowManaged, network.AllowGlobal, network.AllowDefault);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void ToolbarItem_NewNetwork(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
if (CentralAPI.Instance.HasAccessToken())
|
||||
{
|
||||
CentralAPI api = CentralAPI.Instance;
|
||||
CentralNetwork newNetwork = await api.CreateNewNetwork();
|
||||
|
||||
APIHandler handler = APIHandler.Instance;
|
||||
handler.JoinNetwork(this.Dispatcher, newNetwork.Id);
|
||||
|
||||
string nodeId = APIHandler.Instance.NodeAddress();
|
||||
bool authorized = await CentralAPI.Instance.AuthorizeNode(nodeId, newNetwork.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void setWindowPosition(Window w)
|
||||
{
|
||||
double width = w.ActualWidth;
|
||||
double height = w.ActualHeight;
|
||||
|
||||
double screenHeight = SystemParameters.PrimaryScreenHeight;
|
||||
double screenWidth = SystemParameters.PrimaryScreenWidth;
|
||||
|
||||
double top = screenHeight - height - 40;
|
||||
double left = screenWidth - width - 20;
|
||||
|
||||
w.Top = top;
|
||||
w.Left = left;
|
||||
}
|
||||
|
||||
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
|
||||
{
|
||||
// reset cached locations to (0, 0) when display size changes
|
||||
netListLocation.X = 0;
|
||||
netListLocation.Y = 0;
|
||||
joinNetLocation.X = 0;
|
||||
joinNetLocation.Y = 0;
|
||||
aboutViewLocation.X = 0;
|
||||
aboutViewLocation.Y = 0;
|
||||
prefsViewLocation.X = 0;
|
||||
prefsViewLocation.Y = 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,273 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WinUI</RootNamespace>
|
||||
<AssemblyName>ZeroTier One</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ExpressionBlendVersion>5.0.40218.0</ExpressionBlendVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<AutorunEnabled>true</AutorunEnabled>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.0</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WinUI.App</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>ZeroTierIcon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignManifests>false</SignManifests>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<Reference Include="Accessibility" />
|
||||
<Reference Include="Hardcodet.Wpf.TaskbarNotification, Version=1.0.5.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PresentationUI, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
|
||||
<Reference Include="ReachFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Printing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="UIAutomationProvider" />
|
||||
<Reference Include="UIAutomationTypes" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="AboutView.xaml.cs">
|
||||
<DependentUpon>AboutView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CentralAPI.cs" />
|
||||
<Compile Include="CentralLogin.cs" />
|
||||
<Compile Include="CentralNetwork.cs" />
|
||||
<Compile Include="CentralServer.cs" />
|
||||
<Compile Include="CentralToken.cs" />
|
||||
<Compile Include="CentralUser.cs" />
|
||||
<Compile Include="ISwitchable.cs" />
|
||||
<Compile Include="JoinNetworkView.xaml.cs">
|
||||
<DependentUpon>JoinNetworkView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="NetworkMonitor.cs" />
|
||||
<Compile Include="NetworkNameGenerator.cs" />
|
||||
<Compile Include="NetworkRoute.cs" />
|
||||
<Compile Include="NetworksPage.xaml.cs">
|
||||
<DependentUpon>NetworksPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PeersPage.xaml.cs">
|
||||
<DependentUpon>PeersPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="PreferencesView.xaml.cs">
|
||||
<DependentUpon>PreferencesView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ToolbarItem.xaml.cs">
|
||||
<DependentUpon>ToolbarItem.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ZeroTierPeerPhysicalPath.cs" />
|
||||
<Compile Include="ZeroTierPeer.cs" />
|
||||
<Compile Include="ZeroTierNetwork.cs" />
|
||||
<Compile Include="ZeroTierStatus.cs" />
|
||||
<Page Include="AboutView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="JoinNetworkView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="NetworkListView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="APIHandler.cs" />
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="NetworkListView.xaml.cs">
|
||||
<DependentUpon>NetworkListView.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="NetworkInfoView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="NetworksPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="PeersPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="PreferencesView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Simple Styles.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Themes\Generic.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="ToolbarItem.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NetworkInfoView.xaml.cs">
|
||||
<DependentUpon>NetworkInfoView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.manifest" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BlendEmbeddedFont Include="Fonts\segoeui.ttf">
|
||||
<IsSystemFont>True</IsSystemFont>
|
||||
<All>True</All>
|
||||
<AutoFill>True</AutoFill>
|
||||
</BlendEmbeddedFont>
|
||||
<BlendEmbeddedFont Include="Fonts\segoeuib.ttf">
|
||||
<IsSystemFont>True</IsSystemFont>
|
||||
<All>True</All>
|
||||
<AutoFill>True</AutoFill>
|
||||
</BlendEmbeddedFont>
|
||||
<BlendEmbeddedFont Include="Fonts\segoeuii.ttf">
|
||||
<IsSystemFont>True</IsSystemFont>
|
||||
<All>True</All>
|
||||
<AutoFill>True</AutoFill>
|
||||
</BlendEmbeddedFont>
|
||||
<BlendEmbeddedFont Include="Fonts\segoeuiz.ttf">
|
||||
<IsSystemFont>True</IsSystemFont>
|
||||
<All>True</All>
|
||||
<AutoFill>True</AutoFill>
|
||||
</BlendEmbeddedFont>
|
||||
<Resource Include="ZeroTierIcon.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\ZeroTierIcon.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy "$(SolutionDir)\copyutil\bin\$(ConfigurationName)\copyutil.exe" "$(ProjectDir)\$(OutDir)\copyutil.exe"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Binary file not shown.
Before Width: | Height: | Size: 361 KiB |
|
@ -1,516 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
[Serializable]
|
||||
public class ZeroTierNetwork : ISerializable, IEquatable<ZeroTierNetwork>, IComparable<ZeroTierNetwork>, INotifyPropertyChanged
|
||||
{
|
||||
private string networkId;
|
||||
private string macAddress;
|
||||
private string networkName;
|
||||
private string networkStatus;
|
||||
private string networkType;
|
||||
private Int32 mtu;
|
||||
private bool dhcp;
|
||||
private bool bridge;
|
||||
private bool broadcastEnabled;
|
||||
private Int32 portError;
|
||||
private Int32 netconfRevision;
|
||||
private string[] assignedAddresses;
|
||||
private NetworkRoute[] routes;
|
||||
private string deviceName;
|
||||
private bool allowManaged;
|
||||
private bool allowGlobal;
|
||||
private bool allowDefault;
|
||||
private bool allowDNS;
|
||||
private bool isConnected;
|
||||
|
||||
protected ZeroTierNetwork(SerializationInfo info, StreamingContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
NetworkId = info.GetString("nwid");
|
||||
MacAddress = info.GetString("mac");
|
||||
NetworkName = info.GetString("name");
|
||||
NetworkStatus = info.GetString("status");
|
||||
NetworkType = info.GetString("type");
|
||||
MTU = info.GetInt32("mtu");
|
||||
DHCP = info.GetBoolean("dhcp");
|
||||
Bridge = info.GetBoolean("bridge");
|
||||
BroadcastEnabled = info.GetBoolean("broadcastEnabled");
|
||||
PortError = info.GetInt32("portError");
|
||||
NetconfRevision = info.GetInt32("netconfRevision");
|
||||
AssignedAddresses = (string[])info.GetValue("assignedAddresses", typeof(string[]));
|
||||
Routes = (NetworkRoute[])info.GetValue("routes", typeof(NetworkRoute[]));
|
||||
DeviceName = info.GetString("portDeviceName");
|
||||
AllowManaged = info.GetBoolean("allowManaged");
|
||||
AllowGlobal = info.GetBoolean("allowGlobal");
|
||||
AllowDefault = info.GetBoolean("allowDefault");
|
||||
AllowDNS = info.GetBoolean("allowDNS");
|
||||
}
|
||||
catch { }
|
||||
IsConnected = false;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public virtual void GetObjectData(SerializationInfo info, StreamingContext ctx)
|
||||
{
|
||||
info.AddValue("nwid", NetworkId);
|
||||
info.AddValue("mac", MacAddress);
|
||||
info.AddValue("name", NetworkName);
|
||||
info.AddValue("status", NetworkStatus);
|
||||
info.AddValue("type", NetworkType);
|
||||
info.AddValue("mtu", MTU);
|
||||
info.AddValue("dhcp", DHCP);
|
||||
info.AddValue("bridge", Bridge);
|
||||
info.AddValue("broadcastEnabled", BroadcastEnabled);
|
||||
info.AddValue("portError", PortError);
|
||||
info.AddValue("netconfRevision", NetconfRevision);
|
||||
info.AddValue("assignedAddresses", AssignedAddresses);
|
||||
info.AddValue("routes", Routes);
|
||||
info.AddValue("portDeviceName", DeviceName);
|
||||
info.AddValue("allowManaged", AllowManaged);
|
||||
info.AddValue("allowGlobal", AllowGlobal);
|
||||
info.AddValue("allowDefault", AllowDefault);
|
||||
info.AddValue("allowDNS", AllowDNS);
|
||||
}
|
||||
|
||||
public void UpdateNetwork(ZeroTierNetwork network)
|
||||
{
|
||||
if (network == null)
|
||||
return;
|
||||
|
||||
if (!NetworkId.Equals(network.NetworkId))
|
||||
{
|
||||
NetworkId = network.NetworkId;
|
||||
}
|
||||
|
||||
if (!MacAddress.Equals(network.MacAddress))
|
||||
{
|
||||
MacAddress = network.MacAddress;
|
||||
}
|
||||
|
||||
if (!NetworkName.Equals(network.NetworkName))
|
||||
{
|
||||
NetworkName = network.NetworkName;
|
||||
}
|
||||
|
||||
if (!NetworkStatus.Equals(network.NetworkStatus))
|
||||
{
|
||||
NetworkStatus = network.NetworkStatus;
|
||||
}
|
||||
|
||||
if (!NetworkType.Equals(network.NetworkType))
|
||||
{
|
||||
NetworkType = network.NetworkType;
|
||||
}
|
||||
|
||||
if (MTU != network.MTU)
|
||||
{
|
||||
MTU = network.MTU;
|
||||
}
|
||||
|
||||
if (DHCP != network.DHCP)
|
||||
{
|
||||
DHCP = network.DHCP;
|
||||
}
|
||||
|
||||
if (Bridge != network.Bridge)
|
||||
{
|
||||
Bridge = network.Bridge;
|
||||
}
|
||||
|
||||
if (BroadcastEnabled != network.BroadcastEnabled)
|
||||
{
|
||||
BroadcastEnabled = network.BroadcastEnabled;
|
||||
}
|
||||
|
||||
if (PortError != network.PortError)
|
||||
{
|
||||
PortError = network.PortError;
|
||||
}
|
||||
|
||||
if (NetconfRevision != network.NetconfRevision)
|
||||
{
|
||||
NetconfRevision = network.NetconfRevision;
|
||||
}
|
||||
|
||||
AssignedAddresses = network.AssignedAddresses;
|
||||
|
||||
Routes = network.Routes;
|
||||
|
||||
if (!DeviceName.Equals(network.DeviceName))
|
||||
{
|
||||
DeviceName = network.DeviceName;
|
||||
}
|
||||
|
||||
if (AllowManaged != network.AllowManaged)
|
||||
{
|
||||
AllowManaged = network.AllowManaged;
|
||||
}
|
||||
|
||||
if (AllowGlobal != network.AllowGlobal)
|
||||
{
|
||||
AllowGlobal = network.AllowGlobal;
|
||||
}
|
||||
|
||||
if (AllowDefault != network.AllowDefault)
|
||||
{
|
||||
AllowDefault = network.AllowDefault;
|
||||
}
|
||||
|
||||
if (AllowDNS != network.AllowDNS)
|
||||
{
|
||||
AllowDNS = network.AllowDNS;
|
||||
}
|
||||
|
||||
if (IsConnected != network.IsConnected)
|
||||
{
|
||||
IsConnected = network.IsConnected;
|
||||
}
|
||||
}
|
||||
|
||||
protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
[JsonProperty("nwid")]
|
||||
public string NetworkId {
|
||||
get
|
||||
{
|
||||
return networkId;
|
||||
}
|
||||
set
|
||||
{
|
||||
networkId = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("mac")]
|
||||
public string MacAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return macAddress;
|
||||
}
|
||||
set
|
||||
{
|
||||
macAddress = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string NetworkName
|
||||
{
|
||||
get
|
||||
{
|
||||
return networkName;
|
||||
}
|
||||
set
|
||||
{
|
||||
networkName = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("status")]
|
||||
public string NetworkStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return networkStatus;
|
||||
}
|
||||
set
|
||||
{
|
||||
networkStatus = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonProperty("type")]
|
||||
public string NetworkType
|
||||
{
|
||||
get
|
||||
{
|
||||
return networkType;
|
||||
}
|
||||
set
|
||||
{
|
||||
networkType = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("mtu")]
|
||||
public int MTU
|
||||
{
|
||||
get
|
||||
{
|
||||
return mtu;
|
||||
}
|
||||
set
|
||||
{
|
||||
mtu = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("dhcp")]
|
||||
public bool DHCP
|
||||
{
|
||||
get
|
||||
{
|
||||
return dhcp;
|
||||
}
|
||||
set
|
||||
{
|
||||
dhcp = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("bridge")]
|
||||
public bool Bridge
|
||||
{
|
||||
get
|
||||
{
|
||||
return bridge;
|
||||
}
|
||||
set
|
||||
{
|
||||
bridge = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("broadcastEnabled")]
|
||||
public bool BroadcastEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return broadcastEnabled;
|
||||
}
|
||||
set
|
||||
{
|
||||
broadcastEnabled = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("portError")]
|
||||
public int PortError
|
||||
{
|
||||
get
|
||||
{
|
||||
return portError;
|
||||
}
|
||||
set
|
||||
{
|
||||
portError = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("netconfRevision")]
|
||||
public int NetconfRevision
|
||||
{
|
||||
get
|
||||
{
|
||||
return netconfRevision;
|
||||
}
|
||||
set
|
||||
{
|
||||
netconfRevision = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("assignedAddresses")]
|
||||
public string[] AssignedAddresses
|
||||
{
|
||||
get
|
||||
{
|
||||
return assignedAddresses;
|
||||
}
|
||||
set
|
||||
{
|
||||
assignedAddresses = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("routes")]
|
||||
public NetworkRoute[] Routes
|
||||
{
|
||||
get
|
||||
{
|
||||
return routes;
|
||||
}
|
||||
set
|
||||
{
|
||||
routes = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("portDeviceName")]
|
||||
public string DeviceName
|
||||
{
|
||||
get
|
||||
{
|
||||
return deviceName;
|
||||
}
|
||||
set
|
||||
{
|
||||
deviceName = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("allowManaged")]
|
||||
public bool AllowManaged
|
||||
{
|
||||
get
|
||||
{
|
||||
return allowManaged;
|
||||
}
|
||||
set
|
||||
{
|
||||
allowManaged = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("allowGlobal")]
|
||||
public bool AllowGlobal
|
||||
{
|
||||
get
|
||||
{
|
||||
return allowGlobal;
|
||||
}
|
||||
set
|
||||
{
|
||||
allowGlobal = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("allowDefault")]
|
||||
public bool AllowDefault
|
||||
{
|
||||
get
|
||||
{
|
||||
return allowDefault;
|
||||
}
|
||||
set
|
||||
{
|
||||
allowDefault = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("allowDNS")]
|
||||
public bool AllowDNS
|
||||
{
|
||||
get
|
||||
{
|
||||
return allowDNS;
|
||||
}
|
||||
set
|
||||
{
|
||||
allowDNS = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsConnected
|
||||
{
|
||||
get
|
||||
{
|
||||
return isConnected;
|
||||
}
|
||||
set
|
||||
{
|
||||
isConnected = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public String Title
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (NetworkName != null && NetworkName.Length > 0)
|
||||
{
|
||||
return NetworkId + " (" + NetworkName + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
return NetworkId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(ZeroTierNetwork network)
|
||||
{
|
||||
if (NetworkId == null || network == null)
|
||||
return false;
|
||||
|
||||
return NetworkId.Equals(network.NetworkId);
|
||||
}
|
||||
|
||||
public int CompareTo(ZeroTierNetwork network)
|
||||
{
|
||||
if (NetworkId == null || network == null)
|
||||
return -1;
|
||||
|
||||
UInt64 thisNwid = UInt64.Parse(NetworkId, System.Globalization.NumberStyles.HexNumber);
|
||||
UInt64 otherNwid = UInt64.Parse(network.NetworkId, System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
if (thisNwid > otherNwid)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if (thisNwid < otherNwid)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class NetworkEqualityComparer : IEqualityComparer<ZeroTierNetwork>
|
||||
{
|
||||
public bool Equals(ZeroTierNetwork lhs, ZeroTierNetwork rhs)
|
||||
{
|
||||
if (lhs.NetworkId.Equals(rhs.NetworkId))
|
||||
{
|
||||
lhs.UpdateNetwork(rhs);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetHashCode(ZeroTierNetwork obj)
|
||||
{
|
||||
return obj.NetworkId.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,116 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
public class ZeroTierPeer : IEquatable<ZeroTierPeer>
|
||||
{
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
private Int64 _lastUnicast;
|
||||
[JsonProperty("lastUnicastFrame")]
|
||||
public Int64 LastUnicastFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_lastUnicast == 0)
|
||||
return 0;
|
||||
|
||||
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
|
||||
Int64 millisecondsSinceEpoch = (Int64)t.TotalMilliseconds;
|
||||
return (millisecondsSinceEpoch - _lastUnicast) / 1000;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastUnicast = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Int64 _lastMulticast;
|
||||
[JsonProperty("lastMulticastFrame")]
|
||||
public Int64 LastMulticastFrame
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_lastMulticast == 0)
|
||||
return 0;
|
||||
|
||||
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
|
||||
Int64 millisecondsSinceEpoch = (Int64)t.TotalMilliseconds;
|
||||
return (millisecondsSinceEpoch - _lastMulticast) / 1000;
|
||||
}
|
||||
set
|
||||
{
|
||||
_lastMulticast = value;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("versionMajor")]
|
||||
public int VersionMajor { get; set; }
|
||||
|
||||
[JsonProperty("versionMinor")]
|
||||
public int VersionMinor { get; set; }
|
||||
|
||||
[JsonProperty("versionRev")]
|
||||
public int VersionRev { get; set; }
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
public string VersionString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Version == "-1.-1.-1")
|
||||
return "-";
|
||||
else
|
||||
return Version;
|
||||
}
|
||||
}
|
||||
|
||||
[JsonProperty("latency")]
|
||||
public string Latency { get; set; }
|
||||
|
||||
[JsonProperty("role")]
|
||||
public string Role { get; set; }
|
||||
|
||||
[JsonProperty("paths")]
|
||||
public List<ZeroTierPeerPhysicalPath> Paths { get; set; }
|
||||
|
||||
public string DataPaths
|
||||
{
|
||||
get
|
||||
{
|
||||
string pathStr = "";
|
||||
foreach(ZeroTierPeerPhysicalPath path in Paths)
|
||||
{
|
||||
pathStr += path.Address + "\n";
|
||||
}
|
||||
return pathStr;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Equals(ZeroTierPeer other)
|
||||
{
|
||||
return this.Address.Equals(other.Address, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public void Update(ZeroTierPeer other)
|
||||
{
|
||||
_lastUnicast = other._lastUnicast;
|
||||
_lastMulticast = other._lastMulticast;
|
||||
VersionMajor = other.VersionMajor;
|
||||
VersionMinor = other.VersionMinor;
|
||||
VersionRev = other.VersionRev;
|
||||
Version = other.Version;
|
||||
Latency = other.Latency;
|
||||
Role = other.Role;
|
||||
Paths = other.Paths;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
public class ZeroTierPeerPhysicalPath
|
||||
{
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[JsonProperty("lastSend")]
|
||||
public UInt64 LastSend { get; set; }
|
||||
|
||||
[JsonProperty("lastReceive")]
|
||||
public UInt64 LastReceive { get; set; }
|
||||
|
||||
[JsonProperty("fixed")]
|
||||
public bool Fixed { get; set; }
|
||||
|
||||
[JsonProperty("preferred")]
|
||||
public bool Preferred { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WinUI
|
||||
{
|
||||
public class ZeroTierStatus
|
||||
{
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[JsonProperty("publicIdentity")]
|
||||
public string PublicIdentity { get; set; }
|
||||
|
||||
[JsonProperty("online")]
|
||||
public bool Online { get; set; }
|
||||
|
||||
[JsonProperty("tcpFallbackActive")]
|
||||
public bool TcpFallbackActive { get; set; }
|
||||
|
||||
[JsonProperty("versionMajor")]
|
||||
public int VersionMajor { get; set; }
|
||||
|
||||
[JsonProperty("versionMinor")]
|
||||
public int VersionMinor { get; set; }
|
||||
|
||||
[JsonProperty("versionRev")]
|
||||
public int VersionRev { get; set; }
|
||||
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
[JsonProperty("clock")]
|
||||
public UInt64 Clock { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||
<security>
|
||||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<!-- UAC Manifest Options
|
||||
If you want to change the Windows User Account Control level replace the
|
||||
requestedExecutionLevel node with one of the following.
|
||||
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
|
||||
|
||||
Specifying requestedExecutionLevel node will disable file and registry virtualization.
|
||||
If you want to utilize File and Registry Virtualization for backward
|
||||
compatibility then delete the requestedExecutionLevel node.
|
||||
-->
|
||||
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||
<application>
|
||||
<!-- A list of all Windows versions that this application is designed to work with.
|
||||
Windows will automatically select the most compatible environment.-->
|
||||
|
||||
<!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
|
||||
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>-->
|
||||
|
||||
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
|
||||
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
|
||||
|
||||
<!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
|
||||
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>-->
|
||||
|
||||
</application>
|
||||
</compatibility>
|
||||
|
||||
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
|
||||
<!-- <dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity
|
||||
type="win32"
|
||||
name="Microsoft.Windows.Common-Controls"
|
||||
version="6.0.0.0"
|
||||
processorArchitecture="*"
|
||||
publicKeyToken="6595b64144ccf1df"
|
||||
language="*"
|
||||
/>
|
||||
</dependentAssembly>
|
||||
</dependency>-->
|
||||
|
||||
</asmv1:assembly>
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue