Skip to content

Commit

Permalink
Automatically got all file bundle implementations via reflection.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Nov 30, 2024
1 parent f7e894a commit 4f89e99
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 82 deletions.
37 changes: 37 additions & 0 deletions FinModelUtility/Fin/Fin/src/util/types/TypesUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;

using fin.util.asserts;
using fin.util.linq;

namespace fin.util.types;

public static class TypesUtil {
public static IEnumerable<Type> GetAllImplementationTypes<TInterface>()
=> AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(typeof(TInterface).IsAssignableFrom)
.Where(t => t is {
IsAbstract: false, ContainsGenericParameters: false
});

public static IEnumerable<TInterface>
InstantiateAllImplementationsWithDefaultConstructor<TInterface>()
=> GetAllImplementationTypes<TInterface>()
.SelectWhere<Type, TInterface>(
TryToInstantiateWIthDefaultConstructor_);

private static bool TryToInstantiateWIthDefaultConstructor_<TInterface>(
Type type,
out TInterface value) {
var constructor = type.GetConstructor([]);
if (constructor == null) {
value = default;
return false;
}

value = constructor.Invoke([]).AssertAsA<TInterface>();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using fin.model.io;
using fin.model.io.exporters;
using fin.model.io.exporters.assimp.indirect;
using fin.util.types;

namespace uni.cli;

Expand All @@ -14,10 +15,8 @@ public static void Run(string[] args,
Action? runDebug = null) {
IEnumerable<Error>? errors = null;

var massExporterOptionTypes =
AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(s => s.GetTypes())
.Where(typeof(IMassExporterOptions).IsAssignableFrom);
var massExporterOptionTypes
= TypesUtil.GetAllImplementationTypes<IMassExporterOptions>();

var plugins = PluginUtil.Plugins;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,91 +1,16 @@
using fin.io.bundles;
using fin.util.progress;
using fin.util.types;

using uni.config;
using uni.games.animal_crossing;
using uni.games.animal_crossing_wild_world;
using uni.games.battalion_wars_1;
using uni.games.battalion_wars_2;
using uni.games.chibi_robo;
using uni.games.custom_robo;
using uni.games.dead_space_1;
using uni.games.dead_space_2;
using uni.games.dead_space_3;
using uni.games.doshin_the_giant;
using uni.games.ever_oasis;
using uni.games.glover;
using uni.games.great_ace_attorney;
using uni.games.halo_wars;
using uni.games.kirby_air_ride;
using uni.games.luigis_mansion;
using uni.games.luigis_mansion_3d;
using uni.games.majoras_mask_3d;
using uni.games.mario_kart_double_dash;
using uni.games.midnight_club_2;
using uni.games.nintendogs_labrador_and_friends;
using uni.games.ocarina_of_time;
using uni.games.ocarina_of_time_3d;
using uni.games.odyssey_of_hyrule;
using uni.games.paper_mario_directors_cut;
using uni.games.paper_mario_the_thousand_year_door;
using uni.games.pikmin_1;
using uni.games.pikmin_2;
using uni.games.professor_layton_vs_phoenix_wright;
using uni.games.soulcalibur_ii;
using uni.games.super_mario_64;
using uni.games.super_mario_64_ds;
using uni.games.super_mario_sunshine;
using uni.games.super_smash_bros_melee;
using uni.games.timesplitters_2;
using uni.games.twilight_princess;
using uni.games.vrwdw;
using uni.games.wind_waker;

namespace uni.games;

public class RootFileBundleGatherer {
public IFileBundleDirectory GatherAllFiles(
IMutablePercentageProgress mutablePercentageProgress) {
var gatherers = new IAnnotatedFileBundleGatherer[] {
new AnimalCrossingFileBundleGatherer(),
new AnimalCrossingWildWorldFileBundleGatherer(),
new BattalionWars1FileBundleGatherer(),
new BattalionWars2FileBundleGatherer(),
new ChibiRoboFileBundleGatherer(),
new CustomRoboFileBundleGatherer(),
new DeadSpace1FileBundleGatherer(),
new DeadSpace2FileBundleGatherer(),
new DeadSpace3FileBundleGatherer(),
new DoshinTheGiantFileBundleGatherer(),
new EverOasisFileBundleGatherer(),
new GloverFileBundleGatherer(),
new GreatAceAttorneyFileBundleGatherer(),
new HaloWarsFileBundleGatherer(),
new KirbyAirRideFileBundleGatherer(),
new LuigisMansionFileBundleGatherer(),
new LuigisMansion3dFileBundleGatherer(),
new MajorasMask3dFileBundleGatherer(),
new MarioKartDoubleDashFileBundleGatherer(),
new MidnightClub2FileBundleGatherer(),
new NintendogsLabradorAndFriendsFileBundleGatherer(),
new OcarinaOfTimeFileBundleGatherer(),
new OcarinaOfTime3dFileBundleGatherer(),
new OdysseyOfHyruleFileBundleGatherer(),
new PaperMarioDirectorsCutFileBundleGatherer(),
new PaperMarioTheThousandYearDoorFileBundleGatherer(),
new Pikmin1FileBundleGatherer(),
new Pikmin2FileBundleGatherer(),
new ProfessorLaytonVsPhoenixWrightFileBundleGatherer(),
new SoulcaliburIIFileBundleGatherer(),
new SuperMario64DsFileBundleGatherer(),
new SuperMario64FileBundleGatherer(),
new SuperMarioSunshineFileBundleGatherer(),
new SuperSmashBrosMeleeFileBundleGatherer(),
new Timesplitters2FileBundleGatherer(),
new TwilightPrincessFileBundleGatherer(),
new VrwdwFileBundleGatherer(),
new WindWakerFileBundleGatherer(),
};
var gatherers
= TypesUtil.InstantiateAllImplementationsWithDefaultConstructor<IAnnotatedFileBundleGatherer>();

IAnnotatedFileBundleGatherer rootGatherer;
if (Config.Instance.Extractor.ExtractRomsInParallel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using fin.io.bundles;
using fin.util.progress;

using SceneGate.Ekona.Containers.Rom;

using uni.platforms;

using Yarhl.FileSystem;

namespace uni.games.phantom_hourglass;

public class PhantomHourglassFileBundleGatherer
: IAnnotatedFileBundleGatherer {
public void GatherFileBundles(
IFileBundleOrganizer organizer,
IMutablePercentageProgress mutablePercentageProgress) {
if (!DirectoryConstants.ROMS_DIRECTORY.TryToGetExistingFile(
"phantom_hourglass.nds",
out var phantomHourglassRom)) {
return;
}

using var game = NodeFactory.FromFile(phantomHourglassRom.FullPath);
game.TransformWith<Binary2NitroRom>();

var names = new List<string>();

foreach (var node in Navigator.IterateNodes(game)) {
names.Add(node.Name);
}
}
}

0 comments on commit 4f89e99

Please sign in to comment.