Skip to content

Commit

Permalink
添加了自动更新检测功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Dec 21, 2020
1 parent 3342e35 commit 0b88de7
Show file tree
Hide file tree
Showing 16 changed files with 218 additions and 22 deletions.
1 change: 1 addition & 0 deletions SteamTool.Model/Const.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Const
public const string HOST_TAG = "#S302";

public const string REWARDMELIST_URL = "https://raw.githubusercontent.com/rmbadmin/SteamTools/develop/Data/RewardRecord.json";
public const string GITHUB_RELEASEAPI_URL = "https://api.github.com/repos/rmbadmin/SteamTools/releases/latest";

public const string GITHUB_URL = "https://github.com/rmbadmin/SteamTools";
public const string GITHUB_RELEASES_URL = "https://github.com/rmbadmin/SteamTools/releases";
Expand Down
31 changes: 31 additions & 0 deletions SteamTool.Model/ToolModel/GithubReleaseModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SteamTool.Model.ToolModel
{
public class GithubReleaseModel
{
public string id { get; set; }
public string html_url { get; set; }
public string tag_name { get; set; }
public Version version => new Version(tag_name);
public string target_commitish { get; set; }
public string created_at { get; set; }
public string published_at { get; set; }
public List<Assets> assets { get; set; }
public string body { get; set; }
}

public class Assets
{
public string id { get; set; }
public string url { get; set; }
public string name { get; set; }
public string content_type { get; set; }
public string size { get; set; }
public string download_count { get; set; }
public string updated_at { get; set; }
public string browser_download_url { get; set; }
}
}
10 changes: 8 additions & 2 deletions SteamTools/Models/Settings/GeneralSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private static void WindowsStartupAutoRun_ValueChanged(object sender, ValueChang
= new SerializableProperty<bool>(GetKey(), Providers.Roaming, true) { AutoSave = true };

/// <summary>
/// 游戏列表本地缓存
/// 启用游戏列表本地缓存
/// </summary>
public static SerializableProperty<bool> IsSteamAppListLocalCache { get; }
= new SerializableProperty<bool>(GetKey(), Providers.Roaming, true) { AutoSave = true };
Expand All @@ -55,7 +55,13 @@ private static void WindowsStartupAutoRun_ValueChanged(object sender, ValueChang
/// Steam启动参数
/// </summary>
public static SerializableProperty<string> SteamStratParameter { get; }
= new SerializableProperty<string>(GetKey(), Providers.Roaming, string.Empty) { AutoSave = true };
= new SerializableProperty<string>(GetKey(), Providers.Local, string.Empty) { AutoSave = true };

/// <summary>
/// 自动检查更新
/// </summary>
public static SerializableProperty<bool> IsAutoCheckUpdate { get; }
= new SerializableProperty<bool>(GetKey(), Providers.Roaming, true) { AutoSave = true };

private static string GetKey([CallerMemberName] string propertyName = "")
{
Expand Down
2 changes: 1 addition & 1 deletion SteamTools/Services/AuthService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void Initialize()
}
catch (Exception ex)
{
WindowService.Current.ShowDialogWindow($"令牌同步服务器失败,错误信息:{ex.Message}");
WindowService.Current.MainWindow.Dialog($"令牌同步服务器失败,错误信息:{ex.Message}");
}
}
}
Expand Down
94 changes: 94 additions & 0 deletions SteamTools/Services/AutoUpdateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using SteamTool.Core;
using SteamTool.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SteamTool.Model.ToolModel;
using SteamTools.Models;
using SteamTool.Core.Common;
using System.Net;
using System.IO;
using Livet;
using SteamTools.Properties;

namespace SteamTools.Services
{
public class AutoUpdateService : NotificationObject
{
#region static members
public static AutoUpdateService Current { get; } = new AutoUpdateService();
#endregion

private readonly HttpServices httpServices = SteamToolCore.Instance.Get<HttpServices>();

#region 更新进度变更通知
private double _ProgressValue;
public double ProgressValue
{
get => this._ProgressValue;
set
{
if (this._ProgressValue != value)
{
this._ProgressValue = value;
this.RaisePropertyChanged();
}
}
}
#endregion

public async void CheckUpdate()
{
try
{
StatusService.Current.Notify("正在从Github检查更新...");
var result = await httpServices.Get(Const.GITHUB_RELEASEAPI_URL);
var model = JsonConvert.DeserializeObject<GithubReleaseModel>(result);
if (ProductInfo.Version > model.version)
{
if (WindowService.Current.MainWindow.Dialog($"检测到新版本更新内容:{model.body}\r\n是否立即更新?", $"{ProductInfo.Title} | 更新提示") == true)
{
//var name = model.assets.FirstOrDefault()?.name;
var name = Path.Combine(AppContext.BaseDirectory, @$"{ProductInfo.Title} {model.version}.zip");
if (File.Exists(name))
{
StatusService.Current.Notify("更新文件已经存在,不需要下载");
return;
}
var fileReq = WebRequest.Create(model.assets.FirstOrDefault()?.browser_download_url);
await fileReq?.GetResponseAsync().ContinueWith(s =>
{
long totalBytes = s.Result.ContentLength;
using Stream responseStream = s.Result.GetResponseStream();
using FileStream fileStream = new FileStream(name, FileMode.Create, FileAccess.Write);
long totalDownloadBytes = 0;
byte[] bs = new byte[4096];
int size = responseStream.Read(bs, 0, bs.Length);
while (size > 0)
{
totalDownloadBytes += size;
fileStream.Write(bs, 0, size);
ProgressValue = ((double)totalDownloadBytes / (double)totalBytes);
StatusService.Current.Set($"下载更新{ProgressValue.ToString("P")}");
size = responseStream.Read(bs, 0, bs.Length);
}
fileStream.Flush();
fileStream.Close();
StatusService.Current.Set(Resources.Ready);
StatusService.Current.Notify($"{ProductInfo.Title} {model.version}版本已经下载到程序根目录下,暂时请手动替换更新");
});
}
}
}
catch (Exception ex)
{
Logger.Error("更新出错:", ex);
WindowService.Current.MainWindow.Dialog($"更新出错:{ex.Message}");
}

}
}
}
4 changes: 3 additions & 1 deletion SteamTools/Services/SteamConnectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public void Initialize()
var id = ApiService.GetSteamId64();
if (id == 76561197960265728)
{
//该64位id的steamID3等于0,是steam未获取到当前登录用户的默认返回值,所以直接重新获取
//该64位id的steamID3等于0,是steam未获取到当前登录用户的默认返回值,所以直接重新获取,
//希望这位用户不会用steam++,嗯...
ApiService.SteamClient.Dispose();
continue;
}
IsConnectToSteam = true;
Expand Down
7 changes: 4 additions & 3 deletions SteamTools/Services/WindowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public Window GetMainWindow()
throw new InvalidOperationException();
}

public bool? ShowDialogWindow(string content)
public bool ShowDialogWindow(string content)
{
return ShowDialogWindow(content, ProductInfo.Title);
}

public bool? ShowDialogWindow(string content, string title)
public bool ShowDialogWindow(string content, string title)
{
var dialog = new DialogWindowViewModel
{
Expand All @@ -69,7 +69,8 @@ public Window GetMainWindow()
};
var window = new MessageDialog { DataContext = dialog };
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
return window.ShowDialog();
window.ShowDialog();
return dialog.DialogResult;
}

#region disposable members
Expand Down
4 changes: 3 additions & 1 deletion SteamTools/SteamTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@

<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>

<Description>Steam++</Description>
<Description>Steam++」是一个包含多种Steam工具功能的工具箱。</Description>

<Platforms>AnyCPU;x86</Platforms>

<Product>SteamTools</Product>

<PackageId />

<Version>1.0.2</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net472|AnyCPU'">
Expand Down
11 changes: 9 additions & 2 deletions SteamTools/ViewModels/Content/AboutDonateListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using SteamTools.Properties;
using SteamTool.Model;
using Newtonsoft.Json;
using System.Threading;

namespace SteamTools.ViewModels
{
Expand Down Expand Up @@ -50,9 +51,15 @@ public List<DonateRecord> DonateRecordList

public AboutDonateListViewModel()
{
httpServices.Get(Const.REWARDMELIST_URL).ContinueWith(s =>
Task.Run(() =>
{
DonateRecordList = JsonConvert.DeserializeObject<List<DonateRecord>>(s.Result);
httpServices.Get(Const.REWARDMELIST_URL).ContinueWith(s =>
{
if (!string.IsNullOrEmpty(s.Result))
{
DonateRecordList = JsonConvert.DeserializeObject<List<DonateRecord>>(s.Result);
}
});
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public void RefreshGameListCache()
StatusService.Current.Notify("未检测到Steam运行");
}
}

public void CheckUpdate_Click()
{
AutoUpdateService.Current.CheckUpdate();
}
}
}
5 changes: 5 additions & 0 deletions SteamTools/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using SteamTools.Properties;
using MetroRadiance.Interop.Win32;
using SteamTool.Core.Common;
using SteamTools.Models.Settings;

namespace SteamTools.ViewModels
{
Expand Down Expand Up @@ -135,6 +136,10 @@ await Task.Run(() =>
}).ContinueWith(s => { Logger.Error(s.Exception); WindowService.Current.ShowDialogWindow(s.Exception.Message); }, TaskContinuationOptions.OnlyOnFaulted)
.ContinueWith(s => s.Dispose());
AuthService.Current.Initialize();
if (GeneralSettings.IsAutoCheckUpdate)
{
AutoUpdateService.Current.CheckUpdate();
}
StatusService.Current.Set(Resources.Ready);
this.IsInitialized = true;
}
Expand Down
14 changes: 8 additions & 6 deletions SteamTools/Views/Content/About/AboutDonateList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
<ItemsControl ItemsSource="{Binding DonateRecordList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="15,0,0,0"></TextBlock>
<TextBlock Text="{Binding Amount}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="15,0,0,0"></TextBlock>
<TextBlock Text="{Binding Remark}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="15,0,0,0"></TextBlock>
<TextBlock Text="{Binding PayTime}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="15,0,0,0"></TextBlock>
</StackPanel>
<DockPanel Margin="8">
<WrapPanel VerticalAlignment="Center">
<TextBlock Text="{Binding Name}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="30,0,0,0"></TextBlock>
<TextBlock Text="{Binding Amount,StringFormat={}{0:F2}元}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="30,0,0,0"></TextBlock>
<TextBlock Text="{Binding Remark}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="30,0,0,0"></TextBlock>
</WrapPanel>
<TextBlock Text="{Binding PayTime,StringFormat='{}{0:yyyy年MM月dd日}',ConverterCulture=zh-CN}" Foreground="{StaticResource ActiveForegroundBrushKey}" Margin="10" HorizontalAlignment="Right"></TextBlock>
</DockPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
14 changes: 14 additions & 0 deletions SteamTools/Views/Content/About/AboutUpdateHistory.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@
FontFamily="Meiryo UI"
TextAlignment="Left"
MaxPageWidth="900">
<Paragraph Language="zh-cn">
<Run Text="Steam++ v1.0.2" FontSize="16"/>
<Run Text="&#160;"/>
<Run Text="2020-12-14" FontSize="10" />
<LineBreak />
<Run Text="&#160;&#160;&#160;&#160;"/>
<Run Text="添加了" />
<LineBreak/>
<Run Text="&#160;&#160;&#160;&#160;"/>
<Run Text="主要功能:社区反代,帐户切换,成就解锁,本地令牌。"></Run>
<LineBreak/>
<Run Text="&#160;&#160;&#160;&#160;"/>
<Run Text="次要功能:强制无边框窗口化以及CSGO VAC屏蔽修复。"></Run>
</Paragraph>
<Paragraph Language="zh-cn">
<Run Text="Steam++ v1.0.0" FontSize="16"/>
<Run Text="&#160;"/>
Expand Down
24 changes: 22 additions & 2 deletions SteamTools/Views/Content/Settings/SettingsGeneral.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
IsChecked="{Binding Source={x:Static ms:GeneralSettings.WindowsStartupAutoRun}, Path=Value, Mode=TwoWay}">
<TextBlock Text="开机自启动"></TextBlock>
</CheckBox>

<Separator Opacity="0" Height="10"/>
<WrapPanel>
<CheckBox
HorizontalAlignment="Left"
Expand All @@ -59,8 +61,26 @@
<Run Text="*此设置不影响开机自启动时最小化"></Run>
</TextBlock>
</WrapPanel>



<Separator Opacity="0" Height="10"/>
<CheckBox
HorizontalAlignment="Left"
IsChecked="{Binding Source={x:Static ms:GeneralSettings.IsAutoCheckUpdate}, Path=Value, Mode=TwoWay}">
<TextBlock Text="启动时自动检查更新"></TextBlock>
</CheckBox>

<Separator Opacity="0" Height="10"/>
<WrapPanel>
<metro2:CallMethodButton Content="检查更新"
Width="80"
Height="30"
HorizontalAlignment="Left"
MethodName="CheckUpdate_Click"
MethodTarget="{Binding}"/>
<TextBlock Style="{StaticResource DetailTextStyleKey}" Margin="10,0,0,0">
<Run Text="手动检查更新"></Run>
</TextBlock>
</WrapPanel>
<!--<Separator Opacity="0" Height="10"/>-->

<Border Height="1"
Expand Down
6 changes: 5 additions & 1 deletion SteamTools/Views/Pages/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
<TextBlock Text="{Binding Resources.About_DonateList,Source={x:Static services:ResourceService.Current}, Mode=OneWay}"
Style="{StaticResource TabHeaderTextStyleKey}" />
</TabItem.Header>
<contents:AboutDonateList></contents:AboutDonateList>
<contents:AboutDonateList>
<contents:AboutDonateList.DataContext>
<viewModel:AboutDonateListViewModel></viewModel:AboutDonateListViewModel>
</contents:AboutDonateList.DataContext>
</contents:AboutDonateList>
</TabItem>

<TabItem>
Expand Down
8 changes: 5 additions & 3 deletions release-keylol.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Steam++只在keylol论坛与github发布,为了账号安全,请不要到其
已经收到了B叔制作的图标,下个版本可以换上更好看的图标了。

# Steam++工具箱

## 已知的未修复问题
> 目前已知坛友反馈的严重BUG问题
* steam++启动后运行steam在运行steam的部分游戏会使游戏掉帧,gpu利用率很低,这个问题在作者的电脑上确实无法复现,所以暂时只能请各位在遇到此问题时手动关闭steam++,带来不便请谅解,抱歉。

## 工具介绍
`Steam++`是一个包含多种Steam工具功能的工具箱,开源发布于[Github](https://github.com/rmbadmin/SteamTools),如果您对发布的二进制文件不放心,可以自行下载源码编译运行。
此工具的大部分功能都是需要您下载安装Steam才能使用。
工具预计将整合进大部分常用的Steam相关工具,并且尽力做到比原工具更好用,在各种整合添加功能的同时,也会注意体积尽量的控制到最小。
Expand Down Expand Up @@ -81,8 +85,6 @@ Steam++只在keylol论坛与github发布,为了账号安全,请不要到其

> 程序使用C# WPF在 .NET Framework4.7.2环境下开发,如果无法运行请下载安装[.NET Framework 4.7.2](https://dotnet.microsoft.com/download/dotnet-framework/net472)
## 已知的未修复问题
*

## 下载

Expand Down

0 comments on commit 0b88de7

Please sign in to comment.