Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #37 from RyoLee/dev
Browse files Browse the repository at this point in the history
add: autoupdate
  • Loading branch information
Lee committed Feb 28, 2022
2 parents b9ee156 + 5589404 commit ef6bbb1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Gevjon-Core/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="autoUpdate" value="1" />
<add key="alpha" value="0.5" />
<add key="width" value="380" />
<add key="height" value="400" />
Expand All @@ -10,6 +11,8 @@
<add key="lightMode" value="0" />
<add key="currentFontName" value="Microsoft YaHei UI" />
<add key="currentFontSize" value="16" />
<add key="verURL" value="https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/version.txt" />
<add key="dlURL" value="https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/Gevjon.7z" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
Expand Down
4 changes: 3 additions & 1 deletion Gevjon-Core/Gevjon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@
<PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>xcopy "$(SolutionDir)DB\data.json" "$(TargetDir)" /S /Y</PostBuildEvent>
<PostBuildEvent>xcopy "$(SolutionDir)DB\data.json" "$(TargetDir)" /Y
xcopy "$(SolutionDir)README.md" "$(TargetDir)" /Y
xcopy "$(SolutionDir)version.txt" "$(TargetDir)" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions Gevjon-Core/mainwindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<Button x:Name="MoveButton" Content="" ToolTip="左键移动窗口,右键切换收起/展开" Margin="5" Grid.Column="0" PreviewMouseRightButtonDown="MoveButton_RightMouseDown" PreviewMouseLeftButtonDown="MoveButton_LeftMouseDown"/>
<Button x:Name="SettingButton" Content="S" ToolTip="设置(暂未启用)" Margin="5" Grid.Column="1" />
<CheckBox x:Name="OnTopCheckBox" Content="置顶" ToolTip="窗口始终显示在最上层" Checked="OnTopCheckBox_Checked" Unchecked="OnTopCheckBox_Unchecked" Grid.Column="2" Margin="5" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<CheckBox x:Name="OnTopCheckBox" Content="置顶" ToolTip="窗口始终显示在最上层" Checked="OnTopCheckBox_Checked" Unchecked="OnTopCheckBox_Unchecked" Grid.Column="1" Margin="5" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<CheckBox x:Name="UpdateCheckBox" Content="更新" ToolTip="启动时检查更新" Checked="UpdateCheckBox_Checked" Unchecked="UpdateCheckBox_Unchecked" Margin="5" Grid.Column="2" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<CheckBox x:Name="PipeServerCheckBox" Content="服务" ToolTip="监听服务,开启后接受其他联动工具控制显示内容" Checked="PipeServerCheckBox_Checked" Unchecked="PipeServerCheckBox_Unchecked" Margin="5" Grid.Column="3" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<CheckBox x:Name="LightModeCheckBox" Content="轻量" IsEnabled="False" ToolTip="纯显示模式,简化UI,仅服务模式有效" Checked="LightModeCheckBox_Checked" Unchecked="LightModeCheckBox_Unchecked" Margin="5" Grid.Column="4" VerticalContentAlignment="Center" VerticalAlignment="Center"/>
<Button x:Name="ExitButton" Content="X" ToolTip="退出" Margin="5" Grid.Column="5" Click="ExitButton_Click"/>
Expand Down
55 changes: 54 additions & 1 deletion Gevjon-Core/mainwindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
InitBackground();
pipeServer = new PipeServer(this);
UpdateCheckBox.IsChecked = "1".Equals(GetSetting("autoUpdate", "1"));
Background.Opacity = float.Parse(GetSetting("alpha", "0.75"));
Width = int.Parse(GetSetting("width", "300"));
Height = int.Parse(GetSetting("height", "600"));
Expand Down Expand Up @@ -330,7 +331,7 @@ private void InitBackground()
ExitButton.Background = Background;
CardIdBox.Background = Background;
CardNameBox.Background = Background;
SettingButton.Background = Background;
UpdateCheckBox.Background = Background;
CardComboBox.Background = Background;
CardDescBox.Background = Background;
}
Expand Down Expand Up @@ -506,5 +507,57 @@ private void MoveButton_RightMouseDown(object sender, System.Windows.Input.Mouse
e.Handled = true;
}
}

private void UpdateCheckBox_Checked(object sender, RoutedEventArgs e)
{
SetSetting("autoUpdate", "1");
CheckUpdate();
e.Handled = true;
}

private void UpdateCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
SetSetting("autoUpdate", "0");
e.Handled = true;
}
private async Task CheckUpdate()
{
if (System.Threading.Monitor.TryEnter(UpdateCheckBox)) {
try
{
string HITS_URL = "https://hits.dwyl.com/RyoLee/Gevjon.svg";
string VER_URL = GetSetting("verURL", "https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/version.txt");
string REL_URL = GetSetting("dlURL", "https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/Gevjon.7z");
string remote_ver_str = await TryGetAsync(VER_URL);
string locale_ver_str;
using (StreamReader reader = new StreamReader("version.txt")) {
locale_ver_str = reader.ReadLine() ?? "";
}
var remote_ver = new Version(remote_ver_str);
var locale_ver = new Version(locale_ver_str);
if (remote_ver.CompareTo(locale_ver)==1) {
if (MessageBox.Show("本地:\t" + locale_ver_str + "\n远端:\t" + remote_ver_str + "\n是否更新?", "发现新版本", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) {
await TryGetAsync(HITS_URL);
System.Diagnostics.Process.Start(REL_URL);
}
}
}
finally {
System.Threading.Monitor.Exit(UpdateCheckBox);
}
}
}
private async Task<String> TryGetAsync(string url)
{
using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient())
{
System.Net.Http.HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
return default;
}
}
}
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Gevjon
[![HitCount](https://hits.dwyl.com/RyoLee/Gevjon.svg?style=flat-square)](https://github.com/RyoLee/Gevjon)
<!-- (http://hits.dwyl.com/RyoLee/Gevjon) -->
[![HitCount](https://hits.dwyl.com/RyoLee/Gevjon.svg?style=flat-square)](https://github.com/RyoLee/Gevjon) <!-- (http://hits.dwyl.com/RyoLee/Gevjon) -->
[![GitHub all releases](https://img.shields.io/github/downloads/RyoLee/Gevjon/total?logo=Github&style=flat-square)](https://github.com/RyoLee/Gevjon/releases/latest)
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/RyoLee/Gevjon?include_prereleases&style=flat-square#?sort=date)](https://github.com/RyoLee/Gevjon/releases/latest)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/RyoLee/Gevjon/Deploy/master?label=Build&style=flat-square)](https://github.com/RyoLee/Gevjon/actions/workflows/deploy.yml)
Expand Down

0 comments on commit ef6bbb1

Please sign in to comment.