Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
427f16cde0 | ||
|
|
fe8abb589f | ||
|
|
ae787373dc | ||
|
|
4f2fe7b292 | ||
|
|
635a489cc1 | ||
|
|
5b82edb9ee | ||
|
|
84e0fbb959 | ||
|
|
fdebc16b37 | ||
|
|
8467399001 | ||
|
|
2fb673661f |
@@ -43,7 +43,7 @@ jobs:
|
|||||||
id: create_release
|
id: create_release
|
||||||
uses: actions/create-release@v1
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
release_name: ${{ github.ref }}
|
release_name: ${{ github.ref }}
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
id: upload-release-asset
|
id: upload-release-asset
|
||||||
uses: actions/upload-release-asset@v1
|
uses: actions/upload-release-asset@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
|
||||||
asset_path: /app/MonsterMonitor.zip
|
asset_path: /app/MonsterMonitor.zip
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
1.0.1
|
1.0.11
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.32929.386
|
VisualStudioVersion = 16.0.32929.386
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonsterMonitor", "src\MonsterMonitor.csproj", "{7D6104C6-6AEF-4D31-8463-FCEABDF1577A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonsterMonitor", "MonsterMonitor\MonsterMonitor.csproj", "{7D6104C6-6AEF-4D31-8463-FCEABDF1577A}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -4,7 +4,7 @@ using System.IO;
|
|||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Models
|
namespace MonsterMonitor.Models
|
||||||
{
|
{
|
||||||
public sealed class AppSettings
|
public sealed class AppSettings
|
||||||
{
|
{
|
||||||
@@ -58,7 +58,7 @@ namespace SshTunnelMonitor.Models
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(SystemPasswordProtected))
|
if (string.IsNullOrWhiteSpace(SystemPasswordProtected))
|
||||||
{
|
{
|
||||||
return "STerra";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SystemPasswordProtected.StartsWith(ProtectedPrefix, StringComparison.Ordinal))
|
if (!SystemPasswordProtected.StartsWith(ProtectedPrefix, StringComparison.Ordinal))
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net472</TargetFramework>
|
<TargetFramework>net472</TargetFramework>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<RootNamespace>SshTunnelMonitor</RootNamespace>
|
<RootNamespace>MonsterMonitor</RootNamespace>
|
||||||
<AssemblyName>MonsterMonitor</AssemblyName>
|
<AssemblyName>MonsterMonitor</AssemblyName>
|
||||||
|
<AssemblyVersion>1.0.11</AssemblyVersion>
|
||||||
|
<Version>1.0.11</Version>
|
||||||
|
<FileVersion>1.0.11</FileVersion>
|
||||||
|
<InformationalVersion>1.0.11</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||||
@@ -14,7 +18,9 @@
|
|||||||
<PackageReference Include="Fody" Version="6.9.3">
|
<PackageReference Include="Fody" Version="6.9.3">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<Reference Include="System.IO.Compression.FileSystem" />
|
||||||
<Reference Include="System.Security" />
|
<Reference Include="System.Security" />
|
||||||
|
<Reference Include="System.Runtime.Serialization" />
|
||||||
<PackageReference Include="SSH.NET" Version="2025.1.0" />
|
<PackageReference Include="SSH.NET" Version="2025.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -28,4 +34,4 @@
|
|||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using SshTunnelMonitor.UI;
|
using MonsterMonitor.UI;
|
||||||
|
|
||||||
namespace SshTunnelMonitor
|
namespace MonsterMonitor
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using SshTunnelMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public sealed class AppController : IDisposable
|
public sealed class AppController : IDisposable
|
||||||
{
|
{
|
||||||
@@ -4,9 +4,9 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using SshTunnelMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public class AuthMonitor: IAuthMonitor
|
public class AuthMonitor: IAuthMonitor
|
||||||
{
|
{
|
||||||
@@ -57,8 +57,12 @@ namespace SshTunnelMonitor.Services
|
|||||||
var activeWindowTitle = GetActiveWindowTitle();
|
var activeWindowTitle = GetActiveWindowTitle();
|
||||||
if (activeWindowTitle?.Contains("XAuth request") == true)
|
if (activeWindowTitle?.Contains("XAuth request") == true)
|
||||||
{
|
{
|
||||||
SendKeys.SendWait(_settings.GetSystemPassword());
|
var password = _settings.GetSystemPassword();
|
||||||
SendKeys.SendWait("{ENTER}");
|
if (!string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
SendKeys.SendWait(password);
|
||||||
|
SendKeys.SendWait("{ENTER}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -0,0 +1,332 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Net;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Runtime.Serialization.Json;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace MonsterMonitor.Services
|
||||||
|
{
|
||||||
|
public sealed class GitHubUpdateService
|
||||||
|
{
|
||||||
|
private const string GithubUser = "monster1025";
|
||||||
|
private const string GithubRepo = "monster_monitor_v2";
|
||||||
|
private const string GithubToken = "";
|
||||||
|
|
||||||
|
private readonly LogService _log;
|
||||||
|
|
||||||
|
public GitHubUpdateService(LogService log)
|
||||||
|
{
|
||||||
|
_log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CheckAndPrepareUpdateAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var currentVersion = GetCurrentVersion();
|
||||||
|
_log.Info("Проверка обновлений...");
|
||||||
|
_log.Info("Текущая версия: " + currentVersion);
|
||||||
|
|
||||||
|
var release = await GetLatestReleaseAsync();
|
||||||
|
if (release == null)
|
||||||
|
{
|
||||||
|
_log.Warn("Не удалось получить данные о релизе с GitHub.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var latestVersion = ParseVersion(release.TagName);
|
||||||
|
if (latestVersion == null)
|
||||||
|
{
|
||||||
|
_log.Warn("Не удалось распарсить версию релиза: " + (release.TagName ?? "<empty>"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Info("Версия на GitHub: " + latestVersion);
|
||||||
|
if (latestVersion <= currentVersion)
|
||||||
|
{
|
||||||
|
_log.Info("Обновление не требуется.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Info("Найдена новая версия. Начинаю загрузку обновления...");
|
||||||
|
var zipAsset = FindZipAsset(release.Assets);
|
||||||
|
if (zipAsset == null)
|
||||||
|
{
|
||||||
|
_log.Warn("У релиза нет .zip-ассета для автообновления.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tempRoot = Path.Combine(Path.GetTempPath(), "MonsterMonitorUpdate");
|
||||||
|
var packageDir = Path.Combine(tempRoot, latestVersion.ToString());
|
||||||
|
var packageZip = Path.Combine(packageDir, "update.zip");
|
||||||
|
var extractDir = Path.Combine(packageDir, "extracted");
|
||||||
|
Directory.CreateDirectory(packageDir);
|
||||||
|
|
||||||
|
await DownloadFileAsync(GetAssetDownloadUrl(zipAsset), packageZip);
|
||||||
|
_log.Info("Архив обновления загружен: " + zipAsset.Name);
|
||||||
|
|
||||||
|
if (Directory.Exists(extractDir))
|
||||||
|
{
|
||||||
|
Directory.Delete(extractDir, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipFile.ExtractToDirectory(packageZip, extractDir);
|
||||||
|
_log.Info("Архив обновления распакован.");
|
||||||
|
|
||||||
|
var appDir = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
|
var exePath = Application.ExecutablePath;
|
||||||
|
var updaterBat = Path.Combine(packageDir, "apply_update.bat");
|
||||||
|
File.WriteAllText(updaterBat, BuildUpdaterScript(appDir, extractDir, exePath), Encoding.ASCII);
|
||||||
|
|
||||||
|
_log.Info("Обновление подготовлено.");
|
||||||
|
var restartNow = MessageBox.Show(
|
||||||
|
"Обновление загружено и готово к установке. Перезапустить приложение сейчас?",
|
||||||
|
"Monster Monitor",
|
||||||
|
MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question);
|
||||||
|
|
||||||
|
if (restartNow == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_log.Info("Перезапуск приложения для применения обновления...");
|
||||||
|
StartUpdaterAndExit(updaterBat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Warn("Перезапуск отложен. Обновление будет применено после следующего запуска через обновлятор.");
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
var response = ex.Response as HttpWebResponse;
|
||||||
|
var statusCode = response != null ? ((int)response.StatusCode).ToString(CultureInfo.InvariantCulture) : "n/a";
|
||||||
|
var statusText = response != null ? response.StatusCode.ToString() : "unknown";
|
||||||
|
_log.Error("Ошибка обновления (HTTP): " + statusCode + " " + statusText + ". " + ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log.Error("Ошибка обновления: " + ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Version GetCurrentVersion()
|
||||||
|
{
|
||||||
|
Version version;
|
||||||
|
if (!Version.TryParse(Application.ProductVersion, out version))
|
||||||
|
{
|
||||||
|
version = new Version(1, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Version ParseVersion(string rawVersion)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(rawVersion))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalized = rawVersion.Trim();
|
||||||
|
if (normalized.StartsWith("v", true, CultureInfo.InvariantCulture))
|
||||||
|
{
|
||||||
|
normalized = normalized.Substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Version version;
|
||||||
|
if (Version.TryParse(normalized, out version))
|
||||||
|
{
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<GithubRelease> GetLatestReleaseAsync()
|
||||||
|
{
|
||||||
|
var url = string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"https://api.github.com/repos/{0}/{1}/releases/latest",
|
||||||
|
GithubUser,
|
||||||
|
GithubRepo);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var request = CreateGithubRequest(url, "application/vnd.github+json");
|
||||||
|
using (var response = (HttpWebResponse)await request.GetResponseAsync())
|
||||||
|
using (var stream = response.GetResponseStream())
|
||||||
|
{
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serializer = new DataContractJsonSerializer(typeof(GithubRelease));
|
||||||
|
return serializer.ReadObject(stream) as GithubRelease;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (WebException ex)
|
||||||
|
{
|
||||||
|
var response = ex.Response as HttpWebResponse;
|
||||||
|
if (response != null && response.StatusCode == HttpStatusCode.NotFound)
|
||||||
|
{
|
||||||
|
_log.Warn("Релиз /latest не найден. Пробую получить список релизов...");
|
||||||
|
return await GetLatestReleaseFromListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<GithubRelease> GetLatestReleaseFromListAsync()
|
||||||
|
{
|
||||||
|
var url = string.Format(
|
||||||
|
CultureInfo.InvariantCulture,
|
||||||
|
"https://api.github.com/repos/{0}/{1}/releases",
|
||||||
|
GithubUser,
|
||||||
|
GithubRepo);
|
||||||
|
|
||||||
|
var request = CreateGithubRequest(url, "application/vnd.github+json");
|
||||||
|
using (var response = (HttpWebResponse)await request.GetResponseAsync())
|
||||||
|
using (var stream = response.GetResponseStream())
|
||||||
|
{
|
||||||
|
if (stream == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var serializer = new DataContractJsonSerializer(typeof(List<GithubRelease>));
|
||||||
|
var releases = serializer.ReadObject(stream) as List<GithubRelease>;
|
||||||
|
if (releases == null || releases.Count == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return releases[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DownloadFileAsync(string url, string filePath)
|
||||||
|
{
|
||||||
|
var request = CreateGithubRequest(url, "application/octet-stream");
|
||||||
|
|
||||||
|
using (var response = (HttpWebResponse)await request.GetResponseAsync())
|
||||||
|
using (var responseStream = response.GetResponseStream())
|
||||||
|
using (var fileStream = File.Create(filePath))
|
||||||
|
{
|
||||||
|
if (responseStream == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Пустой поток ответа при загрузке файла.");
|
||||||
|
}
|
||||||
|
|
||||||
|
await responseStream.CopyToAsync(fileStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GithubAsset FindZipAsset(IList<GithubAsset> assets)
|
||||||
|
{
|
||||||
|
if (assets == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var asset in assets)
|
||||||
|
{
|
||||||
|
if (asset == null || string.IsNullOrWhiteSpace(asset.Name))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetAssetDownloadUrl(GithubAsset asset)
|
||||||
|
{
|
||||||
|
if (asset == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(asset.ApiUrl))
|
||||||
|
{
|
||||||
|
return asset.ApiUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return asset.DownloadUrl ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpWebRequest CreateGithubRequest(string url, string accept)
|
||||||
|
{
|
||||||
|
var request = (HttpWebRequest)WebRequest.Create(url);
|
||||||
|
request.Method = "GET";
|
||||||
|
request.Accept = accept;
|
||||||
|
request.UserAgent = "MonsterMonitorUpdater/1.0";
|
||||||
|
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
|
||||||
|
if (!string.IsNullOrWhiteSpace(GithubToken))
|
||||||
|
{
|
||||||
|
request.Headers.Add("Authorization", "Bearer " + GithubToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildUpdaterScript(string appDir, string extractDir, string exePath)
|
||||||
|
{
|
||||||
|
return "@echo off" + Environment.NewLine +
|
||||||
|
"setlocal" + Environment.NewLine +
|
||||||
|
"timeout /t 2 /nobreak >nul" + Environment.NewLine +
|
||||||
|
"xcopy \"" + extractDir + "\\*\" \"" + appDir + "\\\" /E /I /Y /Q >nul" + Environment.NewLine +
|
||||||
|
"start \"\" \"" + exePath + "\"" + Environment.NewLine +
|
||||||
|
"endlocal" + Environment.NewLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void StartUpdaterAndExit(string updaterBat)
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = updaterBat,
|
||||||
|
WorkingDirectory = Path.GetDirectoryName(updaterBat) ?? AppDomain.CurrentDomain.BaseDirectory,
|
||||||
|
UseShellExecute = true,
|
||||||
|
CreateNoWindow = true,
|
||||||
|
WindowStyle = ProcessWindowStyle.Hidden
|
||||||
|
};
|
||||||
|
|
||||||
|
Process.Start(psi);
|
||||||
|
Application.Exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataContract]
|
||||||
|
public sealed class GithubRelease
|
||||||
|
{
|
||||||
|
[DataMember(Name = "tag_name")]
|
||||||
|
public string TagName { get; set; }
|
||||||
|
|
||||||
|
[DataMember(Name = "assets")]
|
||||||
|
public List<GithubAsset> Assets { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[DataContract]
|
||||||
|
public sealed class GithubAsset
|
||||||
|
{
|
||||||
|
[DataMember(Name = "url")]
|
||||||
|
public string ApiUrl { get; set; }
|
||||||
|
|
||||||
|
[DataMember(Name = "name")]
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
[DataMember(Name = "browser_download_url")]
|
||||||
|
public string DownloadUrl { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public enum LogLevel
|
public enum LogLevel
|
||||||
{
|
{
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public sealed class PowerManagementService
|
public sealed class PowerManagementService
|
||||||
{
|
{
|
||||||
+1
-1
@@ -2,7 +2,7 @@ using System;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public sealed class ProcessMonitorService : IDisposable
|
public sealed class ProcessMonitorService : IDisposable
|
||||||
{
|
{
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using SshTunnelMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public sealed class SsConfigService
|
public sealed class SsConfigService
|
||||||
{
|
{
|
||||||
@@ -28,6 +28,7 @@ namespace SshTunnelMonitor.Services
|
|||||||
|
|
||||||
var config = "users admin:CL:" + password + "\r\n" +
|
var config = "users admin:CL:" + password + "\r\n" +
|
||||||
"auth strong\r\n" +
|
"auth strong\r\n" +
|
||||||
|
"maxconn 2000\r\n" +
|
||||||
$"socks -i127.0.0.1 -p{port}";
|
$"socks -i127.0.0.1 -p{port}";
|
||||||
|
|
||||||
var configPath = GetConfigPath();
|
var configPath = GetConfigPath();
|
||||||
@@ -2,11 +2,11 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using MonsterMonitor.Models;
|
||||||
using Renci.SshNet;
|
using Renci.SshNet;
|
||||||
using Renci.SshNet.Common;
|
using Renci.SshNet.Common;
|
||||||
using SshTunnelMonitor.Models;
|
|
||||||
|
|
||||||
namespace SshTunnelMonitor.Services
|
namespace MonsterMonitor.Services
|
||||||
{
|
{
|
||||||
public sealed class SshTunnelService : IDisposable
|
public sealed class SshTunnelService : IDisposable
|
||||||
{
|
{
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
using SshTunnelMonitor.Models;
|
|
||||||
using SshTunnelMonitor.Services;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using MonsterMonitor.Models;
|
||||||
|
using MonsterMonitor.Services;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.UI
|
namespace MonsterMonitor.UI
|
||||||
{
|
{
|
||||||
public sealed class MainForm : Form
|
public sealed class MainForm : Form
|
||||||
{
|
{
|
||||||
@@ -12,16 +13,19 @@ namespace SshTunnelMonitor.UI
|
|||||||
private readonly Button _btnSettings = new Button();
|
private readonly Button _btnSettings = new Button();
|
||||||
private readonly Button _btnExit = new Button();
|
private readonly Button _btnExit = new Button();
|
||||||
private readonly NotifyIcon _notifyIcon = new NotifyIcon();
|
private readonly NotifyIcon _notifyIcon = new NotifyIcon();
|
||||||
|
private readonly Timer _updateTimer = new Timer();
|
||||||
private readonly Icon _trayIcon;
|
private readonly Icon _trayIcon;
|
||||||
private readonly LogService _log = new LogService();
|
private readonly LogService _log = new LogService();
|
||||||
private readonly PowerManagementService _power = new PowerManagementService();
|
private readonly PowerManagementService _power = new PowerManagementService();
|
||||||
|
private GitHubUpdateService _updateService;
|
||||||
private AppController _controller;
|
private AppController _controller;
|
||||||
private AppSettings _settings;
|
private AppSettings _settings;
|
||||||
private bool _allowClose;
|
private bool _allowClose;
|
||||||
|
private bool _isUpdateCheckRunning;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
Text = "Monster Monitor";
|
Text = string.Format("Monster Monitor v{0}", Application.ProductVersion);
|
||||||
Width = 980;
|
Width = 980;
|
||||||
Height = 620;
|
Height = 620;
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
@@ -39,7 +43,10 @@ namespace SshTunnelMonitor.UI
|
|||||||
|
|
||||||
_settings = AppSettings.Load();
|
_settings = AppSettings.Load();
|
||||||
_controller = new AppController(_log, _power);
|
_controller = new AppController(_log, _power);
|
||||||
|
_updateService = new GitHubUpdateService(_log);
|
||||||
RestartServices();
|
RestartServices();
|
||||||
|
ConfigureUpdateTimer();
|
||||||
|
_ = RunUpdateCheckAsync(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildUi()
|
private void BuildUi()
|
||||||
@@ -144,6 +151,8 @@ namespace SshTunnelMonitor.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
_notifyIcon.Visible = false;
|
_notifyIcon.Visible = false;
|
||||||
|
_updateTimer.Stop();
|
||||||
|
_updateTimer.Dispose();
|
||||||
_controller?.Dispose();
|
_controller?.Dispose();
|
||||||
_trayIcon?.Dispose();
|
_trayIcon?.Dispose();
|
||||||
}
|
}
|
||||||
@@ -164,6 +173,42 @@ namespace SshTunnelMonitor.UI
|
|||||||
_console.ScrollToCaret();
|
_console.ScrollToCaret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ConfigureUpdateTimer()
|
||||||
|
{
|
||||||
|
_updateTimer.Interval = (int)TimeSpan.FromHours(1).TotalMilliseconds;
|
||||||
|
_updateTimer.Tick += async (_, __) => await RunUpdateCheckAsync(false);
|
||||||
|
_updateTimer.Start();
|
||||||
|
_log.Info("Автопроверка обновлений включена (раз в 1 час).");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task RunUpdateCheckAsync(bool isInitialCheck)
|
||||||
|
{
|
||||||
|
if (_isUpdateCheckRunning)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_isUpdateCheckRunning = true;
|
||||||
|
if (isInitialCheck)
|
||||||
|
{
|
||||||
|
// Небольшая задержка, чтобы окно и лог уже успели инициализироваться.
|
||||||
|
await Task.Delay(1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_log.Info("Плановая проверка обновлений...");
|
||||||
|
}
|
||||||
|
|
||||||
|
await _updateService.CheckAndPrepareUpdateAsync();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isUpdateCheckRunning = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Color GetColor(LogLevel level)
|
private static Color GetColor(LogLevel level)
|
||||||
{
|
{
|
||||||
switch (level)
|
switch (level)
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
using System;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using SshTunnelMonitor.Models;
|
using MonsterMonitor.Models;
|
||||||
|
|
||||||
namespace SshTunnelMonitor.UI
|
namespace MonsterMonitor.UI
|
||||||
{
|
{
|
||||||
public sealed class SettingsForm : Form
|
public sealed class SettingsForm : Form
|
||||||
{
|
{
|
||||||
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
+41
-28
@@ -9,39 +9,52 @@ set informationalversion=%1
|
|||||||
if [%2] NEQ [] SET fileversion=%2
|
if [%2] NEQ [] SET fileversion=%2
|
||||||
if [%3] NEQ [] SET informationalversion=%3
|
if [%3] NEQ [] SET informationalversion=%3
|
||||||
|
|
||||||
echo Setting assembly version information
|
echo Setting version in *.csproj files
|
||||||
|
set "script=%TEMP%\setversion-csproj.ps1"
|
||||||
|
(
|
||||||
|
echo param^(
|
||||||
|
echo [string]$Version,
|
||||||
|
echo [string]$FileVersion,
|
||||||
|
echo [string]$InformationalVersion
|
||||||
|
echo ^)
|
||||||
|
echo $ErrorActionPreference = "Stop"
|
||||||
|
echo $projects = Get-ChildItem -Path ^(Get-Location^) -Filter *.csproj -Recurse
|
||||||
|
echo foreach ^($project in $projects^) ^{
|
||||||
|
echo Write-Host "^> $($project.FullName)"
|
||||||
|
echo [xml]$xml = Get-Content -Path $project.FullName
|
||||||
|
echo $propertyGroup = $xml.Project.PropertyGroup ^| Select-Object -First 1
|
||||||
|
echo if ^(-not $propertyGroup^) ^{
|
||||||
|
echo $propertyGroup = $xml.CreateElement^("PropertyGroup"^)
|
||||||
|
echo [void]$xml.Project.AppendChild^($propertyGroup^)
|
||||||
|
echo ^}
|
||||||
|
echo function Set-Or-CreateTag ^([xml]$doc, [System.Xml.XmlElement]$group, [string]$tagName, [string]$value^) ^{
|
||||||
|
echo $node = $group.SelectSingleNode^($tagName^)
|
||||||
|
echo if ^($node^) ^{
|
||||||
|
echo $node.InnerText = $value
|
||||||
|
echo ^} else ^{
|
||||||
|
echo $newNode = $doc.CreateElement^($tagName^)
|
||||||
|
echo $newNode.InnerText = $value
|
||||||
|
echo [void]$group.AppendChild^($newNode^)
|
||||||
|
echo ^}
|
||||||
|
echo ^}
|
||||||
|
echo Set-Or-CreateTag $xml $propertyGroup "Version" $Version
|
||||||
|
echo Set-Or-CreateTag $xml $propertyGroup "AssemblyVersion" $Version
|
||||||
|
echo Set-Or-CreateTag $xml $propertyGroup "FileVersion" $FileVersion
|
||||||
|
echo Set-Or-CreateTag $xml $propertyGroup "InformationalVersion" $InformationalVersion
|
||||||
|
echo $xml.Save^($project.FullName^)
|
||||||
|
echo ^}
|
||||||
|
) > "%script%"
|
||||||
|
|
||||||
for /F "delims=" %%f in ('dir /s /b Assemblyinfo.cs') do (
|
powershell -NoProfile -ExecutionPolicy Bypass -File "%script%" "%version%" "%fileversion%" "%informationalversion%"
|
||||||
echo ^> %%f
|
set exit_code=%ERRORLEVEL%
|
||||||
|
del /q "%script%" >nul 2>&1
|
||||||
pushd %%~dpf
|
if not %exit_code%==0 exit /b %exit_code%
|
||||||
|
echo Done!
|
||||||
for /F "usebackq delims=" %%g in ("AssemblyInfo.cs") do (
|
|
||||||
set ln=%%g
|
|
||||||
set skip=0
|
|
||||||
|
|
||||||
if "!ln:AssemblyVersion=!" NEQ "!ln!" set skip=1
|
|
||||||
if "!ln:AssemblyFileVersion=!" NEQ "!ln!" set skip=1
|
|
||||||
if "!ln:AssemblyInformationalVersion=!" NEQ "!ln!" set skip=1
|
|
||||||
|
|
||||||
if !skip!==0 echo !ln! >> AssemblyInfo.cs.versioned
|
|
||||||
)
|
|
||||||
|
|
||||||
echo [assembly: AssemblyVersion^("%version%"^)] >> AssemblyInfo.cs.versioned
|
|
||||||
echo [assembly: AssemblyFileVersion^("%fileversion%"^)] >> AssemblyInfo.cs.versioned
|
|
||||||
echo [assembly: AssemblyInformationalVersion^("%informationalversion%"^)] >> AssemblyInfo.cs.versioned
|
|
||||||
|
|
||||||
copy /y AssemblyInfo.cs AssemblyInfo.cs.orig
|
|
||||||
move /y AssemblyInfo.cs.versioned AssemblyInfo.cs
|
|
||||||
|
|
||||||
popd
|
|
||||||
)
|
|
||||||
echo Done^^!
|
|
||||||
|
|
||||||
GOTO:EOF
|
GOTO:EOF
|
||||||
|
|
||||||
:USAGE
|
:USAGE
|
||||||
echo Usage:
|
echo Usage:
|
||||||
echo.
|
echo.
|
||||||
echo SetVersion.bat Version [FileVersion] [InformationalVersion]
|
echo SetVersion.cmd Version [FileVersion] [InformationalVersion]
|
||||||
echo.
|
echo.
|
||||||
Reference in New Issue
Block a user