返回提交历史
Added
XFEToolBox.Core/Downloads/SoftwareCatalogContracts.cs
+46
-0
Modified
XFEToolBox.Server/Profiles/Data/MainDataProfile.cs
+10
-1
Modified
XFEToolBox.Server/Program.cs
+73
-0
Added
XFEToolBox.Server/Services/SoftwareCatalogService.cs
+67
-0
Deleted
XFEToolBox/Resources/Resource/DownloadInfoResource.Designer.cs
+0
-99
Deleted
XFEToolBox/Resources/Resource/DownloadInfoResource.resx
+0
-132
Modified
XFEToolBox/Utilities/Server/ToolBoxRequestService.cs
+12
-0
Modified
XFEToolBox/ViewModel/Pages/DownloadInfoPageViewModel.cs
+271
-8
Deleted
XFEToolBox/ViewModel/Pages/DownloadPageViewModel.cs
+0
-61
Added
XFEToolBox/ViewModel/Pages/SoftwareCardViewModel.cs
+21
-0
Modified
XFEToolBox/Views/Pages/Admin/ServerOverviewPage.xaml
+3
-7
Modified
XFEToolBox/Views/Pages/Admin/ToolManagementPage.xaml
+5
-6
Modified
XFEToolBox/Views/Pages/Admin/UserManagementPage.xaml
+9
-10
Modified
XFEToolBox/Views/Pages/DownloadInfoPage.xaml
+88
-59
Modified
XFEToolBox/Views/Pages/DownloadInfoPage.xaml.cs
+24
-52
Modified
XFEToolBox/Views/Pages/DownloadPage.xaml
+188
-22
Modified
XFEToolBox/Views/Pages/DownloadPage.xaml.cs
+181
-8
Modified
XFEToolBox/Views/Pages/Popups/AgreementDialogPopupPage.xaml.cs
+1
-1
Modified
XFEToolBox/Views/Pages/ToolBoxPage.xaml
+17
-26
Modified
XFEToolBox/XFEToolBox.Client.csproj
+0
-15
Added
docs/software-catalog.md
+37
-0
XFEstudio/XFEToolBox
重构软件下载专区为服务端集中配置
实现软件下载目录服务端集中配置与接口下发,客户端移除本地资源文件,改为动态获取软件列表,支持搜索、分类筛选、图标配置等。重写下载页和详情页逻辑,优化 UI 风格与交互,统一样式。新增软件目录文档,提升灵活性和可维护性。
a1747d6
代码差异
21 个文件
+1053
-507
@@ -0,0 +1,46 @@
1
namespace XFEToolBox.Core.Downloads;
2
3
/// <summary>
4
/// 软件的获取方式。Direct 由客户端保存文件,Browser 交给官方页面继续处理。
5
/// </summary>
6
public enum SoftwareDownloadMode
7
{
8
Direct,
9
Browser
10
}
11
12
/// <summary>
13
/// 由工具箱服务器维护并下发的软件信息。
14
/// </summary>
15
public sealed class SoftwareCatalogItem
16
{
17
public string Id { get; set; } = string.Empty;
18
public string Name { get; set; } = string.Empty;
19
public string Summary { get; set; } = string.Empty;
20
public string Description { get; set; } = string.Empty;
21
public string Publisher { get; set; } = string.Empty;
22
public string Category { get; set; } = string.Empty;
23
public string Version { get; set; } = "最新版";
24
public string DownloadUrl { get; set; } = string.Empty;
25
public string WebsiteUrl { get; set; } = string.Empty;
26
27
/// <summary>可选的 HTTP(S) 或 data:image 图标地址。</summary>
28
public string IconUrl { get; set; } = string.Empty;
29
30
public string FileName { get; set; } = string.Empty;
31
32
/// <summary>可选的十六进制 SHA-256;配置后客户端会在下载完成后校验。</summary>
33
public string Sha256 { get; set; } = string.Empty;
34
35
public string Notice { get; set; } = string.Empty;
36
public string[] Tags { get; set; } = [];
37
public SoftwareDownloadMode DownloadMode { get; set; }
38
public bool Featured { get; set; }
39
public bool Enabled { get; set; } = true;
40
}
41
42
public sealed class SoftwareCatalogResponse
43
{
44
public SoftwareCatalogItem[] Items { get; set; } = [];
45
public string[] Categories { get; set; } = [];
46
}
@@ -1,11 +1,20 @@
1
1
using XFEExtension.NetCore.AutoConfig;
2
2
3
using XFEToolBox.Core.Downloads;
4
3
5
namespace XFEToolBox.Server.Profiles.Data;
4
6
5
7
public partial class MainDataProfile : XFEProfile
6
8
{
9
public MainDataProfile() => DefaultProfileOperationMode = ProfileOperationMode.Xml;
10
7
11
[ProfileProperty]
8
12
[ProfilePropertyAddGet("Current.downloadAddressList.CurrentProfile = Current")]
9
13
[ProfilePropertyAddGet("return Current.downloadAddressList")]
10
14
private ProfileList<string> downloadAddressList = [];
11
}
15
16
[ProfileProperty]
17
[ProfilePropertyAddGet("Current.softwareCatalog.CurrentProfile = Current")]
18
[ProfilePropertyAddGet("return Current.softwareCatalog")]
19
private ProfileList<SoftwareCatalogItem> softwareCatalog = [];
20
}
@@ -1,3 +1,4 @@
1
using XFEToolBox.Core.Downloads;
1
2
using XFEToolBox.Core.Models.Users;
2
3
using XFEToolBox.Server.Core.Options;
3
4
using XFEToolBox.Server.Core.Services;
@@ -9,6 +10,7 @@ using XFEExtension.NetCore.ServerInteractive.Utilities.Extensions;
9
10
using XFEExtension.NetCore.ServerInteractive.Utilities.Server;
10
11
11
12
EnsureInitialAdministrator();
13
EnsureInitialSoftwareCatalog();
12
14
AppDomain.CurrentDomain.ProcessExit += (_, _) => SaveProfiles();
13
15
14
16
var validationOptions = new ToolPackageValidationOptions
@@ -35,6 +37,7 @@ var server = XFEServerBuilder.CreateBuilder()
35
37
.AddParameter("AdminApiKey", adminApiKey)
36
38
.AddParameter("MaxPackageBytes", validationOptions.MaxPackageBytes)
37
39
.AddService<HealthService>()
40
.AddService<SoftwareCatalogService>()
38
41
.AddService<ToolCatalogService>()
39
42
.AddService<ToolAdminService>()
40
43
.AddService<UserProfileService>()
@@ -94,8 +97,78 @@ static void EnsureInitialAdministrator()
94
97
Console.WriteLine("[安全提示] 当前使用初始密码 ChangeMe_123!,请登录后立即修改。");
95
98
}
96
99
100
static void EnsureInitialSoftwareCatalog()
101
{
102
if (MainDataProfile.SoftwareCatalog.Count > 0) return;
103
104
MainDataProfile.SoftwareCatalog.Add(new SoftwareCatalogItem
105
{
106
Id = "steam",
107
Name = "Steam",
108
Summary = "游戏购买、下载、更新与社区服务平台。",
109
Description = "Valve 推出的 PC 游戏平台,提供游戏商店、自动更新、云存档、创意工坊和社区功能。",
110
Publisher = "Valve Corporation",
111
Category = "游戏平台",
112
Version = "最新版",
113
DownloadUrl = "https://cdn.fastly.steamstatic.com/client/installer/SteamSetup.exe",
114
WebsiteUrl = "https://store.steampowered.com/about/",
115
FileName = "SteamSetup.exe",
116
Tags = ["Steam", "游戏", "商店", "社区"],
117
DownloadMode = SoftwareDownloadMode.Direct,
118
Featured = true
119
});
120
MainDataProfile.SoftwareCatalog.Add(new SoftwareCatalogItem
121
{
122
Id = "watt-toolkit",
123
Name = "Watt Toolkit",
124
Summary = "开源、跨平台的多功能游戏工具箱。",
125
Description = "Watt Toolkit(原 Steam++)提供网络加速、账号切换、库存游戏管理等功能。官方发行页会按系统提供当前版本。",
126
Publisher = "BeyondDimension",
127
Category = "游戏工具",
128
Version = "最新版",
129
DownloadUrl = "https://github.com/BeyondDimension/SteamTools/releases/latest",
130
WebsiteUrl = "https://steampp.net/",
131
Tags = ["Steam++", "Watt Toolkit", "网络加速", "开源"],
132
DownloadMode = SoftwareDownloadMode.Browser,
133
Featured = true
134
});
135
MainDataProfile.SoftwareCatalog.Add(new SoftwareCatalogItem
136
{
137
Id = "visual-studio",
138
Name = "Visual Studio Community",
139
Summary = "面向 .NET、C++ 与桌面开发的完整 IDE。",
140
Description = "Microsoft Visual Studio Community 提供代码编辑、调试、测试、设计器和可扩展开发工具。官方页面会下发当前稳定版引导程序。",
141
Publisher = "Microsoft",
142
Category = "开发工具",
143
Version = "最新版",
144
DownloadUrl = "https://visualstudio.microsoft.com/downloads/",
145
WebsiteUrl = "https://visualstudio.microsoft.com/",
146
Tags = ["Visual Studio", ".NET", "C#", "C++", "IDE"],
147
DownloadMode = SoftwareDownloadMode.Browser,
148
Featured = true
149
});
150
MainDataProfile.SoftwareCatalog.Add(new SoftwareCatalogItem
151
{
152
Id = "cheat-engine",
153
Name = "Cheat Engine",
154
Summary = "用于学习和研究的开源内存扫描与调试工具。",
155
Description = "Cheat Engine 提供内存扫描、调试和逆向研究功能。下载和使用前请确认遵守目标软件的许可协议与当地法律。",
156
Publisher = "Cheat Engine Project",
157
Category = "调试工具",
158
Version = "最新版",
159
DownloadUrl = "https://www.cheatengine.org/download.php",
160
WebsiteUrl = "https://www.cheatengine.org/",
161
Notice = "仅用于合法的软件调试、学习和研究;请勿违反第三方软件的 EULA 或服务条款。",
162
Tags = ["内存", "调试", "逆向", "开源"],
163
DownloadMode = SoftwareDownloadMode.Browser
164
});
165
MainDataProfile.SaveProfile();
166
Console.WriteLine("[初始化] 已创建默认软件下载目录。可通过 MainDataProfile 配置维护。");
167
}
168
97
169
static void SaveProfiles()
98
170
{
99
171
ServerProfile.SaveProfile();
172
MainDataProfile.SaveProfile();
100
173
UserDataProfile.SaveProfile();
101
174
}
@@ -0,0 +1,67 @@
1
using System.Net;
2
using XFEToolBox.Core.Downloads;
3
using XFEToolBox.Server.Profiles.Data;
4
using XFEExtension.NetCore.ServerInteractive.Attributes;
5
using XFEExtension.NetCore.ServerInteractive.Implements.CoreService;
6
7
namespace XFEToolBox.Server.Services;
8
9
public partial class SoftwareCatalogService : ServerCoreStandardServiceBase
10
{
11
[EntryPoint("v1/software/list")]
12
public async Task GetSoftwareCatalogEntryPoint()
13
{
14
if (!TryGetString("search", out var search) || !TryGetString("category", out var category))
15
{
16
await CloseWithError("search 和 category 必须是字符串。", HttpStatusCode.BadRequest);
17
return;
18
}
19
20
IEnumerable<SoftwareCatalogItem> filtered = MainDataProfile.SoftwareCatalog
21
.Where(item => item.Enabled && IsWebAddress(item.DownloadUrl));
22
23
if (!string.IsNullOrWhiteSpace(search))
24
{
25
filtered = filtered.Where(item =>
26
item.Name.Contains(search, StringComparison.OrdinalIgnoreCase) ||
27
item.Summary.Contains(search, StringComparison.OrdinalIgnoreCase) ||
28
item.Description.Contains(search, StringComparison.OrdinalIgnoreCase) ||
29
item.Publisher.Contains(search, StringComparison.OrdinalIgnoreCase) ||
30
item.Tags.Any(tag => tag.Contains(search, StringComparison.OrdinalIgnoreCase)));
31
}
32
33
if (!string.IsNullOrWhiteSpace(category))
34
filtered = filtered.Where(item => string.Equals(item.Category, category, StringComparison.OrdinalIgnoreCase));
35
36
var items = filtered
37
.OrderByDescending(item => item.Featured)
38
.ThenBy(item => item.Name, StringComparer.CurrentCultureIgnoreCase)
39
.ToArray();
40
var categories = MainDataProfile.SoftwareCatalog
41
.Where(item => item.Enabled && !string.IsNullOrWhiteSpace(item.Category))
42
.Select(item => item.Category.Trim())
43
.Distinct(StringComparer.CurrentCultureIgnoreCase)
44
.OrderBy(value => value, StringComparer.CurrentCultureIgnoreCase)
45
.ToArray();
46
47
await Close(new SoftwareCatalogResponse { Items = items, Categories = categories });
48
}
49
50
private bool TryGetString(string propertyName, out string? value)
51
{
52
try
53
{
54
value = Json?[propertyName]?.GetValue<string>()?.Trim();
55
return true;
56
}
57
catch (Exception exception) when (exception is InvalidOperationException or FormatException)
58
{
59
value = null;
60
return false;
61
}
62
}
63
64
private static bool IsWebAddress(string value) =>
65
Uri.TryCreate(value, UriKind.Absolute, out var uri) &&
66
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);
67
}
@@ -1,99 +0,0 @@
1
//------------------------------------------------------------------------------
2
// <auto-generated>
3
// 此代码由工具生成。
4
// 运行时版本:4.0.30319.42000
5
//
6
// 对此文件的更改可能会导致不正确的行为,并且如果
7
// 重新生成代码,这些更改将会丢失。
8
// </auto-generated>
9
//------------------------------------------------------------------------------
10
11
namespace XFEToolBox.Client.Resources.Resource {
12
using System;
13
14
15
/// <summary>
16
/// 一个强类型的资源类,用于查找本地化的字符串等。
17
/// </summary>
18
// 此类是由 StronglyTypedResourceBuilder
19
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
20
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
21
// (以 /str 作为命令选项),或重新生成 VS 项目。
22
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
23
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25
internal class DownloadInfoResource {
26
27
private static global::System.Resources.ResourceManager resourceMan;
28
29
private static global::System.Globalization.CultureInfo resourceCulture;
30
31
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32
internal DownloadInfoResource() {
33
}
34
35
/// <summary>
36
/// 返回此类使用的缓存的 ResourceManager 实例。
37
/// </summary>
38
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39
internal static global::System.Resources.ResourceManager ResourceManager {
40
get {
41
if (object.ReferenceEquals(resourceMan, null)) {
42
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XFEToolBox.Client.Resources.Resource.DownloadInfoResource", typeof(DownloadInfoResource).Assembly);
43
resourceMan = temp;
44
}
45
return resourceMan;
46
}
47
}
48
49
/// <summary>
50
/// 重写当前线程的 CurrentUICulture 属性,对
51
/// 使用此强类型资源类的所有资源查找执行重写。
52
/// </summary>
53
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54
internal static global::System.Globalization.CultureInfo Culture {
55
get {
56
return resourceCulture;
57
}
58
set {
59
resourceCulture = value;
60
}
61
}
62
63
/// <summary>
64
/// 查找类似 URL:https://d1vdn3r1396bak.cloudfront.net/installer/615515/8160454381798 的本地化字符串。
65
/// </summary>
66
internal static string CheatEngine {
67
get {
68
return ResourceManager.GetString("CheatEngine", resourceCulture);
69
}
70
}
71
72
/// <summary>
73
/// 查找类似 URL:https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe 的本地化字符串。
74
/// </summary>
75
internal static string Steam {
76
get {
77
return ResourceManager.GetString("Steam", resourceCulture);
78
}
79
}
80
81
/// <summary>
82
/// 查找类似 URL:https://apps.microsoft.com/0d4d1483-85ee-45ff-a2ef-f5cad41db2c8 的本地化字符串。
83
/// </summary>
84
internal static string Steampp {
85
get {
86
return ResourceManager.GetString("Steampp", resourceCulture);
87
}
88
}
89
90
/// <summary>
91
/// 查找类似 URL:https://c2rsetup.officeapps.live.com/c2r/downloadVS.aspx?sku=community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030:932d79d8269b49daac423040f7b7a9d4 的本地化字符串。
92
/// </summary>
93
internal static string VisualStudio {
94
get {
95
return ResourceManager.GetString("VisualStudio", resourceCulture);
96
}
97
}
98
}
99
}
@@ -1,132 +0,0 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<root>
3
<!--
4
Microsoft ResX Schema
5
6
Version 2.0
7
8
The primary goals of this format is to allow a simple XML format
9
that is mostly human readable. The generation and parsing of the
10
various data types are done through the TypeConverter classes
11
associated with the data types.
12
13
Example:
14
15
... ado.net/XML headers & schema ...
16
<resheader name="resmimetype">text/microsoft-resx</resheader>
17
<resheader name="version">2.0</resheader>
18
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23
<value>[base64 mime encoded serialized .NET Framework object]</value>
24
</data>
25
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27
<comment>This is a comment</comment>
28
</data>
29
30
There are any number of "resheader" rows that contain simple
31
name/value pairs.
32
33
Each data row contains a name, and value. The row also contains a
34
type or mimetype. Type corresponds to a .NET class that support
35
text/value conversion through the TypeConverter architecture.
36
Classes that don't support this are serialized and stored with the
37
mimetype set.
38
39
The mimetype is used for serialized objects, and tells the
40
ResXResourceReader how to depersist the object. This is currently not
41
extensible. For a given mimetype the value must be set accordingly:
42
43
Note - application/x-microsoft.net.object.binary.base64 is the format
44
that the ResXResourceWriter will generate, however the reader can
45
read any of the formats listed below.
46
47
mimetype: application/x-microsoft.net.object.binary.base64
48
value : The object must be serialized with
49
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50
: and then encoded with base64 encoding.
51
52
mimetype: application/x-microsoft.net.object.soap.base64
53
value : The object must be serialized with
54
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55
: and then encoded with base64 encoding.
56
57
mimetype: application/x-microsoft.net.object.bytearray.base64
58
value : The object must be serialized into a byte array
59
: using a System.ComponentModel.TypeConverter
60
: and then encoded with base64 encoding.
61
-->
62
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64
<xsd:element name="root" msdata:IsDataSet="true">
65
<xsd:complexType>
66
<xsd:choice maxOccurs="unbounded">
67
<xsd:element name="metadata">
68
<xsd:complexType>
69
<xsd:sequence>
70
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71
</xsd:sequence>
72
<xsd:attribute name="name" use="required" type="xsd:string" />
73
<xsd:attribute name="type" type="xsd:string" />
74
<xsd:attribute name="mimetype" type="xsd:string" />
75
<xsd:attribute ref="xml:space" />
76
</xsd:complexType>
77
</xsd:element>
78
<xsd:element name="assembly">
79
<xsd:complexType>
80
<xsd:attribute name="alias" type="xsd:string" />
81
<xsd:attribute name="name" type="xsd:string" />
82
</xsd:complexType>
83
</xsd:element>
84
<xsd:element name="data">
85
<xsd:complexType>
86
<xsd:sequence>
87
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89
</xsd:sequence>
90
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93
<xsd:attribute ref="xml:space" />
94
</xsd:complexType>
95
</xsd:element>
96
<xsd:element name="resheader">
97
<xsd:complexType>
98
<xsd:sequence>
99
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100
</xsd:sequence>
101
<xsd:attribute name="name" type="xsd:string" use="required" />
102
</xsd:complexType>
103
</xsd:element>
104
</xsd:choice>
105
</xsd:complexType>
106
</xsd:element>
107
</xsd:schema>
108
<resheader name="resmimetype">
109
<value>text/microsoft-resx</value>
110
</resheader>
111
<resheader name="version">
112
<value>2.0</value>
113
</resheader>
114
<resheader name="reader">
115
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116
</resheader>
117
<resheader name="writer">
118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119
</resheader>
120
<data name="Steam" xml:space="preserve">
121
<value>URL:https://cdn.akamai.steamstatic.com/client/installer/SteamSetup.exe</value>
122
</data>
123
<data name="Steampp" xml:space="preserve">
124
<value>URL:https://apps.microsoft.com/0d4d1483-85ee-45ff-a2ef-f5cad41db2c8</value>
125
</data>
126
<data name="VisualStudio" xml:space="preserve">
127
<value>URL:https://c2rsetup.officeapps.live.com/c2r/downloadVS.aspx?sku=community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030:932d79d8269b49daac423040f7b7a9d4</value>
128
</data>
129
<data name="CheatEngine" xml:space="preserve">
130
<value>URL:https://d1vdn3r1396bak.cloudfront.net/installer/615515/8160454381798</value>
131
</data>
132
</root>
@@ -1,5 +1,6 @@
1
1
using System.Text.Json;
2
2
using XFEToolBox.Client.Models.Server;
3
using XFEToolBox.Core.Downloads;
3
4
using XFEToolBox.Core.Models.Users;
4
5
using XFEToolBox.Core.Tools;
5
6
using XFEExtension.NetCore.ServerInteractive.Attributes;
@@ -41,6 +42,17 @@ public partial class ToolBoxRequestService : StandardRequestServiceBase
41
42
[Response("v1/tools/get", Name = "catalogToolDetails")]
42
43
public object ParseCatalogToolDetailsResponse() => Deserialize<ToolPackageDetails>();
43
44
45
[Request("v1/software/list", Name = "softwareCatalog")]
46
public object BuildSoftwareCatalogRequest() => new
47
{
48
execute = "v1/software/list",
49
search = Parameters.Length > 0 ? Parameters[0] : null,
50
category = Parameters.Length > 1 ? Parameters[1] : null
51
};
52
53
[Response("v1/software/list", Name = "softwareCatalog")]
54
public object ParseSoftwareCatalogResponse() => Deserialize<SoftwareCatalogResponse>();
55
44
56
[Request("v1/manage/overview", Name = "adminOverview")]
45
57
public object BuildAdminOverviewRequest() => AuthenticatedBody("v1/manage/overview");
46
58
@@ -1,20 +1,283 @@
1
using CommunityToolkit.Mvvm.ComponentModel;
1
using System.Diagnostics;
2
using System.IO;
3
using System.Net.Http;
4
using System.Security.Cryptography;
5
using System.Windows;
6
using System.Windows.Media;
7
using CommunityToolkit.Mvvm.ComponentModel;
2
8
using CommunityToolkit.Mvvm.Input;
9
using XFEToolBox.Client.Model;
10
using XFEToolBox.Client.Profiles.CrossVersionProfiles;
11
using XFEToolBox.Client.Utilities;
3
12
using XFEToolBox.Client.Views.Pages;
13
using XFEToolBox.Client.Views.Pages.Popups;
14
using XFEToolBox.Core.Downloads;
4
15
5
16
namespace XFEToolBox.Client.ViewModel.Pages;
6
17
7
public partial class DownloadInfoPageViewModel(DownloadInfoPage viewPage) : ObservableObject
18
public partial class DownloadInfoPageViewModel : ObservableObject
8
19
{
9
[ObservableProperty]
10
string appTitle = "";
11
[ObservableProperty]
12
string downloadButtonName = "下载";
13
public DownloadInfoPage ViewPage { get; set; } = viewPage;
20
private static readonly HttpClient DownloadClient = CreateDownloadClient();
21
private readonly SoftwareCatalogItem _software;
22
23
public DownloadInfoPageViewModel(DownloadInfoPage viewPage, SoftwareCatalogItem software, ImageSource iconSource)
24
{
25
ViewPage = viewPage;
26
_software = software;
27
IconSource = iconSource;
28
DownloadButtonName = software.DownloadMode == SoftwareDownloadMode.Direct ? "下载到本地" : "前往官方页面";
29
}
30
31
public DownloadInfoPage ViewPage { get; }
32
public string AppTitle => _software.Name;
33
public string Summary => _software.Summary;
34
public string Description => _software.Description;
35
public string Publisher => _software.Publisher;
36
public string Category => _software.Category;
37
public string Version => _software.Version;
38
public string DownloadModeText => _software.DownloadMode == SoftwareDownloadMode.Direct ? "客户端直接下载" : "浏览器获取";
39
public string Notice => _software.Notice;
40
public Visibility NoticeVisibility => string.IsNullOrWhiteSpace(_software.Notice) ? Visibility.Collapsed : Visibility.Visible;
41
public Visibility WebsiteVisibility => IsWebAddress(_software.WebsiteUrl) ? Visibility.Visible : Visibility.Collapsed;
42
43
[ObservableProperty] private ImageSource iconSource;
44
[ObservableProperty] private string downloadButtonName;
45
[ObservableProperty] private string statusText = "确认信息后即可开始获取。";
46
[ObservableProperty] private double progressValue;
47
[ObservableProperty] private bool isProgressIndeterminate;
48
[ObservableProperty] private Visibility progressVisibility = Visibility.Collapsed;
49
[ObservableProperty] private bool canDownload = true;
50
51
[RelayCommand]
52
private void OpenWebsite()
53
{
54
if (IsWebAddress(_software.WebsiteUrl)) OpenAddress(_software.WebsiteUrl);
55
}
14
56
15
57
[RelayCommand]
16
void DownloadClick()
58
private async Task DownloadClick()
59
{
60
if (!CanDownload || !EnsureAgreementAccepted()) return;
61
62
if (_software.DownloadMode == SoftwareDownloadMode.Browser)
63
{
64
try
65
{
66
OpenAddress(_software.DownloadUrl);
67
StatusText = "已在浏览器中打开服务器提供的官方获取页面。";
68
}
69
catch (Exception exception)
70
{
71
StatusText = $"无法打开官方页面:{exception.Message}";
72
}
73
return;
74
}
75
76
var task = DownloadDirectAsync();
77
TaskManager.TaskDictionary[task.Id] = new NamedTask($"下载 {_software.Name}", task);
78
try
79
{
80
await task;
81
}
82
finally
83
{
84
TaskManager.TaskDictionary.Remove(task.Id);
85
}
86
}
87
88
private bool EnsureAgreementAccepted()
89
{
90
if (DownloadProfile.DownloadAgreementAccepted) return true;
91
92
var result = PopupHelper.ShowDialog(new AgreementDialogPopupPage
93
{
94
Title = "下载协议同意书",
95
Agreement = """
96
1. 下载来源
97
98
软件信息和获取地址由当前配置的工具箱服务器提供。对于跳转到第三方官方网站的内容,实际文件、许可协议和隐私条款由对应发布者负责。
99
100
2. 安全检查
101
102
下载前请确认发布者、文件来源与数字签名。服务器配置了 SHA-256 时,工具箱会校验文件完整性;该校验不替代杀毒软件、数字签名或人工审核。
103
104
3. 使用责任
105
106
请遵守相关法律法规、软件许可协议和服务条款。不得将下载的软件用于侵权、破坏系统或其他非法用途。
107
108
4. 自动运行
109
110
若设置中启用了“下载完成后自动运行”,文件下载完成后会由系统打开。你可以随时在选项设置中关闭该功能。
111
112
继续即表示你已阅读并理解以上内容。
113
"""
114
}, new PopupWindowOptions
115
{
116
Title = "下载协议",
117
Subtitle = "首次下载前需要确认",
118
Width = 520,
119
Height = 520,
120
ContentMargin = new Thickness(12, 0, 12, 12)
121
});
122
if (result != MessageBoxResult.Yes) return false;
123
124
DownloadProfile.DownloadAgreementAccepted = true;
125
DownloadProfile.SaveProfile();
126
return true;
127
}
128
129
private async Task DownloadDirectAsync()
130
{
131
string? temporaryPath = null;
132
CanDownload = false;
133
ProgressVisibility = Visibility.Visible;
134
IsProgressIndeterminate = true;
135
ProgressValue = 0;
136
DownloadButtonName = "正在下载…";
137
StatusText = "正在连接下载服务器…";
138
139
try
140
{
141
if (!IsWebAddress(_software.DownloadUrl)) throw new InvalidOperationException("服务器返回了无效的下载地址。");
142
143
Directory.CreateDirectory(DownloadProfile.DownloadDirectory);
144
using var response = await DownloadClient.GetAsync(_software.DownloadUrl, HttpCompletionOption.ResponseHeadersRead);
145
response.EnsureSuccessStatusCode();
146
147
var fileName = ResolveFileName(response, _software);
148
var destinationPath = GetAvailablePath(Path.Combine(DownloadProfile.DownloadDirectory, fileName));
149
temporaryPath = destinationPath + $".{Guid.NewGuid():N}.download";
150
var contentLength = response.Content.Headers.ContentLength;
151
IsProgressIndeterminate = contentLength is null or <= 0;
152
153
await using (var input = await response.Content.ReadAsStreamAsync())
154
await using (var output = new FileStream(temporaryPath, FileMode.CreateNew, FileAccess.Write, FileShare.None, 81920,
155
FileOptions.Asynchronous | FileOptions.SequentialScan))
156
{
157
var buffer = new byte[81920];
158
long received = 0;
159
int read;
160
while ((read = await input.ReadAsync(buffer)) > 0)
161
{
162
await output.WriteAsync(buffer.AsMemory(0, read));
163
received += read;
164
if (contentLength is > 0)
165
{
166
ProgressValue = received * 100d / contentLength.Value;
167
StatusText = $"正在下载… {FormatBytes(received)} / {FormatBytes(contentLength.Value)}";
168
}
169
else
170
{
171
StatusText = $"正在下载… 已接收 {FormatBytes(received)}";
172
}
173
}
174
await output.FlushAsync();
175
}
176
177
if (!string.IsNullOrWhiteSpace(_software.Sha256))
178
{
179
StatusText = "正在校验文件完整性…";
180
await VerifySha256Async(temporaryPath, _software.Sha256);
181
}
182
183
File.Move(temporaryPath, destinationPath);
184
temporaryPath = null;
185
ProgressValue = 100;
186
IsProgressIndeterminate = false;
187
StatusText = $"下载完成:{Path.GetFileName(destinationPath)}";
188
189
var followUpMessages = new List<string>();
190
if (DownloadProfile.AutoRunWhenComplete)
191
{
192
try { Process.Start(new ProcessStartInfo(destinationPath) { UseShellExecute = true }); }
193
catch (Exception exception) { followUpMessages.Add($"自动打开失败:{exception.Message}"); }
194
}
195
if (DownloadProfile.OpenFolderWhenComplete)
196
{
197
try { Process.Start(new ProcessStartInfo(DownloadProfile.DownloadDirectory) { UseShellExecute = true }); }
198
catch (Exception exception) { followUpMessages.Add($"打开目录失败:{exception.Message}"); }
199
}
200
if (followUpMessages.Count > 0) StatusText += $"({string.Join(";", followUpMessages)})";
201
}
202
catch (Exception exception)
203
{
204
ProgressValue = 0;
205
IsProgressIndeterminate = false;
206
StatusText = $"下载失败:{exception.Message}";
207
}
208
finally
209
{
210
if (temporaryPath is not null && File.Exists(temporaryPath)) File.Delete(temporaryPath);
211
CanDownload = true;
212
DownloadButtonName = "重新下载";
213
}
214
}
215
216
private static string ResolveFileName(HttpResponseMessage response, SoftwareCatalogItem software)
217
{
218
var value = software.FileName;
219
if (string.IsNullOrWhiteSpace(value))
220
value = response.Content.Headers.ContentDisposition?.FileNameStar ?? response.Content.Headers.ContentDisposition?.FileName;
221
value = value?.Trim().Trim('"');
222
if (string.IsNullOrWhiteSpace(value) && Uri.TryCreate(software.DownloadUrl, UriKind.Absolute, out var uri))
223
value = Uri.UnescapeDataString(Path.GetFileName(uri.LocalPath));
224
225
value = Path.GetFileName(value);
226
if (string.IsNullOrWhiteSpace(value)) value = $"{SanitizeFileName(software.Id)}.download";
227
return SanitizeFileName(value);
228
}
229
230
private static string SanitizeFileName(string value)
231
{
232
foreach (var invalid in Path.GetInvalidFileNameChars()) value = value.Replace(invalid, '_');
233
return string.IsNullOrWhiteSpace(value) ? "download.bin" : value;
234
}
235
236
private static string GetAvailablePath(string path)
237
{
238
if (!File.Exists(path)) return path;
239
var directory = Path.GetDirectoryName(path)!;
240
var name = Path.GetFileNameWithoutExtension(path);
241
var extension = Path.GetExtension(path);
242
for (var index = 1; ; index++)
243
{
244
var candidate = Path.Combine(directory, $"{name} ({index}){extension}");
245
if (!File.Exists(candidate)) return candidate;
246
}
247
}
248
249
private static async Task VerifySha256Async(string path, string expected)
250
{
251
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 81920,
252
FileOptions.Asynchronous | FileOptions.SequentialScan);
253
var actual = Convert.ToHexString(await SHA256.HashDataAsync(stream));
254
if (!string.Equals(actual, expected.Trim(), StringComparison.OrdinalIgnoreCase))
255
throw new InvalidDataException("SHA-256 校验失败,文件可能已损坏或被替换。");
256
}
257
258
private static string FormatBytes(long bytes)
17
259
{
260
string[] units = ["B", "KB", "MB", "GB"];
261
var value = (double)bytes;
262
var unit = 0;
263
while (value >= 1024 && unit < units.Length - 1) { value /= 1024; unit++; }
264
return $"{value:0.##} {units[unit]}";
265
}
18
266
267
private static bool IsWebAddress(string value) =>
268
Uri.TryCreate(value, UriKind.Absolute, out var uri) &&
269
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps);
270
271
private static void OpenAddress(string value)
272
{
273
if (!IsWebAddress(value)) return;
274
Process.Start(new ProcessStartInfo(value) { UseShellExecute = true });
275
}
276
277
private static HttpClient CreateDownloadClient()
278
{
279
var client = new HttpClient { Timeout = TimeSpan.FromMinutes(30) };
280
client.DefaultRequestHeaders.UserAgent.ParseAdd("XFEToolBox/0.2");
281
return client;
19
282
}
20
283
}
@@ -1,61 +0,0 @@
1
using CommunityToolkit.Mvvm.ComponentModel;
2
using CommunityToolkit.Mvvm.Input;
3
using XFEToolBox.Client.Profiles.CrossVersionProfiles;
4
using XFEToolBox.Client.Resources.Resource;
5
using XFEToolBox.Client.Utilities;
6
using XFEToolBox.Client.Views.Controls;
7
using XFEToolBox.Client.Views.Pages;
8
using XFEToolBox.Client.Views.Pages.Popups;
9
10
namespace XFEToolBox.Client.ViewModel.Pages;
11
12
public partial class DownloadPageViewModel(DownloadPage viewPage) : ObservableObject
13
{
14
public DownloadPage ViewPage { get; set; } = viewPage;
15
16
[RelayCommand]
17
void GotoDownloadPage(MiniToolButton miniToolButton)
18
{
19
if (DownloadProfile.DownloadAgreementAccepted)
20
{
21
var result = PopupHelper.ShowDialog(new AgreementDialogPopupPage()
22
{
23
Title = "下载协议同意书",
24
Agreement = """
25
软件免责协议:
26
27
28
1. 免责声明
29
30
本软件(以下简称“本软件”)仅用于提供下载服务。用户使用本软件下载的任何内容,均由用户自行负责。本软件的开发者(以下简称“开发者”)对用户使用本软件下载的内容的合法性、准确性、安全性及任何其他形式的风险不承担任何责任。
31
32
33
2. 不提供担保
34
35
本软件按照“现状”提供,没有任何形式的担保,无论是明示的还是暗示的。开发者不对本软件的功能、运行或可用性做出任何保证。开发者不保证本软件无故障、无病毒或其他有害组件。
36
37
38
3. 责任限制
39
40
在适用法律允许的最大范围内,开发者对因使用或无法使用本软件所引起的任何直接、间接、偶然、特殊、或后果性的损害(包括但不限于数据丢失、业务中断、经济损失等)不承担任何责任,即使开发者已被告知此类损害的可能性。
41
42
43
4. 用户责任
44
45
用户在使用本软件时,应遵守相关法律法规和政策。用户不得利用本软件从事任何非法活动或侵犯第三方权利的行为。因用户不当使用本软件造成的所有后果,均由用户自行承担。
46
47
48
5. 协议的接受
49
50
通过安装、复制或以其他方式使用本软件,用户表示已阅读、理解并同意受本免责协议的条款约束。如果用户不同意本免责协议的条款,请勿安装或使用本软件。
51
"""
52
}, 480, 420);
53
if (result == System.Windows.MessageBoxResult.Yes)
54
DownloadProfile.DownloadAgreementAccepted = true;
55
}
56
if (DownloadProfile.DownloadAgreementAccepted && miniToolButton.Tag is string gotoUrl)
57
{
58
var urlString = DownloadInfoResource.ResourceManager.GetString(gotoUrl);
59
}
60
}
61
}
@@ -0,0 +1,21 @@
1
using System.Windows.Media;
2
using CommunityToolkit.Mvvm.ComponentModel;
3
using XFEToolBox.Core.Downloads;
4
5
namespace XFEToolBox.Client.ViewModel.Pages;
6
7
public partial class SoftwareCardViewModel(SoftwareCatalogItem software, ImageSource iconSource) : ObservableObject
8
{
9
public SoftwareCatalogItem Software { get; } = software;
10
11
public string Id => Software.Id;
12
public string Name => Software.Name;
13
public string Summary => Software.Summary;
14
public string Publisher => Software.Publisher;
15
public string Category => Software.Category;
16
public string Version => Software.Version;
17
public string DownloadModeText => Software.DownloadMode == SoftwareDownloadMode.Direct ? "直接下载" : "官方页面";
18
19
[ObservableProperty]
20
private ImageSource iconSource = iconSource;
21
}
@@ -1,7 +1,7 @@
1
1
<Page x:Class="XFEToolBox.Client.Views.Pages.Admin.ServerOverviewPage"
2
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
3
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
Background="#F7F8FC" Title="服务器概览" Loaded="Page_Loaded">
4
Background="Transparent" Title="" Loaded="Page_Loaded">
5
5
<Page.Resources>
6
6
<Style x:Key="MetricCard" TargetType="Border">
7
7
<Setter Property="Background" Value="White"/>
@@ -17,12 +17,8 @@
17
17
</Style>
18
18
</Page.Resources>
19
19
<ScrollViewer VerticalScrollBarVisibility="Auto">
20
<StackPanel Margin="26,22">
21
<Grid Margin="7,0,7,14">
22
<StackPanel>
23
<TextBlock Text="服务器概览" FontSize="26" FontWeight="Bold" Foreground="#29293D"/>
24
<TextBlock Text="实时查看工具服务运行状态、用户和工具包数据。" Foreground="#7C7C91" Margin="0,5,0,0"/>
25
</StackPanel>
20
<StackPanel Margin="14,10,14,12">
21
<Grid Height="38" Margin="7,0,7,8">
26
22
<Button Content="刷新" Style="{StaticResource ActionButton}" HorizontalAlignment="Right" VerticalAlignment="Center" Click="RefreshButton_Click"/>
27
23
</Grid>
28
24
<UniformGrid Columns="2">
@@ -1,18 +1,17 @@
1
1
<Page x:Class="XFEToolBox.Client.Views.Pages.Admin.ToolManagementPage"
2
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
3
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
Background="#F7F8FC" Title="工具管理" Loaded="Page_Loaded">
5
<Grid Margin="25,20">
4
Background="Transparent" Title="" Loaded="Page_Loaded">
5
<Grid Margin="14,10,14,12">
6
6
<Grid.RowDefinitions><RowDefinition Height="Auto"/><RowDefinition Height="*"/><RowDefinition Height="Auto"/></Grid.RowDefinitions>
7
<Grid>
8
<StackPanel><TextBlock Text="工具发布中心" FontSize="26" FontWeight="Bold" Foreground="#29293D"/><TextBlock Text="上传 .xfetool 源码包、切换发布状态并打开代码编辑器。" Foreground="#7C7C91" Margin="0,5,0,0"/></StackPanel>
7
<Grid Height="38">
9
8
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
10
9
<Button Content="打开编辑器" Padding="14,8" Margin="0,0,8,0" Click="OpenEditorButton_Click"/>
11
10
<Button Content="上传工具包" Padding="14,8" Margin="0,0,8,0" Background="#7777DB" Foreground="White" BorderThickness="0" Click="UploadButton_Click"/>
12
11
<Button Content="刷新" Padding="14,8" Click="RefreshButton_Click"/>
13
12
</StackPanel>
14
13
</Grid>
15
<Border Grid.Row="1" Background="White" CornerRadius="15" BorderBrush="#E9E9F3" BorderThickness="1" Margin="0,18,0,12" Padding="8">
14
<Border Grid.Row="1" Background="White" CornerRadius="15" BorderBrush="#E9E9F3" BorderThickness="1" Margin="0,10,0,10" Padding="8">
16
15
<DataGrid x:Name="ToolGrid" AutoGenerateColumns="False" IsReadOnly="True" BorderThickness="0" GridLinesVisibility="Horizontal" SelectionMode="Single">
17
16
<DataGrid.Columns>
18
17
<DataGridTextColumn Header="工具" Binding="{Binding Manifest.Name}" Width="*"/>
@@ -24,7 +23,7 @@
24
23
</DataGrid>
25
24
</Border>
26
25
<Grid Grid.Row="2">
27
<TextBlock x:Name="StatusText" Foreground="#66667A" VerticalAlignment="Center" TextWrapping="Wrap"/>
26
<TextBlock x:Name="StatusText" Foreground="White" VerticalAlignment="Center" TextWrapping="Wrap"/>
28
27
<Button Content="切换选中版本的发布状态" Padding="16,8" HorizontalAlignment="Right" Click="TogglePublicationButton_Click"/>
29
28
</Grid>
30
29
</Grid>