asf download

This commit is contained in:
rmbgame
2021-06-21 15:29:20 +08:00
parent 8ce4861846
commit 7e2b893104
12 changed files with 226 additions and 37 deletions
@@ -31,10 +31,11 @@
HorizontalAlignment="Center"/>
</StackPanel>
<StackPanel IsVisible="{ReflectionBinding Source={x:Static service:IArchiSteamFarmService.Instance},Path=IsArchiSteamFarmRuning}">
<Grid IsVisible="{ReflectionBinding Source={x:Static service:IArchiSteamFarmService.Instance},Path=IsArchiSteamFarmRuning}"
RowDefinitions="*,Auto">
<TextBox x:Name="console" IsReadOnly="True" AcceptsReturn="True" TextWrapping="Wrap" Text="{ReflectionBinding Source={x:Static service:IArchiSteamFarmService.Instance},Path=ArchiSteamFarmOutText}"/>
<TextBox Text="{Binding CommandString}"/>
</StackPanel>
<TextBox x:Name="CommandTextbox" Grid.Row="1" Watermark="输入指令后按下Enter执行"/>
</Grid>
</Panel>
</TabItem>
<TabItem Header="ASF Web UI">
@@ -10,16 +10,29 @@ namespace System.Application.UI.Views.Pages
{
public class ArchiSteamFarmPlusPage : ReactiveUserControl<ArchiSteamFarmPlusPageViewModel>
{
readonly TextBox commandTextbox;
public ArchiSteamFarmPlusPage()
{
InitializeComponent();
var selectAsfPath = this.FindControl<Button>("selectAsfPath");
selectAsfPath.Click += SelectAsfPath_Click;
commandTextbox = this.FindControl<TextBox>("CommandTextbox");
commandTextbox.KeyUp += CommandTextbox_KeyUp;
//var console = this.FindControl<TextBox>("console");
//console.SelectionStart = 999;
}
private void CommandTextbox_KeyUp(object? sender, Avalonia.Input.KeyEventArgs e)
{
if (e.Key == Avalonia.Input.Key.Enter && !string.IsNullOrEmpty(commandTextbox.Text))
{
IArchiSteamFarmService.Instance.WirteLineCommand(commandTextbox.Text);
commandTextbox.Text = "";
}
}
private async void SelectAsfPath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog
@@ -141,8 +141,8 @@
HorizontalAlignment="Stretch" IsVisible="{Binding Source={x:Static service:ProxyService.Current},Path=ProxyStatus,Mode=OneWay}">
<StackPanel Grid.Row="0" HorizontalAlignment="Center" Margin="0 10 0 0" Spacing="10">
<WrapPanel>
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_AlreadyProxy,Mode=OneWay,Source={x:Static resx:R.Current}}" FontSize="26"></TextBlock>
<TextBlock FontSize="26" Text="{Binding AccelerateTime,Source={x:Static service:ProxyService.Current},StringFormat={}{0:HH:mm:ss}}"></TextBlock>
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_AlreadyProxy,Mode=OneWay,Source={x:Static resx:R.Current}}" FontSize="26" VerticalAlignment="Center"></TextBlock>
<TextBlock FontSize="26" Text="{Binding AccelerateTime,Source={x:Static service:ProxyService.Current},StringFormat={}{0:HH:mm:ss}}" VerticalAlignment="Center"></TextBlock>
</WrapPanel>
<WrapPanel HorizontalAlignment="Center">
<TextBlock Text="{ReflectionBinding Path=Res.CommunityFix_ProxyModeTip,Mode=OneWay,Source={x:Static resx:R.Current}}" FontSize="14"/>
@@ -44,17 +44,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.999-cibuild0014488-beta" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0014488-beta" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.999-cibuild0014488-beta" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.999-cibuild0014488-beta" />
<PackageReference Include="Avalonia" Version="0.10.999-cibuild0014582-beta" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.999-cibuild0014582-beta" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="0.10.999-cibuild0014582-beta" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.999-cibuild0014582-beta" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="0.10.6" />
<PackageReference Include="CefNet.Avalonia" Version="90.6.21124.1851" />
<PackageReference Include="LibVLCSharp.Avalonia" Version="3.5.0" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Debug'">
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0014488-beta" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.999-cibuild0014582-beta" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Application.Models
{
public class ASFBot
{
}
}
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Application.Models
{
[Obsolete("use https://github.com/octokit/octokit.net")]
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 long size { get; set; }
public string download_count { get; set; }
public string updated_at { get; set; }
public string browser_download_url { get; set; }
}
}
}
@@ -11,9 +11,10 @@ namespace System.Application.Services
public static IArchiSteamFarmService Instance => DI.Get<IArchiSteamFarmService>();
public string? ArchiSteamFarmExePath { get; }
public string? ArchiSteamFarmConfigPath { get; }
public string? ArchiSteamFarmConfigDirPath { get; }
public string? ArchiSteamFarmOutText { get; }
public string? IPCUrl { get; }
public Process? Process { get; }
public bool IsArchiSteamFarmExists { get; }
@@ -21,9 +22,7 @@ namespace System.Application.Services
public bool IsArchiSteamFarmRuning { get; }
void SetArchiSteamFarmExePath(string path);
string GetArchiSteamFarmIPCUrl();
bool RunArchiSteamFarm();
void StopArchiSteamFarm();
@@ -1,8 +1,10 @@
using ReactiveUI;
using System.Application.Models;
using System.Application.Models.Settings;
using System.Application.UI.Resx;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -11,6 +13,20 @@ namespace System.Application.Services.Implementation
internal sealed class ArchiSteamFarmServiceImpl : ReactiveObject, IArchiSteamFarmService
{
readonly IDesktopPlatformService platformService;
readonly IHttpService httpService;
readonly ICloudServiceClient clientService;
const string GITHUB_LATEST_RELEASEAPI_URL = "https://api.github.com/repos/JustArchiNET/ArchiSteamFarm/releases/latest";
static string Variant => DI.Platform switch
{
Platform.Windows => "win-x64",
Platform.Linux => "linux-x64",
Platform.Apple => "osx-x64",
_ => "win-x64",
};
string? _ArchiSteamFarmExePath;
public string? ArchiSteamFarmExePath
@@ -19,9 +35,9 @@ namespace System.Application.Services.Implementation
private set => this.RaiseAndSetIfChanged(ref _ArchiSteamFarmExePath, value);
}
public string? ArchiSteamFarmConfigPath => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? Path.GetDirectoryName(ArchiSteamFarmExePath) : null;
public string? ArchiSteamFarmConfigDirPath => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? Path.GetDirectoryName(ArchiSteamFarmExePath) : null;
public string? ArchiSteamFarmVersion => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? FileVersionInfo.GetVersionInfo(ArchiSteamFarmExePath).ProductVersion : null;
public Version? ArchiSteamFarmVersion => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? new Version(FileVersionInfo.GetVersionInfo(ArchiSteamFarmExePath).ProductVersion) : null;
string? _ArchiSteamFarmOutText;
public string? ArchiSteamFarmOutText
@@ -41,9 +57,32 @@ namespace System.Application.Services.Implementation
public bool IsArchiSteamFarmRuning => !Process?.HasExited ?? false;
public ArchiSteamFarmServiceImpl(IDesktopPlatformService platform)
bool _IsNewVerison;
public bool IsNewVerison
{
get => _IsNewVerison;
private set => this.RaiseAndSetIfChanged(ref _IsNewVerison, value);
}
GithubReleaseModel? _NewVerison;
public GithubReleaseModel? NewVerison
{
get => _NewVerison;
private set => this.RaiseAndSetIfChanged(ref _NewVerison, value);
}
string? _IPCUrl;
public string? IPCUrl
{
get => _IPCUrl;
private set => this.RaiseAndSetIfChanged(ref _IPCUrl, value);
}
public ArchiSteamFarmServiceImpl(IDesktopPlatformService platform, IHttpService http, ICloudServiceClient client)
{
clientService = client;
platformService = platform;
httpService = http;
ArchiSteamFarmExePath = ASFSettings.ArchiSteamFarmExePath.Value;
if (string.IsNullOrEmpty(ArchiSteamFarmExePath))
@@ -51,6 +90,11 @@ namespace System.Application.Services.Implementation
var temp = Path.Combine(IOPath.BaseDirectory, "ASF", "ArchiSteamFarm.exe");
SetArchiSteamFarmExePath(temp);
}
if (IsArchiSteamFarmExists)
{
IPCUrl = "http://127.0.0.1:1242";
}
}
public void SetArchiSteamFarmExePath(string path)
@@ -120,12 +164,12 @@ namespace System.Application.Services.Implementation
return IsArchiSteamFarmRuning;
}
public void WirteLineCommand(string command)
public void WirteLineCommand(string command)
{
if (IsArchiSteamFarmRuning && !string.IsNullOrEmpty(command))
if (IsArchiSteamFarmRuning && !string.IsNullOrEmpty(command))
{
Process!.StandardInput.WriteLine(command);
Process!.StandardInput.Flush();
//Process!.StandardInput.Flush();
}
}
@@ -137,11 +181,6 @@ namespace System.Application.Services.Implementation
}
}
public string GetArchiSteamFarmIPCUrl()
{
return "http://127.0.0.1:1242";
}
public void SetArchiSteamFarmConfig()
{
@@ -154,7 +193,12 @@ namespace System.Application.Services.Implementation
public void GetAllBots()
{
if (IsArchiSteamFarmExists && IsArchiSteamFarmRuning)
{
var botNames = Directory.EnumerateFiles(ArchiSteamFarmConfigDirPath!, "*" + ".json").Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName));
}
}
public void SaveBotConfig()
@@ -162,10 +206,90 @@ namespace System.Application.Services.Implementation
}
public void UpdateOrDownloadASF()
protected void OnReportDownloading(float value) => OnReport(value, AppResources.Downloading.Format(MathF.Round(value, 2)));
protected void OnReport(float value, string str)
{
ProgressValue = value;
ProgressString = str;
}
float _ProgressValue;
public float ProgressValue
{
get => _ProgressValue;
private set => this.RaiseAndSetIfChanged(ref _ProgressValue, value);
}
string _ProgressString = string.Empty;
public string ProgressString
{
get => _ProgressString;
private set => this.RaiseAndSetIfChanged(ref _ProgressString, value);
}
public async void UpdateOrDownloadASF()
{
string targetFile = "ASF-" + Variant + ".zip";
GithubReleaseModel.Assets? binaryAsset = null;
if (IsArchiSteamFarmExists)
{
var releaseModel = await CheckUpdate();
if (releaseModel != null && IsNewVerison)
{
binaryAsset = releaseModel.assets.FirstOrDefault(asset => !string.IsNullOrEmpty(asset.name) && asset.name!.Equals(targetFile, StringComparison.OrdinalIgnoreCase));
}
}
else
{
var result = await httpService.GetAsync<GithubReleaseModel>(GITHUB_LATEST_RELEASEAPI_URL);
binaryAsset = result.assets.FirstOrDefault(asset => !string.IsNullOrEmpty(asset.name) && asset.name!.Equals(targetFile, StringComparison.OrdinalIgnoreCase));
}
if (binaryAsset?.browser_download_url == null)
{
Toast.Show("未获取到下载链接");
return;
}
var downloadFilePath = IOPath.CacheDirectory + Path.DirectorySeparatorChar + targetFile;
var download = await clientService.Download(true, binaryAsset?.browser_download_url, downloadFilePath, new Progress<float>(OnReportDownloading));
if (download.IsSuccess)
{
var dirPath = Path.GetDirectoryName(ArchiSteamFarmExePath);
if (string.IsNullOrEmpty(dirPath))
{
dirPath = Path.Combine(IOPath.BaseDirectory, "ASF");
}
TarGZipHelper.Unpack(downloadFilePath, dirPath);
Toast.Show("升级完成");
}
else // 下载失败,进度条填满,可能服务器崩了
{
Toast.Show("下载失败:" + binaryAsset?.browser_download_url);
}
}
public async Task<GithubReleaseModel?> CheckUpdate()
{
NewVerison = await httpService.GetAsync<GithubReleaseModel>(GITHUB_LATEST_RELEASEAPI_URL);
if (NewVerison == null)
{
return null;
}
IsNewVerison = (ArchiSteamFarmVersion >= NewVerison.version);
if (IsNewVerison)
{
Toast.Show("ASF已是最新版本");
}
else
{
Toast.Show("检测到新版本" + NewVerison.version);
}
return NewVerison;
}
}
}
+9
View File
@@ -827,6 +827,15 @@ namespace System.Application.UI.Resx {
}
}
/// <summary>
/// 查找类似 正在下载:{0}% 的本地化字符串。
/// </summary>
public static string Downloading {
get {
return ResourceManager.GetString("Downloading", resourceCulture);
}
}
/// <summary>
/// 查找类似 编辑 的本地化字符串。
/// </summary>
@@ -369,6 +369,9 @@
<data name="Download" xml:space="preserve">
<value>下载</value>
</data>
<data name="Downloading" xml:space="preserve">
<value>正在下载:{0}%</value>
</data>
<data name="Download_ScriptError" xml:space="preserve">
<value>脚本下载错误请重试。</value>
</data>
@@ -16,16 +16,9 @@ namespace System.Application.UI.ViewModels
public ArchiSteamFarmPlusPageViewModel()
{
IconKey = nameof(ArchiSteamFarmPlusPageViewModel).Replace("ViewModel", "Svg");
WebUrl = asfSerivce.GetArchiSteamFarmIPCUrl();
}
private string? _WebUrl;
public string? WebUrl
{
get => _WebUrl;
set => this.RaiseAndSetIfChanged(ref _WebUrl, value);
}
public string? WebUrl => asfSerivce.IPCUrl;
private string? _CommandString;
public string? CommandString
@@ -418,10 +418,10 @@ namespace System.Application.Services.Implementation
return false;
}
}
else
{
SetupCertificate();
}
//else
//{
// SetupCertificate();
//}
if (IsProxyGOG) { WirtePemCertificateToGoGSteamPlugins(); }