From 8cced06a2dff66300a46e2962cd462f58096b15c Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 3 Nov 2016 10:04:50 -0700 Subject: upgraded vcxprojs to VS2015. got the tap driver building. --- windows/TapDriver6/TapDriver6.vcxproj | 45 ++++++++++++++++++++++++--------- windows/TapDriver6/tap-windows.h | 4 ++- windows/ZeroTierOne/ZeroTierOne.vcxproj | 10 ++++---- 3 files changed, 41 insertions(+), 18 deletions(-) (limited to 'windows') diff --git a/windows/TapDriver6/TapDriver6.vcxproj b/windows/TapDriver6/TapDriver6.vcxproj index b1f9ae18..cf6b1500 100644 --- a/windows/TapDriver6/TapDriver6.vcxproj +++ b/windows/TapDriver6/TapDriver6.vcxproj @@ -63,7 +63,6 @@ $(VCTargetsPath11) - WindowsKernelModeDriver8.0 Driver KMDF @@ -71,54 +70,66 @@ Windows8 true + WindowsKernelModeDriver10.0 Windows8 false + WindowsKernelModeDriver10.0 Windows7 true + WindowsKernelModeDriver10.0 Windows7 false + WindowsKernelModeDriver10.0 Vista true + WindowsKernelModeDriver8.0 Vista false 1 7 + WindowsKernelModeDriver8.0 Windows8 true + WindowsKernelModeDriver10.0 Windows8 false + WindowsKernelModeDriver10.0 Windows7 true + WindowsKernelModeDriver10.0 Windows7 false + WindowsKernelModeDriver10.0 Vista true + WindowsKernelModeDriver8.0 Vista false 1 7 + WindowsKernelModeDriver8.0 @@ -218,10 +229,10 @@ C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies) - C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies) + $(DDK_LIB_PATH)ndis.lib;$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies) - C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies) + $(DDK_LIB_PATH)ndis.lib;$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies) C:\WinDDK\7600.16385.1\lib\win7\amd64\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\amd64\wdmsec.lib;%(AdditionalDependencies) @@ -236,10 +247,10 @@ C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies) - C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies) + $(DDK_LIB_PATH)ndis.lib;$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies) - C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies) + $(DDK_LIB_PATH)ndis.lib;$(DDK_LIB_PATH)ntstrsafe.lib;$(DDK_LIB_PATH)wdmsec.lib;%(AdditionalDependencies) C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\ntstrsafe.lib;C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib;%(AdditionalDependencies) @@ -261,13 +272,18 @@ 3.00.00.0 - false - false + true + true + + + zttap300.cat - 3.00.00.0 + + false false + 3.00.00.0 @@ -291,13 +307,18 @@ 3.00.00.0 - false - false + true + true + + + zttap300.cat + -v "3.00.00.0" %(AdditionalOptions) 3.00.00.0 - false - false + true + true + -v "3.00.00.0" %(AdditionalOptions) 3.00.00.0 diff --git a/windows/TapDriver6/tap-windows.h b/windows/TapDriver6/tap-windows.h index 7e01846d..fd41a798 100644 --- a/windows/TapDriver6/tap-windows.h +++ b/windows/TapDriver6/tap-windows.h @@ -42,7 +42,9 @@ //#define TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT TAP_WIN_CONTROL_CODE (5, METHOD_BUFFERED) #define TAP_WIN_IOCTL_SET_MEDIA_STATUS TAP_WIN_CONTROL_CODE (6, METHOD_BUFFERED) //#define TAP_WIN_IOCTL_CONFIG_DHCP_MASQ TAP_WIN_CONTROL_CODE (7, METHOD_BUFFERED) -//#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED) +#if DBG +#define TAP_WIN_IOCTL_GET_LOG_LINE TAP_WIN_CONTROL_CODE (8, METHOD_BUFFERED) +#endif //#define TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT TAP_WIN_CONTROL_CODE (9, METHOD_BUFFERED) /* Added in 8.2 */ diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj index ed022134..93da4b1b 100644 --- a/windows/ZeroTierOne/ZeroTierOne.vcxproj +++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -184,26 +184,26 @@ Application true - v110 + v140 MultiByte Application true - v110 + v140 MultiByte Application false - v110 + v140 true MultiByte Application false - v110 + v140 true MultiByte -- cgit v1.2.3 From 8ffae313fd5042bb4330afd98019e4ee907714cb Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 3 Nov 2016 12:10:50 -0700 Subject: add new files & remove old ones from VS project. Now builds & runs on Windows again --- .gitignore | 2 +- controller/EmbeddedNetworkController.cpp | 3 +++ node/Membership.cpp | 28 ++++++++++++++++--------- node/Multicaster.cpp | 2 +- one.cpp | 6 +----- windows/ZeroTierOne.sln | 12 +++++++++-- windows/ZeroTierOne/ZeroTierOne.vcxproj | 11 ++++++++-- windows/ZeroTierOne/ZeroTierOne.vcxproj.filters | 27 ++++++++++++++++-------- 8 files changed, 61 insertions(+), 30 deletions(-) (limited to 'windows') diff --git a/.gitignore b/.gitignore index b01abc35..d3ef1581 100755 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,7 @@ Thumbs.db /windows/TapDriver6/win7Release /windows/*.db /windows/*.opendb - +enc_temp_folder # *nix/Mac build droppings /build-* diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index d9ec76de..8f5cefd1 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -21,7 +21,10 @@ #include #include #include + +#ifndef _WIN32 #include +#endif #include #include diff --git a/node/Membership.cpp b/node/Membership.cpp index c8fb8e4e..d7c7c0e6 100644 --- a/node/Membership.cpp +++ b/node/Membership.cpp @@ -232,7 +232,7 @@ Membership::AddCredentialResult Membership::addCredential(const RuntimeEnvironme Membership::_RemoteTag *Membership::_newTag(const uint64_t id) { - _RemoteTag *t; + _RemoteTag *t = NULL; uint64_t minlr = 0xffffffffffffffffULL; for(unsigned int i=0;iid == ZT_MEMBERSHIP_CRED_ID_UNUSED) { @@ -243,17 +243,21 @@ Membership::_RemoteTag *Membership::_newTag(const uint64_t id) minlr = _remoteTags[i]->lastReceived; } } - t->id = id; - t->lastReceived = 0; - t->revocationThreshold = 0; - t->tag = Tag(); + + if (t) { + t->id = id; + t->lastReceived = 0; + t->revocationThreshold = 0; + t->tag = Tag(); + } + std::sort(&(_remoteTags[0]),&(_remoteTags[ZT_MAX_NETWORK_TAGS]),_RemoteCredentialSorter<_RemoteTag>()); return t; } Membership::_RemoteCapability *Membership::_newCapability(const uint64_t id) { - _RemoteCapability *c; + _RemoteCapability *c = NULL; uint64_t minlr = 0xffffffffffffffffULL; for(unsigned int i=0;iid == ZT_MEMBERSHIP_CRED_ID_UNUSED) { @@ -264,10 +268,14 @@ Membership::_RemoteCapability *Membership::_newCapability(const uint64_t id) minlr = _remoteCaps[i]->lastReceived; } } - c->id = id; - c->lastReceived = 0; - c->revocationThreshold = 0; - c->cap = Capability(); + + if (c) { + c->id = id; + c->lastReceived = 0; + c->revocationThreshold = 0; + c->cap = Capability(); + } + std::sort(&(_remoteCaps[0]),&(_remoteCaps[ZT_MAX_NETWORK_CAPABILITIES]),_RemoteCredentialSorter<_RemoteCapability>()); return c; } diff --git a/node/Multicaster.cpp b/node/Multicaster.cpp index 8743e8f8..17649c7b 100644 --- a/node/Multicaster.cpp +++ b/node/Multicaster.cpp @@ -343,7 +343,7 @@ void Multicaster::clean(uint64_t now) { Mutex::Lock _l(_gatherAuth_m); _GatherAuthKey *k = (_GatherAuthKey *)0; - uint64_t *ts = (uint64_t *)ts; + uint64_t *ts = NULL; Hashtable<_GatherAuthKey,uint64_t>::Iterator i(_gatherAuth); while (i.next(k,ts)) { if ((now - *ts) >= ZT_MULTICAST_CREDENTIAL_EXPIRATON) diff --git a/one.cpp b/one.cpp index 79e8caf8..55cc2e19 100644 --- a/one.cpp +++ b/one.cpp @@ -402,7 +402,7 @@ static int cli(int argc,char **argv) auto &addr = assignedAddresses[j]; if (addr.is_string()) { if (aa.length() > 0) aa.push_back(','); - aa.append(addr); + aa.append(addr.get()); } } } @@ -1194,9 +1194,5 @@ int main(int argc,char **argv) delete zt1Service; zt1Service = (OneService *)0; -#ifdef __UNIX_LIKE__ - OSUtils::rm(pidPath.c_str()); -#endif - return returnValue; } diff --git a/windows/ZeroTierOne.sln b/windows/ZeroTierOne.sln index 68596187..e9a1dfd2 100644 --- a/windows/ZeroTierOne.sln +++ b/windows/ZeroTierOne.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZeroTierOne", "ZeroTierOne\ZeroTierOne.vcxproj", "{B00A4957-5977-4AC1-9EF4-571DC27EADA2}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TapDriver6", "TapDriver6\TapDriver6.vcxproj", "{43BA7584-D4DB-4F7C-90FC-E2B18A68A213}" @@ -157,7 +159,8 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Win32.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Win32.Build.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|Win32.Deploy.0 = Debug|Win32 - {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x64.ActiveCfg = Debug|Win32 + {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x64.ActiveCfg = Debug|x64 + {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x64.Build.0 = Debug|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.ActiveCfg = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.Build.0 = Debug|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Debug|x86.Deploy.0 = Debug|Win32 @@ -169,6 +172,7 @@ Global {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Win32.Build.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|Win32.Deploy.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x64.ActiveCfg = Release|x64 + {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x64.Build.0 = Release|x64 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.ActiveCfg = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.Build.0 = Release|Win32 {B00A4957-5977-4AC1-9EF4-571DC27EADA2}.Win7 Release|x86.Deploy.0 = Release|Win32 @@ -392,14 +396,18 @@ Global {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Mixed Platforms.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|Win32.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x64.ActiveCfg = Debug|Any CPU + {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x64.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x86.ActiveCfg = Debug|Any CPU + {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Debug|x86.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Any CPU.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Any CPU.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Mixed Platforms.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Mixed Platforms.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|Win32.ActiveCfg = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x64.ActiveCfg = Release|Any CPU + {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x64.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x86.ActiveCfg = Release|Any CPU + {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win7 Release|x86.Build.0 = Release|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Any CPU.ActiveCfg = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Any CPU.Build.0 = Debug|Any CPU {4CCA6B98-5E64-45BF-AC34-19B3E2570DB1}.Win8 Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj index 93da4b1b..b4bf308c 100644 --- a/windows/ZeroTierOne/ZeroTierOne.vcxproj +++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj @@ -19,8 +19,8 @@ + - @@ -39,12 +39,13 @@ + - + @@ -54,10 +55,12 @@ + + @@ -251,6 +254,7 @@ NOMINMAX;STATICLIB;WIN32;ZT_TRACE;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;%(PreprocessorDefinitions) + 4996 true @@ -267,6 +271,7 @@ NOMINMAX;STATICLIB;WIN32;ZT_TRACE;ZT_USE_MINIUPNPC;MINIUPNP_STATICLIB;%(PreprocessorDefinitions) false + 4996 true @@ -290,6 +295,7 @@ AnySuitable Speed true + 4996 true @@ -315,6 +321,7 @@ AnySuitable Speed true + 4996 true diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters index eeeb8d2f..337b8cbb 100644 --- a/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters +++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj.filters @@ -55,9 +55,6 @@ {f8a1c208-15b8-4d85-a4cb-11d2b82f2d1e} - - {da28e961-1761-41d8-9a59-65b00dfb1302} - {43f75f84-c70d-4d44-a0ef-28a7a399abd4} @@ -91,6 +88,9 @@ {409ec37e-ff36-4c13-b18d-52d6052e0ca2} + + {3cad34c8-c436-43ae-8323-57803637c832} + @@ -171,9 +171,6 @@ Source Files\ext\http-parser - - Source Files\ext\json-parser - Source Files @@ -192,9 +189,6 @@ Source Files\node - - Source Files\node - Source Files\node @@ -252,6 +246,21 @@ Source Files\osdep + + Source Files\node + + + Source Files\node + + + Source Files\node + + + Source Files\node + + + Source Files\controller + -- cgit v1.2.3 From a7718bae398c8e910142568d7116c8adedce9d71 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 3 Nov 2016 12:25:09 -0700 Subject: link in notelemetry.obj even though Microsoft said CRT telemetry would be disabled in VS2015 Update 3. Just in case. --- windows/ZeroTierOne/ZeroTierOne.vcxproj | 1 + 1 file changed, 1 insertion(+) (limited to 'windows') diff --git a/windows/ZeroTierOne/ZeroTierOne.vcxproj b/windows/ZeroTierOne/ZeroTierOne.vcxproj index b4bf308c..e5ea25bf 100644 --- a/windows/ZeroTierOne/ZeroTierOne.vcxproj +++ b/windows/ZeroTierOne/ZeroTierOne.vcxproj @@ -277,6 +277,7 @@ true wsock32.lib;ws2_32.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) false + "notelemetry.obj" %(AdditionalOptions) -- cgit v1.2.3 From 4762311977a2ebe26c6ac140bdcfc44d7733ff9a Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Nov 2016 12:39:57 -0700 Subject: work in progress windows UI update --- windows/WinUI/APIHandler.cs | 13 ++++++++++++- windows/WinUI/NetworkInfoView.xaml | 17 +++++++++++++---- windows/WinUI/NetworkInfoView.xaml.cs | 31 +++++++++++++++++++++++++++++++ windows/WinUI/NetworkRoute.cs | 24 ++++++++++++++++++++++++ windows/WinUI/WinUI.csproj | 1 + windows/WinUI/ZeroTierNetwork.cs | 15 ++++++++++++--- 6 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 windows/WinUI/NetworkRoute.cs (limited to 'windows') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 92b83021..83a22c66 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -107,7 +107,7 @@ namespace WinUI } } - public void JoinNetwork(string nwid) + public void JoinNetwork(string nwid, bool allowManaged = false, bool allowGlobal = false, bool allowDefault = false) { var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; if (request == null) @@ -116,6 +116,17 @@ namespace WinUI } request.Method = "POST"; + request.ContentType = "applicaiton/json"; + + using (var streamWriter = new StreamWriter(((HttpWebRequest)request).GetRequestStream())) + { + string json = "{\"allowManaged\":" + (allowManaged ? "true" : "false") + "," + + "\"allowGlobal\":" + (allowGlobal ? "true" : "false") + "," + + "\"allowDefault\":" + (allowDefault ? "true" : "false") + "}"; + streamWriter.Write(json); + streamWriter.Flush(); + streamWriter.Close(); + } try { diff --git a/windows/WinUI/NetworkInfoView.xaml b/windows/WinUI/NetworkInfoView.xaml index 54ff0375..1ca488b1 100644 --- a/windows/WinUI/NetworkInfoView.xaml +++ b/windows/WinUI/NetworkInfoView.xaml @@ -26,6 +26,9 @@ + + + @@ -48,8 +51,11 @@ + + + - + @@ -59,10 +65,13 @@ - - + + + + + - + diff --git a/windows/WinUI/NetworkInfoView.xaml.cs b/windows/WinUI/NetworkInfoView.xaml.cs index ccdec288..5c96b985 100644 --- a/windows/WinUI/NetworkInfoView.xaml.cs +++ b/windows/WinUI/NetworkInfoView.xaml.cs @@ -54,6 +54,10 @@ namespace WinUI } this.managedIps.Text = iplist; + + this.allowDefault.IsChecked = network.AllowDefault; + this.allowGlobal.IsChecked = network.AllowGlobal; + this.allowManaged.IsChecked = network.AllowManaged; } public bool HasNetwork(ZeroTierNetwork network) @@ -68,5 +72,32 @@ namespace WinUI { handler.LeaveNetwork(network.NetworkId); } + + private void AllowManaged_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + handler.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } + + private void AllowGlobal_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + handler.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } + + private void AllowDefault_CheckStateChanged(object sender, RoutedEventArgs e) + { + CheckBox cb = sender as CheckBox; + handler.JoinNetwork(network.NetworkId, + allowManaged.IsChecked ?? false, + allowGlobal.IsChecked ?? false, + allowDefault.IsChecked ?? false); + } } } diff --git a/windows/WinUI/NetworkRoute.cs b/windows/WinUI/NetworkRoute.cs new file mode 100644 index 00000000..61616f44 --- /dev/null +++ b/windows/WinUI/NetworkRoute.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; + +namespace WinUI +{ + public class NetworkRoute + { + [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; } + } +} diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index c3eeaba4..9e3527c9 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -99,6 +99,7 @@ MSBuild:Compile Designer + NetworksPage.xaml diff --git a/windows/WinUI/ZeroTierNetwork.cs b/windows/WinUI/ZeroTierNetwork.cs index cce65441..6a6f8498 100644 --- a/windows/WinUI/ZeroTierNetwork.cs +++ b/windows/WinUI/ZeroTierNetwork.cs @@ -42,13 +42,22 @@ namespace WinUI [JsonProperty("netconfRevision")] public int NetconfRevision { get; set; } - [JsonProperty("multicastSubscriptions")] - public string[] MulticastSubscriptions { get; set; } - [JsonProperty("assignedAddresses")] public string[] AssignedAddresses { get; set; } + [JsonProperty("routes")] + public NetworkRoute[] Routes { get; set; } + [JsonProperty("portDeviceName")] public string DeviceName { get; set; } + + [JsonProperty("allowManaged")] + public bool AllowManaged { get; set; } + + [JsonProperty("allowGlobal")] + public bool AllowGlobal { get; set; } + + [JsonProperty("allowDefault")] + public bool AllowDefault { get; set; } } } -- cgit v1.2.3 From efcc24a76b493a3045eb24805fc2e1dd2109823c Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Nov 2016 14:49:15 -0700 Subject: increase window width so IPv6 addreses don't wrap --- windows/WinUI/MainWindow.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'windows') diff --git a/windows/WinUI/MainWindow.xaml b/windows/WinUI/MainWindow.xaml index d71a90df..9d4a9fc1 100644 --- a/windows/WinUI/MainWindow.xaml +++ b/windows/WinUI/MainWindow.xaml @@ -5,7 +5,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WinUI" mc:Ignorable="d" x:Class="WinUI.MainWindow" - Title="ZeroTier One" Height="500" Width="425" Icon="ZeroTierIcon.ico"> + Title="ZeroTier One" Height="500" Width="500" Icon="ZeroTierIcon.ico"> -- cgit v1.2.3 From 1ab9c431350b1e8cf22f27fe5814f1d4608b24a7 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Fri, 4 Nov 2016 14:50:07 -0700 Subject: wire up allowDefault, allowManaged, allowGlobal, allowDefault options --- windows/WinUI/APIHandler.cs | 2 +- windows/WinUI/NetworkInfoView.xaml | 6 +++--- windows/WinUI/NetworkInfoView.xaml.cs | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'windows') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 83a22c66..2a8dea13 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -107,7 +107,7 @@ namespace WinUI } } - public void JoinNetwork(string nwid, bool allowManaged = false, bool allowGlobal = false, bool allowDefault = false) + public void JoinNetwork(string nwid, bool allowManaged = true, bool allowGlobal = false, bool allowDefault = false) { var request = WebRequest.Create(url + "/network/" + nwid + "?auth=" + authtoken) as HttpWebRequest; if (request == null) diff --git a/windows/WinUI/NetworkInfoView.xaml b/windows/WinUI/NetworkInfoView.xaml index 1ca488b1..aea85490 100644 --- a/windows/WinUI/NetworkInfoView.xaml +++ b/windows/WinUI/NetworkInfoView.xaml @@ -65,9 +65,9 @@ - - - + + + diff --git a/windows/WinUI/NetworkInfoView.xaml.cs b/windows/WinUI/NetworkInfoView.xaml.cs index 5c96b985..3ecc31b8 100644 --- a/windows/WinUI/NetworkInfoView.xaml.cs +++ b/windows/WinUI/NetworkInfoView.xaml.cs @@ -58,6 +58,14 @@ namespace WinUI this.allowDefault.IsChecked = network.AllowDefault; this.allowGlobal.IsChecked = network.AllowGlobal; this.allowManaged.IsChecked = network.AllowManaged; + + allowDefault.Checked += AllowDefault_CheckStateChanged; + allowDefault.Unchecked += AllowDefault_CheckStateChanged; + allowGlobal.Checked += AllowGlobal_CheckStateChanged; + allowGlobal.Unchecked += AllowGlobal_CheckStateChanged; + allowManaged.Checked += AllowManaged_CheckStateChanged; + allowManaged.Unchecked += AllowManaged_CheckStateChanged; + } public bool HasNetwork(ZeroTierNetwork network) -- cgit v1.2.3 From c802811ad298d20315e358b0fc7964a16e591aa6 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Mon, 7 Nov 2016 14:08:26 -0800 Subject: Added a file copy util for Windows UI Copies the authtoken.secret file into a private local folder for the user so that the UI doesnt have to be run with Admin privileges. --- .gitignore | 2 + windows/WinUI/MainWindow.xaml.cs | 74 +++++++++++++----- windows/WinUI/WinUI.csproj | 7 +- windows/ZeroTierOne.sln | 115 ++++++++++++++++++++++++++++ windows/copyutil/App.config | 6 ++ windows/copyutil/Program.cs | 40 ++++++++++ windows/copyutil/Properties/AssemblyInfo.cs | 36 +++++++++ windows/copyutil/copyutil.csproj | 60 +++++++++++++++ 8 files changed, 319 insertions(+), 21 deletions(-) create mode 100644 windows/copyutil/App.config create mode 100644 windows/copyutil/Program.cs create mode 100644 windows/copyutil/Properties/AssemblyInfo.cs create mode 100644 windows/copyutil/copyutil.csproj (limited to 'windows') diff --git a/.gitignore b/.gitignore index d3ef1581..d368697c 100755 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,8 @@ Thumbs.db /windows/*.db /windows/*.opendb enc_temp_folder +/windows/copyutil/bin +/windows/copyutil/obj # *nix/Mac build droppings /build-* diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index 47f00bfe..25534b46 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -57,40 +58,77 @@ namespace WinUI } } - private bool InitAPIHandler() + + private String readAuthToken(String path) { - String ztDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; String authToken = ""; + + if (File.Exists(path)) + { + try + { + byte[] tmp = File.ReadAllBytes(path); + authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); + } + catch + { + MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); + } + } + + return authToken; + } + + private Int32 readPort(String path) + { Int32 port = 9993; + try { - byte[] tmp = File.ReadAllBytes(ztDir + "\\authtoken.secret"); - authToken = System.Text.Encoding.ASCII.GetString(tmp).Trim(); + byte[] tmp = File.ReadAllBytes(path); + port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); + if ((port <= 0) || (port > 65535)) + port = 9993; } catch { - MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One"); - this.Close(); - return false; } + return port; + } + + private bool InitAPIHandler() + { + String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; + String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; + + String authToken = ""; + Int32 port = 9993; + + if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) + { + // launch external process to copy file into place + String curPath = System.Reflection.Assembly.GetEntryAssembly().Location; + int index = curPath.LastIndexOf("\\"); + curPath = curPath.Substring(0, index); + ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", globalZtDir + " " + localZtDir); + startInfo.Verb = "runas"; + + + var process = Process.Start(startInfo); + process.WaitForExit(); + } + + authToken = readAuthToken(localZtDir + "\\authtoken.secret"); + if ((authToken == null) || (authToken.Length <= 0)) { - MessageBox.Show("Unable to read ZeroTier One authtoken.secret from:\r\n" + ztDir, "ZeroTier One"); + MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); this.Close(); return false; } - try - { - byte[] tmp = File.ReadAllBytes(ztDir + "\\zerotier-one.port"); - port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); - if ((port <= 0) || (port > 65535)) - port = 9993; - } - catch - { - } + port = readPort(localZtDir + "\\zerotier-one.port"); handler = new APIHandler(port, authToken); return true; } diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 9e3527c9..76b4862a 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -63,9 +63,7 @@ false - - app.manifest - + @@ -218,6 +216,9 @@ + + copy $(SolutionDir)\copyutil\bin\$(ConfigurationName)\copyutil.exe $(ProjectDir)\$(OutDir)\copyutil.exe + + \ No newline at end of file -- cgit v1.2.3 From 6d8c8f9fd149ca438404819d9062d3dcda0e7c51 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 11:23:15 -0800 Subject: update JSON library to latest --- windows/WinUI/WinUI.csproj | 4 ++-- windows/WinUI/packages.config | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'windows') diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 76b4862a..181983c0 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -66,8 +66,8 @@ - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True diff --git a/windows/WinUI/packages.config b/windows/WinUI/packages.config index 505e5883..e1fae9c6 100644 --- a/windows/WinUI/packages.config +++ b/windows/WinUI/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file -- cgit v1.2.3 From 54206fd44d5bda4b9fd0f5dacbaefdbe81e15b18 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 11:24:12 -0800 Subject: add NotifyIcon NuGet package for tray icon support --- windows/WinUI/packages.config | 1 + 1 file changed, 1 insertion(+) (limited to 'windows') diff --git a/windows/WinUI/packages.config b/windows/WinUI/packages.config index e1fae9c6..e6803f84 100644 --- a/windows/WinUI/packages.config +++ b/windows/WinUI/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file -- cgit v1.2.3 From 6b0543ba27511d7bd7b40cfca2f24608a6b8d9ee Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 14:54:55 -0800 Subject: starts up to a toolbar icon with context menu. still much more to do --- windows/WinUI/App.xaml | 2 +- windows/WinUI/App.xaml.cs | 8 ++ windows/WinUI/MainWindow.xaml.cs | 97 +++---------------- windows/WinUI/Properties/Resources.Designer.cs | 52 +++++----- windows/WinUI/Properties/Resources.resx | 17 +++- windows/WinUI/Resources/ZeroTierIcon.ico | Bin 0 -> 45451 bytes windows/WinUI/Simple Styles.xaml | 9 +- windows/WinUI/ToolbarItem.xaml | 32 +++++++ windows/WinUI/ToolbarItem.xaml.cs | 127 +++++++++++++++++++++++++ windows/WinUI/WinUI.csproj | 14 +++ 10 files changed, 244 insertions(+), 114 deletions(-) create mode 100644 windows/WinUI/Resources/ZeroTierIcon.ico create mode 100644 windows/WinUI/ToolbarItem.xaml create mode 100644 windows/WinUI/ToolbarItem.xaml.cs (limited to 'windows') diff --git a/windows/WinUI/App.xaml b/windows/WinUI/App.xaml index 08b9b792..12ed85f9 100644 --- a/windows/WinUI/App.xaml +++ b/windows/WinUI/App.xaml @@ -1,7 +1,7 @@  + StartupUri="ToolbarItem.xaml"> diff --git a/windows/WinUI/App.xaml.cs b/windows/WinUI/App.xaml.cs index a97edde7..53ef2f67 100644 --- a/windows/WinUI/App.xaml.cs +++ b/windows/WinUI/App.xaml.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Threading.Tasks; using System.Windows; +using Hardcodet.Wpf.TaskbarNotification; namespace WinUI { @@ -13,5 +14,12 @@ namespace WinUI /// public partial class App : Application { + private TaskbarIcon tb; + + private void InitApplication() + { + tb = (TaskbarIcon)FindResource("NotifyIcon"); + tb.Visibility = Visibility.Visible; + } } } diff --git a/windows/WinUI/MainWindow.xaml.cs b/windows/WinUI/MainWindow.xaml.cs index 25534b46..a57ee4b9 100644 --- a/windows/WinUI/MainWindow.xaml.cs +++ b/windows/WinUI/MainWindow.xaml.cs @@ -36,102 +36,35 @@ namespace WinUI public MainWindow() { InitializeComponent(); - - if (InitAPIHandler()) - { - networksPage.SetAPIHandler(handler); - - updateStatus(); - if (!connected) - { - MessageBox.Show("Unable to connect to ZeroTier Service."); - } - - updateNetworks(); - //updatePeers(); - - DataObject.AddPastingHandler(joinNetworkID, OnPaste); - - timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); - timer.Interval = 2000; - timer.Enabled = true; - } } - private String readAuthToken(String path) - { - String authToken = ""; - - if (File.Exists(path)) - { - try - { - byte[] tmp = File.ReadAllBytes(path); - authToken = System.Text.Encoding.UTF8.GetString(tmp).Trim(); - } - catch - { - MessageBox.Show("Unable to read ZeroTier One Auth Token from:\r\n" + path, "ZeroTier One"); - } - } - - return authToken; - } - - private Int32 readPort(String path) + public void SetAPIHandler(APIHandler handler) { - Int32 port = 9993; + timer.Stop(); + timer = new Timer(); - try - { - byte[] tmp = File.ReadAllBytes(path); - port = Int32.Parse(System.Text.Encoding.ASCII.GetString(tmp).Trim()); - if ((port <= 0) || (port > 65535)) - port = 9993; - } - catch - { - } + this.handler = handler; - return port; - } + networksPage.SetAPIHandler(handler); - private bool InitAPIHandler() - { - String localZtDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\ZeroTier\\One"; - String globalZtDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\ZeroTier\\One"; - - String authToken = ""; - Int32 port = 9993; + updateStatus(); - if (!File.Exists(localZtDir + "\\authtoken.secret") || !File.Exists(localZtDir + "\\zerotier-one.port")) + if (!connected) { - // launch external process to copy file into place - String curPath = System.Reflection.Assembly.GetEntryAssembly().Location; - int index = curPath.LastIndexOf("\\"); - curPath = curPath.Substring(0, index); - ProcessStartInfo startInfo = new ProcessStartInfo(curPath + "\\copyutil.exe", globalZtDir + " " + localZtDir); - startInfo.Verb = "runas"; - - - var process = Process.Start(startInfo); - process.WaitForExit(); + MessageBox.Show("Unable to connect to ZerOTier Service"); + return; } - authToken = readAuthToken(localZtDir + "\\authtoken.secret"); + updateNetworks(); - if ((authToken == null) || (authToken.Length <= 0)) - { - MessageBox.Show("Unable to read ZeroTier One authtoken", "ZeroTier One"); - this.Close(); - return false; - } + DataObject.AddPastingHandler(joinNetworkID, OnPaste); - port = readPort(localZtDir + "\\zerotier-one.port"); - handler = new APIHandler(port, authToken); - return true; + timer.Elapsed += new ElapsedEventHandler(OnUpdateTimer); + timer.Interval = 2000; + timer.Enabled = true; } + private void updateStatus() { diff --git a/windows/WinUI/Properties/Resources.Designer.cs b/windows/WinUI/Properties/Resources.Designer.cs index 57a56f7d..3e5c78ae 100644 --- a/windows/WinUI/Properties/Resources.Designer.cs +++ b/windows/WinUI/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace WinUI.Properties -{ - - +namespace WinUI.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -22,50 +22,52 @@ namespace WinUI.Properties [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 - { - + 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() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + 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; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } + + /// + /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). + /// + internal static System.Drawing.Icon ZeroTierIcon { + get { + object obj = ResourceManager.GetObject("ZeroTierIcon", resourceCulture); + return ((System.Drawing.Icon)(obj)); + } + } } } diff --git a/windows/WinUI/Properties/Resources.resx b/windows/WinUI/Properties/Resources.resx index af7dbebb..0872fceb 100644 --- a/windows/WinUI/Properties/Resources.resx +++ b/windows/WinUI/Properties/Resources.resx @@ -46,7 +46,7 @@ mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with - : System.Serialization.Formatters.Binary.BinaryFormatter + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 @@ -60,6 +60,7 @@ : and then encoded with base64 encoding. --> + @@ -68,9 +69,10 @@ - + + @@ -85,9 +87,10 @@ - + + @@ -109,9 +112,13 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ..\ZeroTierIcon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/windows/WinUI/Resources/ZeroTierIcon.ico b/windows/WinUI/Resources/ZeroTierIcon.ico new file mode 100644 index 00000000..5d06b9f2 Binary files /dev/null and b/windows/WinUI/Resources/ZeroTierIcon.ico differ diff --git a/windows/WinUI/Simple Styles.xaml b/windows/WinUI/Simple Styles.xaml index f2ddedf9..a03348b3 100644 --- a/windows/WinUI/Simple Styles.xaml +++ b/windows/WinUI/Simple Styles.xaml @@ -1,4 +1,9 @@ - + @@ -1118,4 +1123,6 @@ + + diff --git a/windows/WinUI/ToolbarItem.xaml b/windows/WinUI/ToolbarItem.xaml new file mode 100644 index 00000000..4a153c9a --- /dev/null +++ b/windows/WinUI/ToolbarItem.xaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs new file mode 100644 index 00000000..e34863dd --- /dev/null +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -0,0 +1,127 @@ +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; +using System.Text.RegularExpressions; +using System.Timers; +using System.Windows.Threading; +using System.IO; +using System.Diagnostics; + +namespace WinUI +{ + /// + /// Interaction logic for ToolbarItem.xaml + /// + public partial class ToolbarItem : Window + { + APIHandler handler; + + public ToolbarItem() + { + InitializeComponent(); + + if (InitAPIHandler()) + { + + } + else + { + MessageBox.Show("ZeroTier API Initialization Failed"); + } + } + + 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 ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("TrayContextMenuOpen"); + } + + private void ToolbarItem_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) + { + Console.WriteLine("PreviewTrayContextMenuOpen"); + } + } +} diff --git a/windows/WinUI/WinUI.csproj b/windows/WinUI/WinUI.csproj index 181983c0..00c07f6c 100644 --- a/windows/WinUI/WinUI.csproj +++ b/windows/WinUI/WinUI.csproj @@ -66,6 +66,10 @@ + + ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll + True + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -104,6 +108,9 @@ PeersPage.xaml + + ToolbarItem.xaml + @@ -141,6 +148,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + @@ -214,6 +225,9 @@ + + + -- cgit v1.2.3 From e1f9f7b6dc80a5ad0db3fedc8f5b92d47cbdb1fe Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 15:50:08 -0800 Subject: turn APIHandler into a singleton --- windows/WinUI/APIHandler.cs | 91 ++++++++++++++++++++++++++++++++++++++- windows/WinUI/ToolbarItem.xaml.cs | 85 +----------------------------------- 2 files changed, 91 insertions(+), 85 deletions(-) (limited to 'windows') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index 2a8dea13..f2fb1d21 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -7,6 +7,7 @@ using System.Net; using System.IO; using System.Windows; using Newtonsoft.Json; +using System.Diagnostics; namespace WinUI { @@ -18,7 +19,95 @@ namespace WinUI private string url = null; - public APIHandler() + private static APIHandler instance; + + public static APIHandler Instance + { + get + { + if (instance == null) + { + + } + + return instance; + } + } + + private static bool initHandler() + { + 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"); + 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"; } diff --git a/windows/WinUI/ToolbarItem.xaml.cs b/windows/WinUI/ToolbarItem.xaml.cs index e34863dd..9ff7e860 100644 --- a/windows/WinUI/ToolbarItem.xaml.cs +++ b/windows/WinUI/ToolbarItem.xaml.cs @@ -24,94 +24,11 @@ namespace WinUI /// public partial class ToolbarItem : Window { - APIHandler handler; + APIHandler handler = APIHandler.Instance; public ToolbarItem() { InitializeComponent(); - - if (InitAPIHandler()) - { - - } - else - { - MessageBox.Show("ZeroTier API Initialization Failed"); - } - } - - 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 ToolbarItem_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e) -- cgit v1.2.3 From 7cf3d2caa19da076ebd3539c8786ce62a53d35f9 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Tue, 8 Nov 2016 16:31:07 -0800 Subject: Network list window opens with click on the menu item --- windows/WinUI/APIHandler.cs | 14 ++- windows/WinUI/MainWindow.xaml | 132 --------------------------- windows/WinUI/MainWindow.xaml.cs | 166 ---------------------------------- windows/WinUI/NetworkInfoView.xaml.cs | 12 +-- windows/WinUI/NetworkList.xaml | 132 +++++++++++++++++++++++++++ windows/WinUI/NetworkList.xaml.cs | 153 +++++++++++++++++++++++++++++++ windows/WinUI/NetworksPage.xaml.cs | 8 -- windows/WinUI/ToolbarItem.xaml | 6 +- windows/WinUI/ToolbarItem.xaml.cs | 28 +++++- windows/WinUI/WinUI.csproj | 6 +- 10 files changed, 336 insertions(+), 321 deletions(-) delete mode 100644 windows/WinUI/MainWindow.xaml delete mode 100644 windows/WinUI/MainWindow.xaml.cs create mode 100644 windows/WinUI/NetworkList.xaml create mode 100644 windows/WinUI/NetworkList.xaml.cs (limited to 'windows') diff --git a/windows/WinUI/APIHandler.cs b/windows/WinUI/APIHandler.cs index f2fb1d21..9cddd916 100644 --- a/windows/WinUI/APIHandler.cs +++ b/windows/WinUI/APIHandler.cs @@ -19,7 +19,8 @@ namespace WinUI private string url = null; - private static APIHandler instance; + private static volatile APIHandler instance; + private static object syncRoot = new Object(); public static APIHandler Instance { @@ -27,7 +28,16 @@ namespace WinUI { if (instance == null) { - + lock (syncRoot) + { + if (instance == null) + { + if (!initHandler()) + { + return null; + } + } + } } return instance; diff --git a/windows/WinUI/MainWindow.xaml b/windows/WinUI/MainWindow.xaml deleted file mode 100644 index 9d4a9fc1..00000000 --- a/windows/WinUI/MainWindow.xaml +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -