Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
添加更新系统
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-L committed Aug 5, 2020
1 parent a960ff5 commit 9834bab
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 18 deletions.
9 changes: 7 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:Vrc_Lyric_Format_Convert_GUI"
xmlns:mah ="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
Title="Vrc Converter - v1.2 有问题请联系组内或开 Issue" Height="600" Width="520">
Title="Vrc Converter - v1.3 有问题请联系组内或开 Issue" Height="600" Width="520">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.ColumnDefinitions>
Expand Down Expand Up @@ -45,7 +45,12 @@
<TextBox x:Name="JsonIndent" FontSize="18" Margin="5,0" Text="2"/>
</StackPanel>
</GroupBox>
<Button x:Name="README" Content="点击查看说明" Margin="0,5,0,0" Click="README_Click" FontSize="18"/>
<GroupBox>
<StackPanel>
<Button x:Name="README" Content="点击查看说明" Margin="0,5,0,0" Click="README_Click" FontSize="18"/>
<Button x:Name="CheckUpdateButton" Content="检查更新" Margin="0,5,0,0" FontSize="18" Click="CheckUpdateButton_Click"/>
</StackPanel>
</GroupBox>
</StackPanel>
<Button x:Name="Run" Click="Run_Click" Grid.Row="1" Content="走你!" FontSize="18"/>
</Grid>
Expand Down
123 changes: 110 additions & 13 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
using ControlzEx.Standard;
using LitJson;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Win32;
using Microsoft.WindowsAPICodePack.Dialogs;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Net;
using System.Threading;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Vrc_Lyric_Format_Convert_GUI
{
Expand All @@ -39,6 +32,9 @@ public partial class MainWindow : MetroWindow
private string sourceDirPath = "";
private string outputDirPath = "";

// 检查更新
private string version = "v1.3";

public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -400,5 +396,106 @@ private FileInfo[] FindAllFile(string path,string ext)
return directoryInfo.GetFiles(ext, SearchOption.AllDirectories);
}
#endregion

#region 检查更新
private async void CheckUpdateButton_Click(object sender, RoutedEventArgs e)
{
CheckUpdateButton.IsEnabled = false;
CheckUpdateButton.Content = "检查中...";
var client = new RestClient("https://api.misakal.xyz");
var request = new RestRequest("/Software_Update/Vrc_Convert/getUpdataInfo.php");
// var request = new RestRequest("/Software_Update/Vrc_Convert/update.json");
var response = client.Get(request);
if (response.IsSuccessful)
{
try
{
JsonData jsonData = JsonMapper.ToObject(response.Content);
if (version == (string)jsonData["laster"]["version"])
{
await this.ShowMessageAsync("你已经是最新版本了", "最新版本:" + (string)jsonData["laster"]["version"] + "\r\n本地版本:" + version);
}
else
{
MessageDialogResult result = await this.ShowMessageAsync("发现更新", "最新版本:" + (string)jsonData["laster"]["version"] + "\r\n本地版本" + version + "\r\n更新内容:\r\n" + (string)jsonData["laster"]["log"] + "\r\n是否更新?",
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings() {
AffirmativeButtonText = "取消",
NegativeButtonText = "更新"
});
if (result == MessageDialogResult.Negative)
{
var progressControl = await this.ShowProgressAsync("正在更新", "下载新版本中...");
new Thread(a =>
{
try
{
string tempFilePath = "Vrc_Convert_New.zip";
Stream writer = new FileStream(tempFilePath, FileMode.Create);

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest downloadRequest = (HttpWebRequest)WebRequest.Create((string)jsonData["laster"]["download"]);
HttpWebResponse downloadResponse = (HttpWebResponse)downloadRequest.GetResponse();
long totalBytes = downloadResponse.ContentLength;

Stream downloadStream = downloadResponse.GetResponseStream();
long totalDownloadedByte = 0;
byte[] downloadByte = new byte[1024];
int osize = downloadStream.Read(downloadByte, 0, (int)downloadByte.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
writer.Write(downloadByte, 0, osize);
osize = downloadStream.Read(downloadByte, 0, (int)downloadByte.Length);
float downloadProgress = totalDownloadedByte / totalBytes;
// Dispatcher.Invoke(new Action(delegate { progressControl.SetProgress(downloadProgress); progressControl.SetMessage("下载新版本中... (" + (downloadProgress * 100).ToString() + "%)"); }));
progressControl.SetProgress(downloadProgress);
progressControl.SetMessage("下载新版本中... (" + (downloadProgress * 100).ToString() + "%)");
}
downloadStream.Close();
writer.Close();

progressControl.SetMessage("正在释放文件...");
if (Directory.Exists(Environment.CurrentDirectory + "\\update_cache"))
{
Directory.Delete(Environment.CurrentDirectory + "\\update_cache",true);
}
ZipFile.ExtractToDirectory(tempFilePath, Environment.CurrentDirectory+"\\update_cache");
progressControl.CloseAsync();
Dispatcher.Invoke(new Action(
async delegate
{
result = await this.ShowMessageAsync("请手动安装更新", "更新已下载完成。请点击 \"确认\" 并将弹出文件夹内容覆盖程序目录。");
if (result == MessageDialogResult.Affirmative)
{
Process.Start("explorer.exe", Environment.CurrentDirectory + "\\update_cache");
Environment.Exit(0);
}
}));
}
catch (Exception downloadException)
{
progressControl.CloseAsync();
Dispatcher.Invoke(new Action(delegate { this.ShowMessageAsync("下载失败", "错误信息:\r\n" + downloadException.Message + "\r\n错误追踪:" + downloadException.StackTrace); }));
}
})
{ IsBackground = true }.Start();
}
}
}
catch
{
await this.ShowMessageAsync("无法解析更新信息", "服务器返回内容:\r\n" + response.Content);
}
}
else
{
await this.ShowMessageAsync("无法连接到检查更新服务", "Http 状态代码:" + response.StatusCode.ToString() + "\r\n错误信息:" + response.ErrorMessage + "\r\n错误追踪:" + response.ErrorException);
}

CheckUpdateButton.IsEnabled = true;
CheckUpdateButton.Content = "检查更新";
}
#endregion
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: NeutralResourcesLanguage("zh-CN")]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Vrc Convert
基于 [Lyric-Format-Convert](https://github.com/vtbmusic/Lyric-Format-Convert) 的 GUI Vrc 格式转换器
基于 [Lyric-Format-Convert](https://github.com/vtbmusic/Lyric-Format-Convert) 的 GUI Vrc 格式转换器
## 自行编译注意事项
- 请将脚本放入程序目录下的 bin\convert.exe
7 changes: 7 additions & 0 deletions Vrc-Lyric-Format-Convert-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
</Reference>
<Reference Include="LitJSON, Version=0.16.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\LitJson.0.16.0\lib\net45\LitJSON.dll</HintPath>
</Reference>
<Reference Include="MahApps.Metro, Version=2.0.0.0, Culture=neutral, PublicKeyToken=51482d6f650b2b3f, processorArchitecture=MSIL">
<HintPath>packages\MahApps.Metro.2.2.0\lib\net452\MahApps.Metro.dll</HintPath>
</Reference>
Expand All @@ -59,10 +62,14 @@
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.Xaml.Behaviors.Wpf.1.1.19\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.11.4.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>packages\RestSharp.106.11.4\lib\net452\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml" />
Expand Down
2 changes: 2 additions & 0 deletions packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<package id="ControlzEx" version="4.3.2" targetFramework="net452" />
<package id="Costura.Fody" version="4.1.0" targetFramework="net45" />
<package id="Fody" version="6.0.0" targetFramework="net45" developmentDependency="true" />
<package id="LitJson" version="0.16.0" targetFramework="net452" />
<package id="MahApps.Metro" version="2.2.0" targetFramework="net452" />
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.19" targetFramework="net452" />
<package id="RestSharp" version="106.11.4" targetFramework="net452" />
<package id="WindowsAPICodePack-Core" version="1.1.1" targetFramework="net45" />
<package id="WindowsAPICodePack-Shell" version="1.1.1" targetFramework="net45" />
</packages>
20 changes: 20 additions & 0 deletions update/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"total": 3,
"laster":{
"version": "v1.3",
"log": "添加了检查更新系统",
"download": "https://api.misakal.xyz/Software_Update/Vrc_Convert/files/Crc Convert v1.3.zip"
},
"history":[
{
"version": "v1.3",
"log": "添加了检查更新系统",
"download": "https://api.misakal.xyz/Software_Update/Vrc_Convert/files/Crc Convert v1.3.zip"
},
{
"version": "v1.2",
"log": "更新 UI 界面\n添加递归模式支持",
"download":"https://api.misakal.xyz/Software_Update/Vrc_Convert/files/Crc Convert v1.2.zip"
}
]
}

0 comments on commit 9834bab

Please sign in to comment.