11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using System . Linq ;
45using System . Threading ;
56using ColorMC . Core ;
67using ColorMC . Core . Config ;
@@ -45,81 +46,118 @@ public static class GameManager
4546 /// <summary>
4647 /// 正在安装的整合包
4748 /// </summary>
48- private static readonly List < FileItemDownloadModel > s_installModpack = [ ] ;
49+ private static readonly List < SourceItemObj > s_installModpack = [ ] ;
4950 /// <summary>
5051 /// 正在安装资源的游戏实例
5152 /// </summary>
52- private static readonly Dictionary < Guid , List < FileItemDownloadModel > > s_gameDownload = [ ] ;
53+ private static readonly Dictionary < Guid , List < SourceItemObj > > s_gameDownload = [ ] ;
5354
54- public static void StartDownload ( Guid game , FileItemDownloadModel download )
55+ public static void StartDownload ( Guid game , SourceItemObj obj )
5556 {
5657 if ( s_gameDownload . TryGetValue ( game , out var list ) )
5758 {
58- list . Add ( download ) ;
59+ list . Add ( obj ) ;
5960 }
6061 else
6162 {
62- s_gameDownload [ game ] = [ download ] ;
63+ s_gameDownload [ game ] = [ obj ] ;
6364 }
65+
66+ EventManager . OnResourceInstall ( game , obj ) ;
6467 }
6568
66- public static void StopDownload ( Guid game , FileItemDownloadModel download )
69+ public static void StopDownload ( Guid game , SourceItemObj obj , bool res )
6770 {
6871 if ( s_gameDownload . TryGetValue ( game , out var list ) )
6972 {
70- list . Remove ( download ) ;
73+ list . Remove ( obj ) ;
7174 }
75+
76+ EventManager . OnResourceStop ( game , obj , res ) ;
7277 }
7378
7479 /// <summary>
7580 /// 开始下载整合包
7681 /// </summary>
7782 /// <param name="obj"></param>
78- public static void StartDownload ( FileItemDownloadModel obj )
83+ public static void StartDownload ( SourceItemObj obj )
7984 {
8085 foreach ( var item in s_installModpack )
8186 {
82- if ( item . Obj . Source == obj . Obj . Source && item . Obj . Pid == obj . Obj . Pid )
87+ if ( item . CheckProject ( obj ) )
8388 {
8489 return ;
8590 }
8691 }
8792
8893 s_installModpack . Add ( obj ) ;
8994
90- EventManager . OnModpackInstall ( obj . Obj ) ;
95+ EventManager . OnModpackInstall ( obj ) ;
9196 }
9297
93- public static void StopDownload ( FileItemDownloadModel obj , bool res )
98+ public static void StopDownload ( SourceItemObj obj , bool res )
9499 {
95100 s_installModpack . Remove ( obj ) ;
96101
97- EventManager . OnModpackStop ( obj . Obj , res ) ;
102+ EventManager . OnModpackStop ( obj , res ) ;
98103 }
99104
100105 /// <summary>
101106 /// 检查资源是否在下载
102107 /// </summary>
103108 /// <param name="obj"></param>
104109 /// <returns></returns>
105- public static bool TestDowload ( Guid game , SourceItemObj obj )
106- {
107- //foreach (var item in s_installModpack)
108- //{
109- // if (item.FileType == info.Type && item.SourceType == info.Source)
110- // {
111- // if (item.ID == info.Pid)
112- // {
113- // item.NowDownload = false;
114- // item.IsDownload = done;
115- // }
116- // else if (info.SubPid != null && info.SubPid.Contains(item.ID))
117- // {
118- // item.NowDownload = false;
119- // item.NowDownload = done;
120- // }
121- // }
122- //}
110+ public static bool IsDownload ( Guid game , SourceItemObj obj )
111+ {
112+ if ( s_gameDownload . TryGetValue ( game , out var list ) )
113+ {
114+ foreach ( var item in list )
115+ {
116+ if ( item . CheckProject ( obj ) )
117+ {
118+ return true ;
119+ }
120+ }
121+ }
122+
123+ return false ;
124+ }
125+
126+ /// <summary>
127+ /// 检查游戏资源是否在下载
128+ /// </summary>
129+ /// <param name="obj"></param>
130+ /// <returns></returns>
131+ public static bool IsDownload ( Guid game , SourceType source , FileType type , string pid )
132+ {
133+ if ( s_gameDownload . TryGetValue ( game , out var list ) )
134+ {
135+ foreach ( var item in list )
136+ {
137+ if ( item . Source == source && item . Pid == pid && item . Type == type )
138+ {
139+ return true ;
140+ }
141+ }
142+ }
143+
144+ return false ;
145+ }
146+
147+ /// <summary>
148+ /// 检查整合包是否在下载
149+ /// </summary>
150+ /// <param name="obj"></param>
151+ /// <returns></returns>
152+ public static bool IsDownload ( SourceItemObj obj )
153+ {
154+ foreach ( var item in s_installModpack )
155+ {
156+ if ( item . Source == obj . Source && item . Pid == obj . Pid )
157+ {
158+ return true ;
159+ }
160+ }
123161
124162 return false ;
125163 }
@@ -129,11 +167,11 @@ public static bool TestDowload(Guid game, SourceItemObj obj)
129167 /// </summary>
130168 /// <param name="obj"></param>
131169 /// <returns></returns>
132- public static bool TestDowload ( SourceItemObj obj )
170+ public static bool IsDownload ( SourceType source , string pid )
133171 {
134172 foreach ( var item in s_installModpack )
135173 {
136- if ( item . Obj . Source == obj . Source && item . Obj . Pid == obj . Pid )
174+ if ( item . Source == source && item . Pid == pid )
137175 {
138176 return true ;
139177 }
0 commit comments