Skip to content

Commit 16bd920

Browse files
committed
up 整合包下载
1 parent c08d287 commit 16bd920

13 files changed

Lines changed: 315 additions & 73 deletions

File tree

log.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
## 计划中 Planning
99
- 调整代码
1010
- 新界面
11+
- 压缩包子文件夹识别
1112

1213
## 已知问题 Known issue
1314

1415
## 已完成 Done
16+
### 2026.3.2
17+
- 添加hmcl服务器整合包的下载
18+
1519
### 2026.2.26
1620
- 更换SVG图标
1721
- 添加HMCL在线包支持

src/ColorMC.Core/Game/GameLaunch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static async Task AuthLoginAsync(GameSettingObj obj, GameLaunchArg larg,
6868
/// <exception cref="LaunchException"></exception>
6969
private static async Task PackUpdateAsync(GameSettingObj obj, GameLaunchArg larg, CancellationToken token)
7070
{
71-
if (obj.ModPackType != SourceType.ColorMC || string.IsNullOrWhiteSpace(obj.ServerUrl))
71+
if (obj.ModPackType != SourceType.ServerPack || string.IsNullOrWhiteSpace(obj.ServerUrl))
7272
{
7373
return;
7474
}

src/ColorMC.Core/Game/ServerPack.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static async Task<bool> UpdateAsync(this ServerPackObj obj, IUpdateGui? g
101101
Name = item.File,
102102
Local = Path.Combine(path, item.File),
103103
Sha256 = item.Sha256,
104-
Url = obj.Game.ServerUrl + item.Url
104+
Url = item.Url
105105
});
106106
}
107107
else
@@ -142,7 +142,7 @@ public static async Task<bool> UpdateAsync(this ServerPackObj obj, IUpdateGui? g
142142
Name = item.File,
143143
Local = Path.Combine(path, item.File),
144144
Sha256 = item.Sha256,
145-
Url = obj.Game.ServerUrl + item.Url
145+
Url = item.Url
146146
});
147147
}
148148
}, token);
@@ -162,7 +162,8 @@ public static async Task<bool> UpdateAsync(this ServerPackObj obj, IUpdateGui? g
162162
Name = item.FileName,
163163
Local = Path.Combine(path1, item.FileName),
164164
Sha256 = item.Sha256,
165-
Url = obj.Game.ServerUrl + item.Url,
165+
Sha1 = item.Sha1,
166+
Url = item.Url,
166167
Overwrite = true,
167168
Later = (stream) =>
168169
{
@@ -184,8 +185,9 @@ public static async Task<bool> UpdateAsync(this ServerPackObj obj, IUpdateGui? g
184185
Name = item.Group + item.FileName,
185186
Local = Path.GetFullPath(path + "/" + item.Group + item.FileName),
186187
Sha256 = item.Sha256,
188+
Sha1 = item.Sha1,
187189
Overwrite = true,
188-
Url = obj.Game.ServerUrl + item.Url
190+
Url = item.Url
189191
});
190192
}
191193
}

src/ColorMC.Core/Helpers/GameHelper.cs

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using ColorMC.Core.Objs.Loader;
77
using ColorMC.Core.Objs.Minecraft;
88
using ColorMC.Core.Objs.OtherLaunch;
9+
using ColorMC.Core.Objs.ServerPack;
910
using ColorMC.Core.Utils;
1011
using SharpCompress.Archives.Zip;
1112

@@ -1126,14 +1127,70 @@ public static GameSettingObj ToColorMC(this HMCLServerObj obj)
11261127
Modpack = true
11271128
};
11281129

1129-
if (!string.IsNullOrWhiteSpace(obj.Author))
1130+
//if (!string.IsNullOrWhiteSpace(obj.Author))
1131+
//{
1132+
// game.Name += "-" + obj.Author;
1133+
//}
1134+
//if (!string.IsNullOrWhiteSpace(obj.Version))
1135+
//{
1136+
// game.Name += "-" + obj.Version;
1137+
//}
1138+
foreach (var item in obj.Addons)
11301139
{
1131-
game.Name += "-" + obj.Author;
1140+
if (item.Id == "game")
1141+
{
1142+
game.Version = item.Version;
1143+
}
1144+
else if (item.Id == "forge")
1145+
{
1146+
game.Loader = Loaders.Forge;
1147+
game.LoaderVersion = item.Version;
1148+
}
1149+
else if (item.Id == "neoforge")
1150+
{
1151+
game.Loader = Loaders.NeoForge;
1152+
game.LoaderVersion = item.Version;
1153+
}
1154+
else if (item.Id == "fabric")
1155+
{
1156+
game.Loader = Loaders.Fabric;
1157+
game.LoaderVersion = item.Version;
1158+
}
1159+
else if (item.Id == "quilt")
1160+
{
1161+
game.Loader = Loaders.Quilt;
1162+
game.LoaderVersion = item.Version;
1163+
}
11321164
}
1133-
if (!string.IsNullOrWhiteSpace(obj.Version))
1165+
1166+
return game;
1167+
}
1168+
1169+
/// <summary>
1170+
/// HMCL配置转ColorMC
1171+
/// </summary>
1172+
/// <param name="obj">HMCL储存</param>
1173+
/// <returns>游戏实例</returns>
1174+
public static ServerPackObj ToServerPack(this HMCLServerObj obj)
1175+
{
1176+
var game = new ServerPackObj()
11341177
{
1135-
game.Name += "-" + obj.Version;
1136-
}
1178+
Name = obj.Name,
1179+
Loader = Loaders.Normal,
1180+
PackVersion = obj.Version,
1181+
Mod = [],
1182+
Resourcepack = [],
1183+
Config = []
1184+
};
1185+
1186+
//if (!string.IsNullOrWhiteSpace(obj.Author))
1187+
//{
1188+
// game.Name += "-" + obj.Author;
1189+
//}
1190+
//if (!string.IsNullOrWhiteSpace(obj.Version))
1191+
//{
1192+
// game.Name += "-" + obj.Version;
1193+
//}
11371194
foreach (var item in obj.Addons)
11381195
{
11391196
if (item.Id == "game")
@@ -1162,6 +1219,24 @@ public static GameSettingObj ToColorMC(this HMCLServerObj obj)
11621219
}
11631220
}
11641221

1222+
var url = obj.FileApi;
1223+
if (!url.EndsWith('/'))
1224+
{
1225+
url += '/';
1226+
}
1227+
1228+
foreach (var item in obj.Files)
1229+
{
1230+
var file1 = Path.GetFileName(item.Path);
1231+
game.Config.Add(new ConfigPackObj
1232+
{
1233+
Group = item.Path.Replace(file1, ""),
1234+
FileName = file1,
1235+
Sha1 = item.Hash,
1236+
Url = url + Names.NameOverrideDir + "/" + item.Path
1237+
});
1238+
}
1239+
11651240
return game;
11661241
}
11671242
}

src/ColorMC.Core/Objs/Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public enum CustomLoaderType
9797
/// </summary>
9898
public enum SourceType
9999
{
100-
CurseForge, Modrinth, McMod, ColorMC
100+
CurseForge, Modrinth, McMod, ServerPack
101101
}
102102

103103
/// <summary>

src/ColorMC.Core/Objs/ServerPack/ConfigPackObj.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public record ConfigPackObj
1818
/// </summary>
1919
public string Sha256 { get; set; }
2020
/// <summary>
21+
/// 校验
22+
/// </summary>
23+
public string Sha1 { get; set; }
24+
/// <summary>
2125
/// 是否为压缩包打包
2226
/// </summary>
2327
public bool IsZip { get; set; }

src/ColorMC.Core/Objs/ServerPack/ServerPackObj.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public record ServerPackObj
1212
/// </summary>
1313
public string Text { get; set; }
1414
/// <summary>
15+
/// 服务器包版本
16+
/// </summary>
17+
public string PackVersion { get; set; }
18+
/// <summary>
1519
/// Mod列表
1620
/// </summary>
1721
public List<ServerModItemObj> Mod { get; set; }
@@ -24,8 +28,42 @@ public record ServerPackObj
2428
/// </summary>
2529
public List<ConfigPackObj> Config { get; set; }
2630
/// <summary>
27-
/// 游戏实例
31+
/// 实例名字
32+
/// </summary>
33+
public string Name { get; set; }
34+
/// <summary>
35+
/// 游戏版本
36+
/// </summary>
37+
public string Version { get; set; }
38+
/// <summary>
39+
/// 加载器类型
40+
/// </summary>
41+
public Loaders Loader { get; set; }
42+
/// <summary>
43+
/// 加载器版本
44+
/// </summary>
45+
public string? LoaderVersion { get; set; }
46+
/// <summary>
47+
/// 游戏发布类型
2848
/// </summary>
29-
[JsonIgnore]
30-
public GameSettingObj Game { get; set; }
49+
public GameType GameType { get; set; }
50+
/// <summary>
51+
/// Jvm参数
52+
/// </summary>
53+
public RunArgObj? JvmArg { get; set; }
54+
/// <summary>
55+
/// 窗口设置
56+
/// </summary>
57+
public WindowSettingObj? Window { get; set; }
58+
/// <summary>
59+
/// 加入服务器设置
60+
/// </summary>
61+
public ServerObj? StartServer { get; set; }
62+
/// <summary>
63+
/// 高级Jvm设置
64+
/// </summary>
65+
public AdvanceJvmObj? AdvanceJvm { get; set; }
66+
67+
[JsonInclude]
68+
public GameSettingObj Game;
3169
}

src/ColorMC.Gui/ColorMC.Gui.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
<None Remove="Resource\Icon\Button\ArrowRight.svg" />
5151
<None Remove="Resource\Icon\Button\Close.svg" />
5252
<None Remove="Resource\Icon\Button\Cog.svg" />
53+
<None Remove="Resource\Icon\Button\Pause.svg" />
54+
<None Remove="Resource\Icon\Button\Play.svg" />
5355
<None Remove="Resource\Icon\close.svg" />
5456
<None Remove="Resource\Icon\cog.svg" />
5557
<None Remove="Resource\Icon\collection.svg" />
@@ -197,7 +199,9 @@
197199
<AvaloniaResource Include="Resource\Icon\Button\Cog.svg" />
198200
<AvaloniaResource Include="Resource\Icon\Button\Counter.svg" />
199201
<AvaloniaResource Include="Resource\Icon\Button\Delete.svg" />
202+
<AvaloniaResource Include="Resource\Icon\Button\Pause.svg" />
200203
<AvaloniaResource Include="Resource\Icon\Button\Pencil.svg" />
204+
<AvaloniaResource Include="Resource\Icon\Button\Play.svg" />
201205
<AvaloniaResource Include="Resource\Icon\Emoticon\EmoticonFrown.svg" />
202206
<AvaloniaResource Include="Resource\Icon\GroupIcon\Adjust.svg" />
203207
<AvaloniaResource Include="Resource\Icon\GroupIcon\Animation.svg" />

src/ColorMC.Gui/Resource/Language/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@
480480
"GameEditWindow.Tab1.Text45": "版本读取失败",
481481
"GameEditWindow.Tab1.Text46": "游戏实例正在下载资源,无法删除",
482482
"GameEditWindow.Tab1.Text47": "其他设置",
483+
"GameEditWindow.Tab1.Text48": "服务器包",
484+
"GameEditWindow.Tab1.Text49": "服务器包地址",
483485
"GameEditWindow.Tab2.Text13": "以下设定只应用于游戏实例 {0}",
484486
"GameEditWindow.Tab2.Text22": "设置启动使用的Java",
485487
"GameEditWindow.Tab2.Text23": "指定Java路径",

src/ColorMC.Gui/UI/Controls/GameEdit/Tab1Control.axaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@
141141
Margin="0,0,5,0"
142142
Content="{setting:Localize GameEditWindow.Tab1.Text3}"
143143
IsChecked="{Binding Modpack}" />
144+
<CheckBox
145+
Margin="0,0,5,0"
146+
Content="{setting:Localize GameEditWindow.Tab1.Text48}"
147+
IsChecked="{Binding ServerPack}"
148+
IsEnabled="{Binding Modpack}" />
144149
<Button
145150
Width="100"
146151
Height="35"
@@ -152,7 +157,10 @@
152157
IsEnabled="{Binding Modpack}"
153158
ToolTip.Tip="{setting:Localize ToolTip.Text51}" />
154159
</StackPanel>
155-
<Grid ColumnDefinitions="auto,*,auto,*">
160+
<Grid
161+
ColumnDefinitions="auto,*,auto,*"
162+
IsEnabled="{Binding Modpack}"
163+
IsVisible="{Binding !ServerPack}">
156164
<TextBlock Margin="0,0,5,0" Text="{setting:Localize GameEditWindow.Tab1.Text8}" />
157165
<TextBox
158166
Grid.Column="1"
@@ -171,6 +179,10 @@
171179
Text="{Binding FID}"
172180
Watermark="{setting:Localize GameEditWindow.Tab1.Text9}" />
173181
</Grid>
182+
<DockPanel IsEnabled="{Binding Modpack}" IsVisible="{Binding ServerPack}">
183+
<TextBlock Margin="0,0,5,0" Text="{setting:Localize GameEditWindow.Tab1.Text49}" />
184+
<TextBox Text="{Binding ServerPackUrl}" />
185+
</DockPanel>
174186
</StackPanel>
175187
</Border>
176188
<Border Margin="10,5,10,3" Classes="t2">

0 commit comments

Comments
 (0)