Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf01546b0b | ||
|
|
ec80bea024 | ||
|
|
b88006f02d |
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.14
|
1.0.17
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace MonsterMonitor.Models
|
|||||||
public int LocalPort { get; set; } = 7829;
|
public int LocalPort { get; set; } = 7829;
|
||||||
public int MaxPingFailures { get; set; } = 3;
|
public int MaxPingFailures { get; set; } = 3;
|
||||||
public int ReconnectTimeoutSec { get; set; } = 45;
|
public int ReconnectTimeoutSec { get; set; } = 45;
|
||||||
|
public string Proxy { get; set; } = string.Empty;
|
||||||
public string SsProcessPath { get; set; } = Path.Combine("App_Data", "ss", "ss.exe");
|
public string SsProcessPath { get; set; } = Path.Combine("App_Data", "ss", "ss.exe");
|
||||||
public string SsArguments { get; set; } = string.Empty;
|
public string SsArguments { get; set; } = string.Empty;
|
||||||
|
|
||||||
@@ -163,6 +164,7 @@ namespace MonsterMonitor.Models
|
|||||||
result.LocalPort = GetInt(map, nameof(LocalPort), result.LocalPort);
|
result.LocalPort = GetInt(map, nameof(LocalPort), result.LocalPort);
|
||||||
result.MaxPingFailures = GetInt(map, nameof(MaxPingFailures), result.MaxPingFailures);
|
result.MaxPingFailures = GetInt(map, nameof(MaxPingFailures), result.MaxPingFailures);
|
||||||
result.ReconnectTimeoutSec = GetInt(map, nameof(ReconnectTimeoutSec), result.ReconnectTimeoutSec);
|
result.ReconnectTimeoutSec = GetInt(map, nameof(ReconnectTimeoutSec), result.ReconnectTimeoutSec);
|
||||||
|
result.Proxy = Get(map, nameof(Proxy), result.Proxy);
|
||||||
result.SsProcessPath = Get(map, nameof(SsProcessPath), result.SsProcessPath);
|
result.SsProcessPath = Get(map, nameof(SsProcessPath), result.SsProcessPath);
|
||||||
result.SsArguments = Get(map, nameof(SsArguments), result.SsArguments);
|
result.SsArguments = Get(map, nameof(SsArguments), result.SsArguments);
|
||||||
|
|
||||||
@@ -191,6 +193,7 @@ namespace MonsterMonitor.Models
|
|||||||
$"{nameof(LocalPort)}={LocalPort}",
|
$"{nameof(LocalPort)}={LocalPort}",
|
||||||
$"{nameof(MaxPingFailures)}={MaxPingFailures}",
|
$"{nameof(MaxPingFailures)}={MaxPingFailures}",
|
||||||
$"{nameof(ReconnectTimeoutSec)}={ReconnectTimeoutSec}",
|
$"{nameof(ReconnectTimeoutSec)}={ReconnectTimeoutSec}",
|
||||||
|
$"{nameof(Proxy)}={Proxy}",
|
||||||
$"{nameof(SsProcessPath)}={SsProcessPath}",
|
$"{nameof(SsProcessPath)}={SsProcessPath}",
|
||||||
$"{nameof(SsArguments)}={SsArguments}"
|
$"{nameof(SsArguments)}={SsArguments}"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<RootNamespace>MonsterMonitor</RootNamespace>
|
<RootNamespace>MonsterMonitor</RootNamespace>
|
||||||
<AssemblyName>MonsterMonitor</AssemblyName>
|
<AssemblyName>devenv</AssemblyName>
|
||||||
<AssemblyVersion>1.0.14</AssemblyVersion>
|
<AssemblyVersion>1.0.17</AssemblyVersion>
|
||||||
<Version>1.0.14</Version>
|
<Version>1.0.17</Version>
|
||||||
<FileVersion>1.0.14</FileVersion>
|
<FileVersion>1.0.17</FileVersion>
|
||||||
<InformationalVersion>1.0.14</InformationalVersion>
|
<InformationalVersion>1.0.17</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||||
|
|||||||
@@ -5,11 +5,13 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Runtime.Serialization.Json;
|
using System.Runtime.Serialization.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using MonsterMonitor.Models;
|
||||||
|
|
||||||
namespace MonsterMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
@@ -20,10 +22,12 @@ namespace MonsterMonitor.Services
|
|||||||
private const string GithubToken = "";
|
private const string GithubToken = "";
|
||||||
|
|
||||||
private readonly LogService _log;
|
private readonly LogService _log;
|
||||||
|
private readonly AppSettings _settings;
|
||||||
|
|
||||||
public GitHubUpdateService(LogService log)
|
public GitHubUpdateService(LogService log, AppSettings settings)
|
||||||
{
|
{
|
||||||
_log = log;
|
_log = log;
|
||||||
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CheckAndPrepareUpdateAsync()
|
public async Task CheckAndPrepareUpdateAsync()
|
||||||
@@ -63,8 +67,8 @@ namespace MonsterMonitor.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tempRoot = Path.Combine(Path.GetTempPath(), "MonsterMonitorUpdate");
|
var appDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
var packageDir = Path.Combine(tempRoot, latestVersion.ToString());
|
var packageDir = Path.Combine(appDir, "update", latestVersion.ToString());
|
||||||
var packageZip = Path.Combine(packageDir, "update.zip");
|
var packageZip = Path.Combine(packageDir, "update.zip");
|
||||||
var extractDir = Path.Combine(packageDir, "extracted");
|
var extractDir = Path.Combine(packageDir, "extracted");
|
||||||
Directory.CreateDirectory(packageDir);
|
Directory.CreateDirectory(packageDir);
|
||||||
@@ -80,7 +84,6 @@ namespace MonsterMonitor.Services
|
|||||||
ZipFile.ExtractToDirectory(packageZip, extractDir);
|
ZipFile.ExtractToDirectory(packageZip, extractDir);
|
||||||
_log.Info("Архив обновления распакован.");
|
_log.Info("Архив обновления распакован.");
|
||||||
|
|
||||||
var appDir = AppDomain.CurrentDomain.BaseDirectory;
|
|
||||||
var exePath = Application.ExecutablePath;
|
var exePath = Application.ExecutablePath;
|
||||||
var updaterBat = Path.Combine(packageDir, "apply_update.bat");
|
var updaterBat = Path.Combine(packageDir, "apply_update.bat");
|
||||||
File.WriteAllText(updaterBat, BuildUpdaterScript(appDir, extractDir, exePath), Encoding.ASCII);
|
File.WriteAllText(updaterBat, BuildUpdaterScript(appDir, extractDir, exePath), Encoding.ASCII);
|
||||||
@@ -114,15 +117,51 @@ namespace MonsterMonitor.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Version GetCurrentVersion()
|
private Version GetCurrentVersion()
|
||||||
{
|
{
|
||||||
Version version;
|
var fileVersion = TryParseVersion(FileVersionInfo.GetVersionInfo(Application.ExecutablePath).ProductVersion);
|
||||||
if (!Version.TryParse(Application.ProductVersion, out version))
|
if (fileVersion != null)
|
||||||
{
|
{
|
||||||
version = new Version(1, 0, 0, 0);
|
return fileVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||||
|
if (assemblyVersion != null)
|
||||||
|
{
|
||||||
|
return assemblyVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
var productVersion = TryParseVersion(Application.ProductVersion);
|
||||||
|
if (productVersion != null)
|
||||||
|
{
|
||||||
|
return productVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Warn("Не удалось определить текущую версию приложения, использую 1.0.0.");
|
||||||
|
return new Version(1, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Version TryParseVersion(string raw)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(raw))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = raw.Trim();
|
||||||
|
var plusIndex = value.IndexOf('+');
|
||||||
|
if (plusIndex > 0)
|
||||||
|
{
|
||||||
|
value = value.Substring(0, plusIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.StartsWith("v", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
value = value.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Version version;
|
||||||
|
return Version.TryParse(value, out version) ? version : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Version ParseVersion(string rawVersion)
|
private static Version ParseVersion(string rawVersion)
|
||||||
@@ -159,7 +198,7 @@ namespace MonsterMonitor.Services
|
|||||||
{
|
{
|
||||||
var request = CreateGithubRequest(url, "application/vnd.github+json");
|
var request = CreateGithubRequest(url, "application/vnd.github+json");
|
||||||
using (var response = (HttpWebResponse)await request.GetResponseAsync())
|
using (var response = (HttpWebResponse)await request.GetResponseAsync())
|
||||||
using (var stream = response.GetResponseStream())
|
using (var stream = response.GetResponseStream())
|
||||||
{
|
{
|
||||||
if (stream == null)
|
if (stream == null)
|
||||||
{
|
{
|
||||||
@@ -266,7 +305,7 @@ namespace MonsterMonitor.Services
|
|||||||
return asset.DownloadUrl ?? string.Empty;
|
return asset.DownloadUrl ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpWebRequest CreateGithubRequest(string url, string accept)
|
private HttpWebRequest CreateGithubRequest(string url, string accept)
|
||||||
{
|
{
|
||||||
var request = (HttpWebRequest)WebRequest.Create(url);
|
var request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
request.Method = "GET";
|
request.Method = "GET";
|
||||||
@@ -277,10 +316,26 @@ namespace MonsterMonitor.Services
|
|||||||
{
|
{
|
||||||
request.Headers.Add("Authorization", "Bearer " + GithubToken);
|
request.Headers.Add("Authorization", "Bearer " + GithubToken);
|
||||||
}
|
}
|
||||||
|
if (!string.IsNullOrWhiteSpace(_settings.Proxy))
|
||||||
|
{
|
||||||
|
request.Proxy = GetProxy(_settings.Proxy);
|
||||||
|
}
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private WebProxy GetProxy(string proxyUri)
|
||||||
|
{
|
||||||
|
var proxy = new WebProxy(new Uri(proxyUri), false);
|
||||||
|
var cc = new CredentialCache();
|
||||||
|
cc.Add(
|
||||||
|
new Uri(proxyUri),
|
||||||
|
"Negotiate", // if we don't set it to "Kerberos" we get error 407 with ---> the function requested is not supported.
|
||||||
|
CredentialCache.DefaultNetworkCredentials);
|
||||||
|
proxy.Credentials = cc;
|
||||||
|
return proxy;
|
||||||
|
}
|
||||||
|
|
||||||
private static string BuildUpdaterScript(string appDir, string extractDir, string exePath)
|
private static string BuildUpdaterScript(string appDir, string extractDir, string exePath)
|
||||||
{
|
{
|
||||||
return "@echo off" + Environment.NewLine +
|
return "@echo off" + Environment.NewLine +
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace MonsterMonitor.UI
|
|||||||
|
|
||||||
_settings = AppSettings.Load();
|
_settings = AppSettings.Load();
|
||||||
_controller = new AppController(_log, _power);
|
_controller = new AppController(_log, _power);
|
||||||
_updateService = new GitHubUpdateService(_log);
|
_updateService = new GitHubUpdateService(_log, _settings);
|
||||||
RestartServices();
|
RestartServices();
|
||||||
ConfigureUpdateTimer();
|
ConfigureUpdateTimer();
|
||||||
_ = RunUpdateCheckAsync(true);
|
_ = RunUpdateCheckAsync(true);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ namespace MonsterMonitor.UI
|
|||||||
private readonly NumericUpDown _numLocalPort = new NumericUpDown();
|
private readonly NumericUpDown _numLocalPort = new NumericUpDown();
|
||||||
private readonly NumericUpDown _numMaxFailures = new NumericUpDown();
|
private readonly NumericUpDown _numMaxFailures = new NumericUpDown();
|
||||||
private readonly NumericUpDown _numReconnectTimeout = new NumericUpDown();
|
private readonly NumericUpDown _numReconnectTimeout = new NumericUpDown();
|
||||||
|
private readonly TextBox _txtProxy = new TextBox();
|
||||||
private readonly TextBox _txtSsPath = new TextBox();
|
private readonly TextBox _txtSsPath = new TextBox();
|
||||||
private readonly TextBox _txtSsArgs = new TextBox();
|
private readonly TextBox _txtSsArgs = new TextBox();
|
||||||
private readonly TextBox _txtSystemPassword = new TextBox();
|
private readonly TextBox _txtSystemPassword = new TextBox();
|
||||||
@@ -30,7 +31,7 @@ namespace MonsterMonitor.UI
|
|||||||
_settings = settings;
|
_settings = settings;
|
||||||
Text = "Настройки";
|
Text = "Настройки";
|
||||||
Width = 560;
|
Width = 560;
|
||||||
Height = 520;
|
Height = 560;
|
||||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
MaximizeBox = false;
|
MaximizeBox = false;
|
||||||
MinimizeBox = false;
|
MinimizeBox = false;
|
||||||
@@ -47,7 +48,7 @@ namespace MonsterMonitor.UI
|
|||||||
Dock = DockStyle.Fill,
|
Dock = DockStyle.Fill,
|
||||||
Padding = new Padding(10),
|
Padding = new Padding(10),
|
||||||
ColumnCount = 2,
|
ColumnCount = 2,
|
||||||
RowCount = 14
|
RowCount = 15
|
||||||
};
|
};
|
||||||
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 44f));
|
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 44f));
|
||||||
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 56f));
|
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 56f));
|
||||||
@@ -65,10 +66,11 @@ namespace MonsterMonitor.UI
|
|||||||
AddRow(panel, "Локальный порт:", _numLocalPort, 6);
|
AddRow(panel, "Локальный порт:", _numLocalPort, 6);
|
||||||
AddRow(panel, "Макс. потерь:", _numMaxFailures, 7);
|
AddRow(panel, "Макс. потерь:", _numMaxFailures, 7);
|
||||||
AddRow(panel, "Таймаут reconnect (сек):", _numReconnectTimeout, 8);
|
AddRow(panel, "Таймаут reconnect (сек):", _numReconnectTimeout, 8);
|
||||||
AddRow(panel, "Путь к ss:", _txtSsPath, 9);
|
AddRow(panel, "Прокси (http://host:port):", _txtProxy, 9);
|
||||||
AddRow(panel, "Аргументы ss:", _txtSsArgs, 10);
|
AddRow(panel, "Путь к ss:", _txtSsPath, 10);
|
||||||
BuildSystemPasswordRow(panel, 11);
|
AddRow(panel, "Аргументы ss:", _txtSsArgs, 11);
|
||||||
BuildThreeProxyPasswordRow(panel, 12);
|
BuildSystemPasswordRow(panel, 12);
|
||||||
|
BuildThreeProxyPasswordRow(panel, 13);
|
||||||
|
|
||||||
foreach (var num in new[] { _numSshPort, _numRemotePort, _numLocalPort })
|
foreach (var num in new[] { _numSshPort, _numRemotePort, _numLocalPort })
|
||||||
{
|
{
|
||||||
@@ -93,7 +95,7 @@ namespace MonsterMonitor.UI
|
|||||||
|
|
||||||
buttonsPanel.Controls.Add(btnSave);
|
buttonsPanel.Controls.Add(btnSave);
|
||||||
buttonsPanel.Controls.Add(btnCancel);
|
buttonsPanel.Controls.Add(btnCancel);
|
||||||
panel.Controls.Add(buttonsPanel, 0, 13);
|
panel.Controls.Add(buttonsPanel, 0, 14);
|
||||||
panel.SetColumnSpan(buttonsPanel, 2);
|
panel.SetColumnSpan(buttonsPanel, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,6 +202,7 @@ namespace MonsterMonitor.UI
|
|||||||
_numLocalPort.Value = _settings.LocalPort;
|
_numLocalPort.Value = _settings.LocalPort;
|
||||||
_numMaxFailures.Value = _settings.MaxPingFailures;
|
_numMaxFailures.Value = _settings.MaxPingFailures;
|
||||||
_numReconnectTimeout.Value = _settings.ReconnectTimeoutSec;
|
_numReconnectTimeout.Value = _settings.ReconnectTimeoutSec;
|
||||||
|
_txtProxy.Text = _settings.Proxy;
|
||||||
_txtSsPath.Text = _settings.SsProcessPath;
|
_txtSsPath.Text = _settings.SsProcessPath;
|
||||||
_txtSsArgs.Text = _settings.SsArguments;
|
_txtSsArgs.Text = _settings.SsArguments;
|
||||||
_txtSystemPassword.Text = _settings.GetSystemPassword();
|
_txtSystemPassword.Text = _settings.GetSystemPassword();
|
||||||
@@ -223,6 +226,7 @@ namespace MonsterMonitor.UI
|
|||||||
_settings.LocalPort = (int)_numLocalPort.Value;
|
_settings.LocalPort = (int)_numLocalPort.Value;
|
||||||
_settings.MaxPingFailures = (int)_numMaxFailures.Value;
|
_settings.MaxPingFailures = (int)_numMaxFailures.Value;
|
||||||
_settings.ReconnectTimeoutSec = (int)_numReconnectTimeout.Value;
|
_settings.ReconnectTimeoutSec = (int)_numReconnectTimeout.Value;
|
||||||
|
_settings.Proxy = _txtProxy.Text.Trim();
|
||||||
_settings.SsProcessPath = string.IsNullOrWhiteSpace(_txtSsPath.Text)
|
_settings.SsProcessPath = string.IsNullOrWhiteSpace(_txtSsPath.Text)
|
||||||
? System.IO.Path.Combine("App_Data", "ss", "ss.exe")
|
? System.IO.Path.Combine("App_Data", "ss", "ss.exe")
|
||||||
: _txtSsPath.Text.Trim();
|
: _txtSsPath.Text.Trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user