AvalonEdit

This commit is contained in:
rmbgame
2021-07-02 10:16:51 +08:00
parent fe000c95b6
commit cd39edeefd
14 changed files with 166 additions and 426 deletions
+1 -1
View File
@@ -22,7 +22,7 @@
<StyleInclude Source="avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Styles/ThemeAccent.xaml" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
<StyleInclude Source="avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Styles/Controls.xaml" />
<!--<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml"/>-->
<StyleInclude Source="avares://AvaloniaEdit/AvaloniaEdit.xaml"/>
<Style Selector="Window">
<Setter Property="Icon" Value="avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Assets/Icon.ico"/>
</Style>
@@ -173,7 +173,7 @@ namespace System.Application.UI
compositeDisposable.Add(ProxyService.Current.Dispose);
compositeDisposable.Add(AuthService.Current.SaveEditNameAuthenticators);
compositeDisposable.Add(SteamConnectService.Current.Dispose);
compositeDisposable.Add(IASFService.Instance.StopArchiSteamFarm);
compositeDisposable.Add(IArchiSteamFarmService.Instance.Stop);
if (GeneralSettings.IsStartupAppMinimized.Value)
{
Program.IsMinimize = true;
@@ -11,9 +11,7 @@
</Border>
</Design.PreviewWith>
<Styles.Resources>
</Styles.Resources>
<Styles.Resources>
<FontFamily x:Key="UnicodeFont">avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Assets/Fonts#WenQuanYi Micro Hei</FontFamily>
<Thickness x:Key="TextControlBorderThemeThickness">0,0,0,2</Thickness>
<Thickness x:Key="TextControlBorderThemeThicknessFocused">0,0,0,2</Thickness>
<Thickness x:Key="TextControlThemePadding">15,10,15,8</Thickness>
@@ -83,7 +81,7 @@
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<TextPresenter Name="PART_TextPresenter"
FontFamily="avares://System.Application.SteamTools.Client.Desktop.Avalonia/Application/UI/Assets/Fonts#WenQuanYi Micro Hei"
FontFamily="{StaticResource UnicodeFont}"
Text="{TemplateBinding Text, Mode=TwoWay}"
CaretIndex="{TemplateBinding CaretIndex}"
SelectionStart="{TemplateBinding SelectionStart}"
@@ -5,6 +5,7 @@
xmlns:resx="clr-namespace:System.Application.UI.Resx;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:service="clr-namespace:System.Application.Services;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:ms="using:System.Application.Models.Settings"
xmlns:AvalonEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="using:System.Application.UI.Views.Pages"
@@ -18,33 +19,40 @@
<TabControl TabStripPlacement="Left">
<TabItem Header="ASF控制台">
<Panel>
<StackPanel Spacing="20" IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=!IsArchiSteamFarmRuning}"
<!--<StackPanel Spacing="20"
VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Center">
<Ellipse Height="6" Width="6" Fill="#FF4F58" Margin="0 0 5 0" VerticalAlignment="Center"/>
<!--<Ellipse Height="6" Width="6" Fill="#47A42B" Margin="0 0 5 0" VerticalAlignment="Center" />-->
-->
<!--<Ellipse Height="6" Width="6" Fill="#47A42B" Margin="0 0 5 0" VerticalAlignment="Center" />-->
<!--
<TextBlock Text="ArchiSteamFarm 未运行" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<Button Content="启动ASF" Width="200"
Classes="action" Command="{ReflectionBinding RunOrStopASF}"
HorizontalAlignment="Center"/>
</StackPanel>
</StackPanel>-->
<Grid IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=IsArchiSteamFarmRuning}"
RowDefinitions="*,Auto">
<TextBox x:Name="console" IsReadOnly="True" AcceptsReturn="True" TextWrapping="Wrap" Text="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=ArchiSteamFarmOutText}"/>
<TextBox x:Name="CommandTextbox" Grid.Row="1" Watermark="输入指令后按下Enter执行"/>
</Grid>
</Panel>
<AvalonEdit:TextEditor Name="Editor"
FontFamily="{StaticResource UnicodeFont}"
Background="Black"
Foreground="{DynamicResource HighlightForegroundBrushKey}"
SyntaxHighlighting="PowerShell"
WordWrap="true"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Visible" />
<!--<TextBox x:Name="console" IsReadOnly="True" AcceptsReturn="True" TextWrapping="Wrap" Text="{ReflectionBinding Source={x:Static service:ASFService.Current},Path=CommandText}"/>
<TextBox x:Name="CommandTextbox" Grid.Row="1" Watermark="输入指令后按下Enter执行"/>-->
</TabItem>
<TabItem Header="ASF Web UI">
<Panel>
<StackPanel Spacing="20" IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=!IsArchiSteamFarmRuning}"
<StackPanel Spacing="20" IsVisible="{ReflectionBinding Source={x:Static service:ASFService.Current},Path=!IsArchiSteamFarmRuning}"
VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" Spacing="8" HorizontalAlignment="Center">
<Ellipse Height="6" Width="6" Fill="#FF4F58" Margin="0 0 5 0" VerticalAlignment="Center"/>
<!--<Ellipse Height="6" Width="6" Fill="#47A42B" Margin="0 0 5 0" VerticalAlignment="Center" />-->
<Ellipse Height="6" Width="6" Fill="#47A42B" Margin="0 0 5 0" VerticalAlignment="Center" />
<TextBlock Text="ArchiSteamFarm 未运行" VerticalAlignment="Center"></TextBlock>
</StackPanel>
<Button Content="启动ASF" Width="200"
@@ -52,7 +60,7 @@
HorizontalAlignment="Center"/>
</StackPanel>
<controls:WebView3 Url="{Binding WebUrl}" IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=IsArchiSteamFarmRuning}"/>
<!--<controls:WebView3 Url="{Binding WebUrl}" IsVisible="{ReflectionBinding Source={x:Static service:ASFService.Current},Path=IsArchiSteamFarmRuning}"/>-->
</Panel>
</TabItem>
@@ -89,9 +97,8 @@
<WrapPanel>
<TextBlock Text="ASF可执行文件路径:"/>
<controls:ScrollingTextBlock x:Name="asfPath" Text="{ReflectionBinding Source={x:Static ms:ASFSettings.ArchiSteamFarmExePath},Path=Value,Mode=OneWay}" DockPanel.Dock="Right" IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=IsArchiSteamFarmExists,Mode=OneWay}"/>
<controls:ScrollingTextBlock Text="{ReflectionBinding Path=Res.ASF_ExeNoExists,Source={x:Static resx:R.Current},Mode=OneWay}"
IsVisible="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=!IsArchiSteamFarmExists,Mode=OneWay}"/>
<controls:ScrollingTextBlock x:Name="asfPath" Text="{ReflectionBinding Source={x:Static ms:ASFSettings.ArchiSteamFarmExePath},Path=Value,Mode=OneWay}" DockPanel.Dock="Right"/>
<controls:ScrollingTextBlock Text="{ReflectionBinding Path=Res.ASF_ExeNoExists,Source={x:Static resx:R.Current},Mode=OneWay}"/>
<!--<i:Interaction.Behaviors>
<ia:DataTriggerBehavior Binding="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=IsArchiSteamFarmExists,Mode=OneWay}" ComparisonCondition="Equal" Value="True">
<ia:ChangePropertyAction TargetObject="{ReflectionBinding #asfPath}" PropertyName="Text" Value="{ReflectionBinding Source={x:Static ms:ASFSettings.ArchiSteamFarmExePath},Path=Value,Mode=OneWay}"/>
@@ -110,7 +117,7 @@
<StackPanel Spacing="10">
<WrapPanel>
<TextBlock Text="当前 ArchiSteamFarm 版本 : " VerticalAlignment="Center"></TextBlock>
<TextBlock Text="{ReflectionBinding Source={x:Static service:IASFService.Instance},Path=ArchiSteamFarmVersion}" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="" VerticalAlignment="Center"></TextBlock>
</WrapPanel>
<!--<TextBlock Text="最新 ArchiSteamFarm 版本 : " VerticalAlignment="Center"></TextBlock>
<TextBlock Text="{ReflectionBinding Source={x:Static ms:ASFSettings.ArchiSteamFarmExePath},Path=Value,Mode=OneWay}" VerticalAlignment="Center"></TextBlock>-->
@@ -6,56 +6,68 @@ using System.Collections.Generic;
using System.Properties;
using System.Application.Services;
using System.IO;
using AvaloniaEdit;
using AvaloniaEdit.Highlighting;
namespace System.Application.UI.Views.Pages
{
public class ArchiSteamFarmPlusPage : ReactiveUserControl<ArchiSteamFarmPlusPageViewModel>
{
readonly TextBox commandTextbox;
private readonly TextEditor _textEditor;
public ArchiSteamFarmPlusPage()
{
InitializeComponent();
var selectAsfPath = this.FindControl<Button>("selectAsfPath");
selectAsfPath.Click += SelectAsfPath_Click;
commandTextbox = this.FindControl<TextBox>("CommandTextbox");
commandTextbox.KeyUp += CommandTextbox_KeyUp;
//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;
}
_textEditor = this.FindControl<TextEditor>("Editor");
//_textEditor.ShowLineNumbers = true;
private void CommandTextbox_KeyUp(object? sender, Avalonia.Input.KeyEventArgs e)
{
if (e.Key == Avalonia.Input.Key.Enter && !string.IsNullOrEmpty(commandTextbox.Text))
IArchiSteamFarmService.Instance.GetConsoleWirteFunc = (message) =>
{
IASFService.Instance.WirteLineCommand(commandTextbox.Text);
commandTextbox.Text = "";
}
_textEditor.AppendText(message += Environment.NewLine);
};
//_textEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition("PowerShell");
//_textEditor.TextArea.TextEntered += textEditor_TextArea_TextEntered;
//_textEditor.TextArea.TextEntering += textEditor_TextArea_TextEntering;
//_textEditor.TextArea.IndentationStrategy = new AvaloniaEdit.Indentation.CSharp.CSharpIndentationStrategy();
}
//private void CommandTextbox_KeyUp(object? sender, Avalonia.Input.KeyEventArgs e)
//{
// if (e.Key == Avalonia.Input.Key.Enter && !string.IsNullOrEmpty(commandTextbox.Text))
// {
// IArchiSteamFarmService.Instance.ExecuteCommand(commandTextbox.Text);
// commandTextbox.Text = "";
// }
//}
private async void SelectAsfPath_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var fileDialog = new OpenFileDialog
{
Filters = new List<FileDialogFilter> {
new FileDialogFilter { Name = "Exe Files", Extensions = new List<string> { "exe" } },
new FileDialogFilter { Name = "All Files", Extensions = new List<string> { "*" } },
},
Title = ThisAssembly.AssemblyTrademark,
AllowMultiple = false,
};
//var fileDialog = new OpenFileDialog
//{
// Filters = new List<FileDialogFilter> {
// new FileDialogFilter { Name = "Exe Files", Extensions = new List<string> { "exe" } },
// new FileDialogFilter { Name = "All Files", Extensions = new List<string> { "*" } },
// },
// Title = ThisAssembly.AssemblyTrademark,
// AllowMultiple = false,
//};
if (IASFService.Instance.IsArchiSteamFarmExists)
{
fileDialog.Directory = Path.GetDirectoryName(IASFService.Instance.ArchiSteamFarmExePath);
}
//if (IASFService.Instance.IsArchiSteamFarmExists)
//{
// fileDialog.Directory = Path.GetDirectoryName(IASFService.Instance.ArchiSteamFarmExePath);
//}
var result = await fileDialog.ShowAsync(IDesktopAvaloniaAppService.Instance.MainWindow);
if (result.Any_Nullable())
{
IASFService.Instance.SetArchiSteamFarmExePath(result[0]);
}
//var result = await fileDialog.ShowAsync(IDesktopAvaloniaAppService.Instance.MainWindow);
//if (result.Any_Nullable())
//{
// IASFService.Instance.SetArchiSteamFarmExePath(result[0]);
//}
}
private void InitializeComponent()
@@ -4,6 +4,7 @@
xmlns:resx="clr-namespace:System.Application.UI.Resx;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:service="clr-namespace:System.Application.Services;assembly=System.Application.SteamTools.Client.Desktop"
xmlns:controls="clr-namespace:System.Application.UI.Views.Controls;assembly=System.Application.SteamTools.Client.Desktop.Avalonia"
xmlns:AvalonEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
@@ -11,6 +12,16 @@
x:Class="System.Application.UI.Views.Pages.DebugPage">
<Grid RowDefinitions="*,Auto">
<TextBox Grid.Row="0" Text="{Binding DebugString}" AcceptsReturn="True" />
<!--<AvalonEdit:TextEditor
FontFamily="Cascadia Code"
Background="Transparent"
Margin="30"
Foreground="White"
SyntaxHighlighting="PowerShell"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Visible"
FontWeight="Light"
FontSize="18" />-->
<StackPanel Grid.Row="1" Orientation="Horizontal">
<Button Height="35" MinWidth="200" Content="Debug Button"
Command="{Binding DebugButton_Click}" />
@@ -22,4 +33,4 @@
Command="{Binding TestFontsButton_Click}" />
</StackPanel>
</Grid>
</UserControl>
</UserControl>
@@ -110,16 +110,5 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddSingleton<IWindowService, WindowServiceImpl>();
return services;
}
/// <summary>
/// 添加 asf 功能
/// </summary>
/// <param name="services"></param>
/// <returns></returns>
public static IServiceCollection AddASFService(this IServiceCollection services)
{
services.AddSingleton<IASFService, ASFServiceImpl>();
return services;
}
}
}
@@ -1,35 +0,0 @@
using ReactiveUI;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace System.Application.Services
{
public interface IASFService
{
public static IASFService Instance => DI.Get<IASFService>();
public string? ArchiSteamFarmExePath { get; }
public string? ArchiSteamFarmConfigDirPath { get; }
public string? ArchiSteamFarmOutText { get; }
public string? IPCUrl { get; }
public Process? Process { get; }
public bool IsArchiSteamFarmExists { get; }
public bool IsArchiSteamFarmRuning { get; }
void SetArchiSteamFarmExePath(string path);
bool RunArchiSteamFarm();
void StopArchiSteamFarm();
void WirteLineCommand(string command, bool useipc = false);
void SetArchiSteamFarmConfig();
void AddBot();
}
}
@@ -1,319 +0,0 @@
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.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace System.Application.Services.Implementation
{
internal sealed class ASFServiceImpl : ReactiveObject, IASFService
{
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
{
get => _ArchiSteamFarmExePath;
private set => this.RaiseAndSetIfChanged(ref _ArchiSteamFarmExePath, value);
}
public string? ArchiSteamFarmConfigDirPath => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? Path.GetDirectoryName(ArchiSteamFarmExePath) : null;
public Version? ArchiSteamFarmVersion => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? new Version(FileVersionInfo.GetVersionInfo(ArchiSteamFarmExePath).ProductVersion) : null;
string? _ArchiSteamFarmOutText;
public string? ArchiSteamFarmOutText
{
get => _ArchiSteamFarmOutText;
private set => this.RaiseAndSetIfChanged(ref _ArchiSteamFarmOutText, value);
}
Process? _Process;
public Process? Process
{
get => _Process;
private set => this.RaiseAndSetIfChanged(ref _Process, value);
}
public bool IsArchiSteamFarmExists => !string.IsNullOrEmpty(ArchiSteamFarmExePath) ? File.Exists(ArchiSteamFarmExePath) : false;
public bool IsArchiSteamFarmRuning => !Process?.HasExited ?? false;
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 ASFServiceImpl(IDesktopPlatformService platform, IHttpService http, ICloudServiceClient client)
{
clientService = client;
platformService = platform;
httpService = http;
ArchiSteamFarmExePath = ASFSettings.ArchiSteamFarmExePath.Value;
if (string.IsNullOrEmpty(ArchiSteamFarmExePath))
{
var temp = Path.Combine(IOPath.BaseDirectory, "ASF", "ArchiSteamFarm.exe");
SetArchiSteamFarmExePath(temp);
}
if (IsArchiSteamFarmExists)
{
//IPC默认地址
IPCUrl = "http://127.0.0.1:1242";
}
this.WhenAnyValue(x => x.ArchiSteamFarmExePath)
.Subscribe(_ =>
{
this.RaisePropertyChanged(nameof(IsArchiSteamFarmExists));
this.RaisePropertyChanged(nameof(ArchiSteamFarmVersion));
this.RaisePropertyChanged(nameof(ArchiSteamFarmConfigDirPath));
});
}
public void SetArchiSteamFarmExePath(string path)
{
if (File.Exists(path) && Path.GetExtension(path).Equals(".exe", StringComparison.OrdinalIgnoreCase))
{
ArchiSteamFarmExePath = path;
ASFSettings.ArchiSteamFarmExePath.Value = path;
}
}
public bool RunArchiSteamFarm()
{
try
{
if (!IsArchiSteamFarmRuning)
{
if (IsArchiSteamFarmExists)
{
Task.Run(() =>
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Process = new Process();
Process.StartInfo.FileName = ArchiSteamFarmExePath;//要执行的程序名称
Process.StartInfo.UseShellExecute = false;
Process.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(R.Culture.TextInfo.ANSICodePage);
Process.StartInfo.StandardInputEncoding = Process.StartInfo.StandardOutputEncoding;
Process.StartInfo.StandardErrorEncoding = Process.StartInfo.StandardOutputEncoding;
Process.StartInfo.RedirectStandardInput = true;
Process.StartInfo.RedirectStandardOutput = true;
Process.StartInfo.RedirectStandardError = true;
Process.StartInfo.CreateNoWindow = true;//不显示程序窗口
Process.Start();//启动程序
Process.StandardInput.AutoFlush = true;
//Process.StartInfo.Verb = "runas";
this.RaisePropertyChanged(nameof(IsArchiSteamFarmRuning));
using StreamReader standardOutput = Process.StandardOutput;
//Process.StandardInput.WriteLine();
while (!standardOutput.EndOfStream)
{
string? text = standardOutput.ReadLine();
#if DEBUG
Debug.WriteLine(text);
#endif
ArchiSteamFarmOutText += (text + Environment.NewLine);
}
Process.Close();
standardOutput.Close();
}).Forget();
}
else
{
Toast.Show(AppResources.ASF_ExeNoExists);
}
}
else
{
Toast.Show(AppResources.ASF_RuningTip);
}
}
catch (Exception ex)
{
Log.Error(nameof(IArchiSteamFarmService), ex, nameof(RunArchiSteamFarm));
}
return IsArchiSteamFarmRuning;
}
public void WirteLineCommand(string command, bool useipc = false)
{
if (IsArchiSteamFarmRuning && !string.IsNullOrEmpty(command))
{
Process!.StandardInput.WriteLine(command);
//Process!.StandardInput.Flush();
}
}
private async void IPCCommand(string command)
{
if (IsArchiSteamFarmRuning && !string.IsNullOrEmpty(command))
{
}
}
public void StopArchiSteamFarm()
{
if (IsArchiSteamFarmRuning)
{
Process?.Kill();
}
}
public void SetArchiSteamFarmConfig()
{
}
public void AddBot()
{
}
public void GetAllBots()
{
if (IsArchiSteamFarmExists && IsArchiSteamFarmRuning)
{
var botNames = Directory.EnumerateFiles(ArchiSteamFarmConfigDirPath!, "*" + ".json").Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName));
}
}
public void SaveBotConfig()
{
}
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
{
return;
}
}
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;
}
}
}
@@ -0,0 +1,31 @@
using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System.Application.Services
{
public class ASFService : ReactiveObject
{
#region static members
public static ASFService Current { get; } = new();
#endregion
bool _IPCUrl;
public bool IPCUrl
{
get => _IPCUrl;
set => this.RaiseAndSetIfChanged(ref _IPCUrl, value);
}
string? _CommandText;
public string? CommandText
{
get => _CommandText;
set => this.RaiseAndSetIfChanged(ref _CommandText, value);
}
}
}
@@ -6,7 +6,7 @@ namespace System.Application.UI.ViewModels
{
public class ArchiSteamFarmPlusPageViewModel : TabItemViewModel
{
readonly IASFService asfSerivce = DI.Get<IASFService>();
readonly IArchiSteamFarmService asfSerivce = DI.Get<IArchiSteamFarmService>();
public override string Name
{
get => AppResources.ArchiSteamFarmPlus;
@@ -18,7 +18,7 @@ namespace System.Application.UI.ViewModels
IconKey = nameof(ArchiSteamFarmPlusPageViewModel).Replace("ViewModel", "Svg");
}
public string? WebUrl => asfSerivce.IPCUrl;
public string? WebUrl => asfSerivce.GetIPCUrl();
private string? _CommandString;
public string? CommandString
@@ -12,16 +12,26 @@ namespace System.Application.Services
static Action? InitCoreLoggers { protected get; set; }
Action<string>? GetConsoleWirteFunc { get; set; }
/// <summary>
/// 启动ASF
/// </summary>
/// <param name="args"></param>
void Start(string[]? args = null);
void Stop();
/// <summary>
/// 执行asf指令
/// </summary>
/// <param name="command"></param>
Task<string?> ExecuteCommand(string command);
/// <summary>
/// 获取IPC地址
/// </summary>
/// <returns></returns>
string GetIPCUrl();
}
}
@@ -8,6 +8,10 @@ using ArchiSteamFarm.Storage;
using ArchiSteamFarm.NLog.Targets;
using ArchiSteamFarm.Steam;
using NLog;
using System.IO;
using ArchiSteamFarm;
using Microsoft.Extensions.Configuration;
using System.Net;
namespace System.Application.Services.Implementation
{
@@ -29,6 +33,11 @@ namespace System.Application.Services.Implementation
}
}
public async void Stop()
{
await ArchiSteamFarm.Program.InitShutdownSequence().ConfigureAwait(false);
}
private void InitHistoryLogger()
{
ArchiSteamFarm.NLog.Logging.InitHistoryLogger();
@@ -89,6 +98,36 @@ namespace System.Application.Services.Implementation
return ASF.GlobalConfig;
}
public string GetIPCUrl()
{
string absoluteConfigDirectory = Path.Combine(ASFPathHelper.AppDataDirectory, SharedInfo.ConfigDirectory);
string customConfigPath = Path.Combine(absoluteConfigDirectory, SharedInfo.IPCConfigFile);
if (File.Exists(customConfigPath))
{
var configRoot = new ConfigurationBuilder().SetBasePath(absoluteConfigDirectory).AddJsonFile(SharedInfo.IPCConfigFile, false, true).Build();
var urlSection = configRoot.GetSection("Url").Value;
try
{
var url = new Uri(urlSection);
if (IPAddress.Any.ToString() == url.Host)
{
return "http://" + IPAddress.Loopback + ":1242";
}
else
{
return url.AbsolutePath;
}
}
catch
{
return "http://" + IPAddress.Loopback + ":1242";
}
}
else
{
return "http://" + IPAddress.Loopback + ":1242";
}
}
public void SaveGlobalConfig(GlobalConfig config)
{
-3
View File
@@ -320,9 +320,6 @@ namespace System.Application
// ASF Service
services.AddArchiSteamFarmService();
// ASF Service
services.AddASFService();
#if StartupTrace
StartupTrace.Restart("DI.ConfigureDemandServices.Steam");
#endif