Browse Source

Merge branch 'net-core-build' into net-core-cipher-api

pull/2865/head
Student Main 5 years ago
parent
commit
7ca36d5498
2 changed files with 37 additions and 30 deletions
  1. +22
    -23
      shadowsocks-csharp/Util/Util.cs
  2. +15
    -7
      shadowsocks-csharp/View/MenuViewController.cs

+ 22
- 23
shadowsocks-csharp/Util/Util.cs View File

@@ -268,34 +268,33 @@ namespace Shadowsocks.Util
private static extern bool SetProcessWorkingSetSize(IntPtr process, private static extern bool SetProcessWorkingSetSize(IntPtr process,
UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize); UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize);
// See: https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
public static bool IsSupportedRuntimeVersion()
public static void OpenInBrowser(string url)
{ {
/*
* +-----------------------------------------------------------------+----------------------------+
* | Version | Value of the Release DWORD |
* +-----------------------------------------------------------------+----------------------------+
* | .NET Framework 4.6.2 installed on Windows 10 Anniversary Update | 394802 |
* | .NET Framework 4.6.2 installed on all other Windows OS versions | 394806 |
* +-----------------------------------------------------------------+----------------------------+
*/
const int minSupportedRelease = 394802;
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
using (var ndpKey = OpenRegKey(subkey, false, RegistryHive.LocalMachine))
try
{ {
if (ndpKey?.GetValue("Release") != null)
Process.Start(url);
}
catch
{
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
var releaseKey = (int)ndpKey.GetValue("Release");
if (releaseKey >= minSupportedRelease)
{
return true;
}
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
} }
} }
return false;
} }
} }
} }

+ 15
- 7
shadowsocks-csharp/View/MenuViewController.cs View File

@@ -38,7 +38,7 @@ namespace Shadowsocks.View
private ToolStripMenuItem disableItem; private ToolStripMenuItem disableItem;
private ToolStripMenuItem AutoStartupItem; private ToolStripMenuItem AutoStartupItem;
private ToolStripMenuItem ShareOverLANItem; private ToolStripMenuItem ShareOverLANItem;
private ToolStripSeparator SeperatorItem;
private ToolStripSeparator SeperatorItem;
private ToolStripMenuItem ConfigItem; private ToolStripMenuItem ConfigItem;
private ToolStripMenuItem ServersItem; private ToolStripMenuItem ServersItem;
private ToolStripMenuItem globalModeItem; private ToolStripMenuItem globalModeItem;
@@ -277,12 +277,12 @@ namespace Shadowsocks.View
private ToolStripMenuItem CreateToolStripMenuItem(string text, EventHandler click) private ToolStripMenuItem CreateToolStripMenuItem(string text, EventHandler click)
{ {
return new ToolStripMenuItem(I18N.GetString(text),null, click);
return new ToolStripMenuItem(I18N.GetString(text), null, click);
} }
private ToolStripMenuItem CreateMenuGroup(string text, ToolStripItem[] items) private ToolStripMenuItem CreateMenuGroup(string text, ToolStripItem[] items)
{ {
return new ToolStripMenuItem(I18N.GetString(text), null,items);
return new ToolStripMenuItem(I18N.GetString(text), null, items);
} }
private void LoadMenu() private void LoadMenu()
@@ -461,7 +461,7 @@ namespace Shadowsocks.View
int strategyCount = 0; int strategyCount = 0;
foreach (var strategy in controller.GetStrategies()) foreach (var strategy in controller.GetStrategies())
{ {
if (!items.OfType<ToolStripItem>().Any(ts=>ts.Text==strategy.Name))
if (!items.OfType<ToolStripItem>().Any(ts => ts.Text == strategy.Name))
{ {
ToolStripMenuItem item = new ToolStripMenuItem(strategy.Name); ToolStripMenuItem item = new ToolStripMenuItem(strategy.Name);
item.Tag = strategy.ID; item.Tag = strategy.ID;
@@ -496,9 +496,17 @@ namespace Shadowsocks.View
foreach (var item in items) foreach (var item in items)
{ {
var menuItem = item as ToolStripMenuItem; var menuItem = item as ToolStripMenuItem;
if (menuItem != null && menuItem.Tag != null && (menuItem.Tag.ToString() == configuration.index.ToString() || menuItem.Tag.ToString() == configuration.strategy))
if (menuItem == null || menuItem.Tag == null) continue;
if (
menuItem.Tag.ToString() == configuration.index.ToString()
|| menuItem.Tag.ToString() == configuration.strategy
)
{ {
menuItem.Checked = true; menuItem.Checked = true;
} else
{
menuItem.Checked = false;
} }
} }
} }
@@ -624,7 +632,7 @@ namespace Shadowsocks.View
private void AboutItem_Click(object sender, EventArgs e) private void AboutItem_Click(object sender, EventArgs e)
{ {
Process.Start("https://github.com/shadowsocks/shadowsocks-windows");
Utils.OpenInBrowser("https://github.com/shadowsocks/shadowsocks-windows");
} }
private void notifyIcon1_Click(object sender, MouseEventArgs e) private void notifyIcon1_Click(object sender, MouseEventArgs e)
@@ -846,7 +854,7 @@ namespace Shadowsocks.View
void openURLFromQRCode(object sender, FormClosedEventArgs e) void openURLFromQRCode(object sender, FormClosedEventArgs e)
{ {
Process.Start(_urlToOpen);
Utils.OpenInBrowser(_urlToOpen);
} }
private void AutoStartupItem_Click(object sender, EventArgs e) private void AutoStartupItem_Click(object sender, EventArgs e)


Loading…
Cancel
Save