3
3
using System . Collections . Generic ;
4
4
using System . Collections . Immutable ;
5
5
using System . Diagnostics ;
6
+ using System . Diagnostics . CodeAnalysis ;
6
7
using System . Linq ;
7
8
using System . Runtime . CompilerServices ;
8
9
using System . Threading ;
@@ -165,6 +166,8 @@ public FluentResults.Result ProcessQueuedPackages(bool rescanPackages = false, b
165
166
/*
166
167
* Helper functions
167
168
*/
169
+
170
+ // register in the list so we can check against it.
168
171
FluentResults . Result LoadPackageInfo ( LoadablePackage package )
169
172
{
170
173
try
@@ -199,18 +202,42 @@ FluentResults.Result LoadPackageInfo(LoadablePackage package)
199
202
}
200
203
201
204
/*
202
- * Return array: (Normal, MissingDeps)
205
+ * Return array: (Normal, MissingDepsRes, MissingDeps)
203
206
*/
204
- FluentResults . Result < ( ImmutableArray < T > , ImmutableArray < T > ) > GetLoadablePackages < T > ( ImmutableArray < T > resources , bool errorForPacksMissingDeps = false )
207
+ FluentResults . Result < ( ImmutableArray < T > , ImmutableArray < T > , ImmutableArray < IPackageDependencyInfo > ) > GetLoadablePackages < T > ( ImmutableArray < T > resources , bool errorForPacksMissingDeps = false )
205
208
where T : class , IPackageDependenciesInfo , IPackageInfo , IResourceInfo , IResourceCultureInfo
206
209
{
207
- throw new NotImplementedException ( ) ;
208
210
209
211
// filter optional resources (process later)
210
212
// add back in optional packages that are required by other required packages
211
213
// filter and log required packages that are missing dependencies
212
214
// re-include optionals where dependencies are available
213
215
// return both lists (A normal, B missingDeps).
216
+
217
+ HashSet < IPackageDependencyInfo > missingDeps = new ( ) ;
218
+ var missingDepsBuilder = ImmutableArray . CreateBuilder < T > ( ) ;
219
+
220
+ var reqPacks = resources . Where ( r => ! r . Optional ) . Select ( r => r . OwnerPackage ) . Distinct ( ) . ToImmutableHashSet ( ) ;
221
+ var optPack = resources . Where ( r => r . Optional ) . Select ( r => r . OwnerPackage ) . Distinct ( ) . ToImmutableHashSet ( ) ;
222
+ var req = resources
223
+ . Where ( r => ! r . Optional )
224
+ . Where ( CheckEnvironmentSupported )
225
+ . Where ( r =>
226
+ {
227
+ if ( r . Dependencies . Length == 0 )
228
+ return true ;
229
+
230
+ if ( CheckDependenciesLoaded ( r . Dependencies , out var missingDepsList ) )
231
+ return true ;
232
+
233
+ missingDepsBuilder . Add ( r ) ;
234
+ missingDeps . UnionWith ( missingDepsList ) ;
235
+ return false ;
236
+ } ) ;
237
+ var reqOptionals = resources . Where ( r => r . Optional && optPack . Contains ( r . OwnerPackage ) ) ;
238
+ var notReqOptionals = resources . Where ( r => r . Optional && ! optPack . Contains ( r . OwnerPackage ) ) ;
239
+
240
+ throw new NotImplementedException ( ) ;
214
241
}
215
242
216
243
FluentResults . Result < ImmutableArray < T > > SortByDependencies < T > ( ImmutableArray < T > resources )
@@ -235,7 +262,11 @@ FluentResults.Result<ImmutableArray<T>> SortByDependencies<T>(ImmutableArray<T>
235
262
public FluentResults . Result UnloadPackages ( )
236
263
{
237
264
if ( ! ModUtils . Environment . IsMainThread )
238
- throw new InvalidOperationException ( $ "{ nameof ( UnloadPackages ) } : This method can only be called on the main thread.") ;
265
+ {
266
+ return FluentResults . Result . Fail (
267
+ new ExceptionalError ( new InvalidOperationException ( $ "{ nameof ( UnloadPackages ) } : This method can only be called on the main thread.") )
268
+ . WithMetadata ( MetadataType . ExceptionObject , this ) ) ;
269
+ }
239
270
240
271
var res = new FluentResults . Result ( ) ;
241
272
_contentPackagesModificationsLock . EnterWriteLock ( ) ;
@@ -256,16 +287,15 @@ public FluentResults.Result UnloadPackages()
256
287
public bool CheckDependencyLoaded ( IPackageDependencyInfo info ) =>
257
288
info is not null && IsPackageLoaded ( info . DependencyPackage ) ;
258
289
259
- public bool CheckDependenciesLoaded ( IEnumerable < IPackageDependencyInfo > infos , out IReadOnlyList < IPackageDependencyInfo > missingPackages )
290
+ public bool CheckDependenciesLoaded ( [ NotNull ] IEnumerable < IPackageDependencyInfo > infos , out ImmutableArray < IPackageDependencyInfo > missingPackages )
260
291
{
261
- var missing = new List < IPackageDependencyInfo > ( ) ;
262
- foreach ( IPackageDependencyInfo info in infos )
263
- {
264
- if ( ! CheckDependencyLoaded ( info ) )
265
- missing . Add ( info ) ;
266
- }
267
- missingPackages = missing ;
268
- return missing . Count == 0 ;
292
+ var missing = ImmutableArray . CreateBuilder < IPackageDependencyInfo > ( ) ;
293
+ missing . AddRange ( infos
294
+ . Where ( i => i . DependencyPackage is not null )
295
+ . DistinctBy ( i => i . DependencyPackage )
296
+ . Where ( i => ! CheckDependencyLoaded ( i ) ) ) ;
297
+ missingPackages = missing . MoveToImmutable ( ) ;
298
+ return missingPackages . Length == 0 ;
269
299
}
270
300
271
301
public bool CheckEnvironmentSupported ( IPlatformInfo platform )
0 commit comments