feat.更新了更新功能(?

This commit is contained in:
MistEO
2021-12-05 02:22:21 +08:00
parent 8926bfa381
commit 775ed9318e
13 changed files with 264 additions and 85 deletions

BIN
3rdparty/bin/aria2c.exe vendored Normal file

Binary file not shown.

View File

@@ -2,5 +2,5 @@
namespace asst
{
constexpr static const char* Version = "v2.1.2";
constexpr static const char* Version = "v2.1.3";
}

View File

@@ -246,7 +246,7 @@ namespace MeoAsstGui
case AsstMsg.RecruitSpecialTag:
string special = detail["tag"].ToString();
new ToastContentBuilder().AddText("公招特殊Tag" + special).Show();
new ToastContentBuilder().AddText("公招提示" + special).Show();
break;
case AsstMsg.RecruitResult:

View File

@@ -132,6 +132,9 @@
<Compile Include="UserControl\PenguinReportSettingsUserControl.xaml.cs">
<DependentUpon>PenguinReportSettingsUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\VersionUpdateSettingsUserControl.xaml.cs">
<DependentUpon>VersionUpdateSettingsUserControl.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\RecruitViewModel.cs" />
<Compile Include="ViewModels\RootViewModel.cs" />
<Compile Include="ViewModels\SettingsViewModel.cs" />
@@ -169,6 +172,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\VersionUpdateSettingsUserControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@@ -13,12 +13,6 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center" Margin="10">
<CheckBox IsChecked="{Binding ChooseLevel3}" Content="自动确认3星Tags" Margin="5" />
<CheckBox IsChecked="{Binding ChooseLevel4}" Content="自动确认4星Tags" Margin="5" />
<CheckBox IsChecked="{Binding ChooseLevel5}" Content="自动确认5星Tags" Margin="5" />
<CheckBox IsEnabled="False" IsChecked="False" Content="自动确认6星Tags" Margin="5" />
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="10">
<CheckBox IsChecked="{Binding RefreshLevel3}" Content="自动刷新3星Tags" VerticalAlignment="Center" Margin="10" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0, 10">
<TextBlock Style="{StaticResource TextBlockDefault}"
@@ -27,5 +21,11 @@
Width="50" InputMethod.IsInputMethodEnabled="False" />
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="10">
<CheckBox IsChecked="{Binding ChooseLevel3}" Content="自动确认3星Tags" Margin="5" />
<CheckBox IsChecked="{Binding ChooseLevel4}" Content="自动确认4星Tags" Margin="5" />
<CheckBox IsChecked="{Binding ChooseLevel5}" Content="自动确认5星Tags" Margin="5" />
<CheckBox IsEnabled="False" IsChecked="False" Content="自动确认6星Tags" Margin="5" />
</StackPanel>
</Grid>
</UserControl>

View File

@@ -9,7 +9,7 @@
d:DesignHeight="300" d:DesignWidth="550">
<Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Style="{StaticResource TextBlockDefault}"
<TextBlock Style="{StaticResource TextBlockDefault}" Block.TextAlignment="Center"
Text="企鹅数据汇报ID&#13;(仅数字部分)" Margin="10" />
<TextBox Text="{Binding PenguinId}" Margin="10"
Width="150" InputMethod.IsInputMethodEnabled="False" />

View File

@@ -0,0 +1,28 @@
<UserControl x:Class="MeoAsstGui.VersionUpdateSettingsUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:dd="urn:gong-wpf-dragdrop"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="550">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Style="{StaticResource TextBlockDefault}" HorizontalAlignment="Center" VerticalAlignment="Center"
Text="{Binding VersionInfo, Mode=OneWay}" Margin="10" />
<CheckBox Grid.Row="1" IsChecked="{Binding UpdateBeta}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10"
Content="检查测试版本更新" />
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Style="{StaticResource TextBlockDefault}"
Text="Proxy" Margin="10" />
<TextBox Text="{Binding Proxy}" Margin="10"
Width="150" InputMethod.IsInputMethodEnabled="False" />
</StackPanel>
</Grid>
</UserControl>

View File

@@ -0,0 +1,26 @@
// MeoAssistanceGui - A part of the MeoAssistance-Arknight project
// Copyright (C) 2021 MistEO and Contributors
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
using System.Windows.Controls;
namespace MeoAsstGui
{
/// <summary>
/// PenguinReportSettingsUserControl.xaml 的交互逻辑
/// </summary>
public partial class VersionUpdateSettingsUserControl : UserControl
{
public VersionUpdateSettingsUserControl()
{
InitializeComponent();
}
}
}

View File

@@ -61,7 +61,10 @@ namespace MeoAsstGui
{
var task = Task.Run(() =>
{
return vuvm.CheckAndDownloadUpdate();
if (!vuvm.CheckAndDownloadUpdate())
{
vuvm.ResourceOTA();
}
});
await task;

View File

@@ -9,9 +9,10 @@
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using Stylet;
using StyletIoC;
@@ -22,17 +23,26 @@ namespace MeoAsstGui
private IWindowManager _windowManager;
private IContainer _container;
[DllImport("MeoAssistance.dll")] private static extern IntPtr AsstGetVersion();
private string _versionInfo = "版本号:" + Marshal.PtrToStringAnsi(AsstGetVersion());
public string VersionInfo
{
get { return _versionInfo; }
}
public SettingsViewModel(IContainer container, IWindowManager windowManager)
{
_container = container;
_windowManager = windowManager;
DisplayName = "设置";
_listTitle.Add("基建");
_listTitle.Add("基建设置");
_listTitle.Add("自动公招");
_listTitle.Add("信用商店");
_listTitle.Add("企鹅数据");
//_listTitle.Add("连接");
_listTitle.Add("软件更新");
//_listTitle.Add("其他");
InfrastInit();
@@ -268,7 +278,7 @@ namespace MeoAsstGui
/* 信用商店设置 */
private bool _creditShopping = System.Convert.ToBoolean(ViewStatusStorage.Get("Mall.CreditShopping", bool.FalseString));
private bool _creditShopping = System.Convert.ToBoolean(ViewStatusStorage.Get("Mall.CreditShopping", bool.TrueString));
public bool CreditShopping
{
@@ -354,5 +364,30 @@ namespace MeoAsstGui
ViewStatusStorage.Set("AutoRecruit.ChooseLevel5", value.ToString());
}
}
/* 软件更新设置 */
private bool _updateBeta = System.Convert.ToBoolean(ViewStatusStorage.Get("VersionUpdate.UpdateBeta", bool.FalseString));
public bool UpdateBeta
{
get { return _updateBeta; }
set
{
SetAndNotify(ref _updateBeta, value);
ViewStatusStorage.Set("VersionUpdate.UpdateBeta", value.ToString());
}
}
private string _proxy = ViewStatusStorage.Get("VersionUpdate.Proxy", "");
public string Proxy
{
get { return _proxy; }
set
{
SetAndNotify(ref _proxy, value);
ViewStatusStorage.Set("VersionUpdate.Proxy", value);
}
}
}
}

View File

@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using StyletIoC;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
@@ -15,9 +18,11 @@ namespace MeoAsstGui
public class VersionUpdateViewModel : Screen
{
private IWindowManager _windowManager;
private IContainer _container;
public VersionUpdateViewModel(IWindowManager windowManager)
public VersionUpdateViewModel(IContainer container, IWindowManager windowManager)
{
_container = container;
_windowManager = windowManager;
}
@@ -87,7 +92,8 @@ namespace MeoAsstGui
}
private const string _requestUrl = "https://api.github.com/repos/MistEO/MeoAssistance-Arknights/releases/latest";
private const string _viewUrl = "https://github.com/MistEO/MeoAssistance-Arknights/releases/latest";
private const string _requestBetaUrl = "https://api.github.com/repos/MistEO/MeoAssistance-Arknights/releases";
private string _viewUrl;
private JObject _lastestJson;
private string _downloadUrl;
@@ -179,7 +185,7 @@ namespace MeoAsstGui
.AddButton(openUrlToastButton)
.Show();
// 下载压缩包
const int downloadRetryMaxTimes = 5;
const int downloadRetryMaxTimes = 1;
string downloadTempFilename = UpdatePackageName + ".tmp";
bool downloaded = false;
for (int i = 0; i != downloadRetryMaxTimes; ++i)
@@ -194,11 +200,11 @@ namespace MeoAsstGui
{
new ToastContentBuilder()
.AddText("新版本下载失败")
.AddText("请尝试手动下载后,将压缩包放到exe同级目录_(:з」∠)_")
.AddText("请尝试手动下载后,将压缩包放到目录_(:з」∠)_")
.AddButton(openUrlToastButton)
.Show();
return false;
}
}
File.Copy(downloadTempFilename, UpdatePackageName, true);
File.Delete(downloadTempFilename);
// 把相关信息存下来,更新完之后启动的时候显示
@@ -211,12 +217,20 @@ namespace MeoAsstGui
}
public bool CheckUpdate()
{
{
var settings = _container.Get<SettingsViewModel>();
string response = string.Empty;
const int requestRetryMaxTimes = 5;
for (int i = 0; i != requestRetryMaxTimes; ++i)
{
response = RequestApi(_requestUrl);
if (settings.UpdateBeta)
{
response = RequestApi(_requestBetaUrl);
}
else
{
response = RequestApi(_requestUrl);
}
if (response.Length != 0)
{
break;
@@ -226,8 +240,19 @@ namespace MeoAsstGui
{
return false;
}
JObject json = (JObject)JsonConvert.DeserializeObject(response);
JObject json;
if (settings.UpdateBeta)
{
JArray all = (JArray)JsonConvert.DeserializeObject(response);
json = (JObject)all[0];
}
else
{
json = (JObject)JsonConvert.DeserializeObject(response);
}
_viewUrl = json["html_url"].ToString();
_latestVersion = json["tag_name"].ToString();
if (string.Compare(_latestVersion, _curVersion) <= 0
|| ViewStatusStorage.Get("VersionUpdate.Ignore", string.Empty) == _latestVersion)
@@ -242,63 +267,115 @@ namespace MeoAsstGui
_downloadUrl = downUrl;
_lastestJson = json;
return true;
}
}
}
}
return false;
}
private string RequestApi(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Method = "GET";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36";
httpWebRequest.Accept = "application/vnd.github.v3+json";
//httpWebRequest.Timeout = 20000;
try
{
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
string responseContent = streamReader.ReadToEnd();
streamReader.Close();
httpWebResponse.Close();
return responseContent;
}
catch (Exception)
{
return string.Empty;
}
private string RequestApi(string url)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Method = "GET";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36";
httpWebRequest.Accept = "application/vnd.github.v3+json";
var settings = _container.Get<SettingsViewModel>();
if (settings.Proxy.Length > 0)
{
httpWebRequest.Proxy = new WebProxy(settings.Proxy);
}
//httpWebRequest.Timeout = 20000;
try
{
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
string responseContent = streamReader.ReadToEnd();
streamReader.Close();
httpWebResponse.Close();
return responseContent;
}
catch (Exception)
{
return string.Empty;
}
}
private bool DownloadFile(string url, string path)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpWebRequest.Method = "GET";
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36";
httpWebRequest.Accept = "application/vnd.github.v3+json";
httpWebRequest.Timeout = 20 * 1000;
try
{
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Stream reponseStream = httpWebResponse.GetResponseStream();
Stream fileStream = new FileStream(path, FileMode.Create);
byte[] bArr = new byte[4096];
int size = reponseStream.Read(bArr, 0, (int)bArr.Length);
while (size > 0)
{
fileStream.Write(bArr, 0, size);
size = reponseStream.Read(bArr, 0, (int)bArr.Length);
};
fileStream.Close();
reponseStream.Close();
httpWebResponse.Close();
return true;
}
catch (Exception)
{
return false;
}
}
private bool DownloadFile(string url, string filename)
{
string cmd = Environment.CurrentDirectory + "\\aria2c.exe";
string args = "-c " + url + " -o " + filename;
var settings = _container.Get<SettingsViewModel>();
if (settings.Proxy.Length > 0)
{
args += " --all-proxy " + settings.Proxy;
}
int exit_code = -1;
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = cmd;
startInfo.Arguments = args;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process processTemp = new Process();
processTemp.StartInfo = startInfo;
processTemp.EnableRaisingEvents = true;
try
{
processTemp.Start();
processTemp.WaitForExit();
exit_code = processTemp.ExitCode;
}
catch (Exception ex)
{
return false;
}
return exit_code == 0;
}
public bool ResourceOTA()
{
const string base_url = "https://raw.githubusercontent.com/MistEO/MeoAssistance-Arknights/master/";
var update_dict = new Dictionary<string, string>()
{
{ "3rdparty/resource/penguin-stats-recognize/json/stages.json" , "resource/penguin-stats-recognize/json/stages.json"},
{ "resource/recruit.json", "resource/recruit.json" }
};
bool updated = false;
foreach (var item in update_dict)
{
string url = base_url + item.Key;
string filename = item.Value;
string tempname = filename + ".tmp";
if (!DownloadFile(url, tempname))
{
continue;
}
string src = File.ReadAllText(filename).Replace("\r\n", "\n");
string tmp = File.ReadAllText(tempname).Replace("\r\n", "\n");
if (src.Length < tmp.Length)
{
File.Copy(tempname, filename, true);
updated = true;
}
File.Delete(tempname);
}
if (updated)
{
new ToastContentBuilder().AddText("资源文件已更新").AddText("下次启动软件生效!").Show();
return true;
}
else
{
return false;
}
}
private static void CopyFilesRecursively(string sourcePath, string targetPath)
{
//Now Create all of the directories
@@ -312,14 +389,14 @@ namespace MeoAsstGui
{
File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);
}
}
public void Close()
{
RequestClose();
IsFirstBootAfterUpdate = false;
UpdateTag = "";
UpdateInfo = "";
}
public void Close()
{
RequestClose();
IsFirstBootAfterUpdate = false;
UpdateTag = "";
UpdateInfo = "";
}
}
}

View File

@@ -32,6 +32,9 @@
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[3]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:PenguinReportSettingsUserControl Margin="20" />
<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />
<TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ListTitle[4]}" Foreground="Gray" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />
<local:VersionUpdateSettingsUserControl Margin="20" />
<!--<Rectangle HorizontalAlignment="Stretch" Fill="LightGray" Height="1" />-->
</StackPanel>
</ScrollViewer>

View File

@@ -3,4 +3,4 @@ LatestTag=$(git describe --tags $(git rev-list --tags --max-count=1))
Package="../x64/MeoAssistance_"$LatestTag".zip"
cp ./*.url $TargetDir
7z.exe a $Package $TargetDir/resource $TargetDir/*.dll $TargetDir/MeoAsstGui.exe $TargetDir/*.url
7z.exe a $Package $TargetDir/resource $TargetDir/*.dll $TargetDir/aria2c.exe $TargetDir/MeoAsstGui.exe $TargetDir/*.url