/// <summary> /// Loads the factories for games that have been previously detected as installed. /// </summary> /// <param name="supportedGameModes">A registry containing the factories for all supported game modes.</param> /// <param name="environmentInfo">The application's environment info.</param> /// <returns>A registry containing all of the game mode factories for games that were previously detected as installed.</returns> public static GameModeRegistry LoadInstalledGameModes(GameModeRegistry supportedGameModes, EnvironmentInfo environmentInfo) { Trace.TraceInformation("Loading Game Mode Factories for Installed Games..."); Trace.Indent(); var installedGameModes = new GameModeRegistry(); foreach (var gameId in environmentInfo.Settings.InstalledGames) { Trace.Write($"Loading {gameId}: "); if (supportedGameModes.IsRegistered(gameId)) { Trace.WriteLine("Supported"); installedGameModes.RegisterGameMode(supportedGameModes.GetGameMode(gameId)); } else { Trace.WriteLine("Not Supported"); } } Trace.Unindent(); return(installedGameModes); }
/// <summary> /// Searches for game mode factories in the specified path, and loads /// any factories that are found into a registry. /// </summary> /// <returns>A registry containing all of the discovered game mode factories.</returns> public static GameModeRegistry DiscoverSupportedGameModes(EnvironmentInfo p_eifEnvironmentInfo) { Trace.TraceInformation("Discovering Game Mode Factories..."); Trace.Indent(); string strGameModesPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "GameModes"); Trace.TraceInformation("Looking in: {0}", strGameModesPath); GameModeRegistry gmrRegistry = new GameModeRegistry(); string[] strAssemblies = Directory.GetFiles(strGameModesPath, "*.dll"); foreach (string strAssembly in strAssemblies) { Trace.TraceInformation("Checking: {0}", Path.GetFileName(strAssembly)); Trace.Indent(); Assembly asmGameMode = Assembly.LoadFrom(strAssembly); try { Type[] tpeTypes = asmGameMode.GetExportedTypes(); foreach (Type tpeType in tpeTypes) { if (typeof(IGameModeFactory).IsAssignableFrom(tpeType) && !tpeType.IsAbstract) { Trace.TraceInformation("Initializing: {0}", tpeType.FullName); Trace.Indent(); ConstructorInfo cifConstructor = tpeType.GetConstructor(new Type[] { typeof(IEnvironmentInfo) }); if (cifConstructor == null) { Trace.TraceInformation("No constructor accepting one argument of type IEnvironmentInfo found."); Trace.Unindent(); continue; } IGameModeFactory gmfGameModeFactory = (IGameModeFactory)cifConstructor.Invoke(new object[] { p_eifEnvironmentInfo }); gmrRegistry.RegisterGameMode(gmfGameModeFactory); Trace.Unindent(); } } } catch (FileNotFoundException e) { Trace.TraceError(String.Format("Cannot load {0}: cannot find dependency {1}", strAssembly, e.FileName)); //some dependencies were missing, so we couldn't load the assembly // given that these are plugins we don't have control over the dependecies: // we may not even know what they (we can get their name, but if it's a custom // dll not part of the client code base, we can't provide it even if we wanted to) // there's nothing we can do, so simply skip the assembly } Trace.Unindent(); } Trace.Unindent(); return(gmrRegistry); }
/// <summary> /// Searches for game mode factories in the specified path, and loads /// any factories that are found into a registry. /// </summary> /// <returns>A registry containing all of the discovered game mode factories.</returns> public static GameModeRegistry DiscoverSupportedGameModes(EnvironmentInfo p_eifEnvironmentInfo) { Trace.TraceInformation("Discovering Game Mode Factories..."); Trace.Indent(); string strGameModesPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "GameModes"); Trace.TraceInformation("Looking in: {0}", strGameModesPath); GameModeRegistry gmrRegistry = new GameModeRegistry(); string[] strAssemblies = Directory.GetFiles(strGameModesPath, "*.dll"); foreach (string strAssembly in strAssemblies) { Trace.TraceInformation("Checking: {0}", Path.GetFileName(strAssembly)); Trace.Indent(); Assembly asmGameMode = Assembly.LoadFrom(strAssembly); try { Type[] tpeTypes = asmGameMode.GetExportedTypes(); foreach (Type tpeType in tpeTypes) { if (typeof(IGameModeFactory).IsAssignableFrom(tpeType) && !tpeType.IsAbstract) { Trace.TraceInformation("Initializing: {0}", tpeType.FullName); Trace.Indent(); ConstructorInfo cifConstructor = tpeType.GetConstructor(new Type[] { typeof(IEnvironmentInfo) }); if (cifConstructor == null) { Trace.TraceInformation("No constructor accepting one argument of type IEnvironmentInfo found."); Trace.Unindent(); continue; } IGameModeFactory gmfGameModeFactory = (IGameModeFactory)cifConstructor.Invoke(new object[] { p_eifEnvironmentInfo }); gmrRegistry.RegisterGameMode(gmfGameModeFactory); Trace.Unindent(); } } } catch (FileNotFoundException e) { Trace.TraceError(String.Format("Cannot load {0}: cannot find dependency {1}", strAssembly, e.FileName)); //some dependencies were missing, so we couldn't load the assembly // given that these are plugins we don't have control over the dependecies: // we may not even know what they (we can get their name, but if it's a custom // dll not part of the client code base, we can't provide it even if we wanted to) // there's nothing we can do, so simply skip the assembly } Trace.Unindent(); } Trace.Unindent(); return gmrRegistry; }
/// <summary> /// Loads the factories for games that have been previously detected as installed. /// </summary> /// <param name="p_gmrSupportedGameModes">A registry containing the factories for all supported game modes.</param> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <returns>A registry containing all of the game mode factories for games that were previously detected as installed.</returns> public static GameModeRegistry LoadInstalledGameModes(GameModeRegistry p_gmrSupportedGameModes, EnvironmentInfo p_eifEnvironmentInfo) { Trace.TraceInformation("Loading Game Mode Factories for Installed Games..."); Trace.Indent(); GameModeRegistry gmrInstalled = new GameModeRegistry(); foreach (string strGameId in p_eifEnvironmentInfo.Settings.InstalledGames) { Trace.Write(String.Format("Loading {0}: ", strGameId)); if (p_gmrSupportedGameModes.IsRegistered(strGameId)) { Trace.WriteLine("Supported"); gmrInstalled.RegisterGameMode(p_gmrSupportedGameModes.GetGameMode(strGameId)); } else Trace.WriteLine("Not Supported"); } Trace.Unindent(); return gmrInstalled; }
/// <summary> /// Loads the factories for games that have been previously detected as installed. /// </summary> /// <param name="p_gmrSupportedGameModes">A registry containing the factories for all supported game modes.</param> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <returns>A registry containing all of the game mode factories for games that were previously detected as installed.</returns> public static GameModeRegistry LoadInstalledGameModes(GameModeRegistry p_gmrSupportedGameModes, EnvironmentInfo p_eifEnvironmentInfo) { Trace.TraceInformation("Loading Game Mode Factories for Installed Games..."); Trace.Indent(); GameModeRegistry gmrInstalled = new GameModeRegistry(); foreach (string strGameId in p_eifEnvironmentInfo.Settings.InstalledGames) { Trace.Write(String.Format("Loading {0}: ", strGameId)); if (p_gmrSupportedGameModes.IsRegistered(strGameId)) { Trace.WriteLine("Supported"); gmrInstalled.RegisterGameMode(p_gmrSupportedGameModes.GetGameMode(strGameId)); } else { Trace.WriteLine("Not Supported"); } } Trace.Unindent(); return(gmrInstalled); }
/// <summary> /// A simple constructor that initializes the object with the given dependencies. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_gmrInstalledGames">The registry of insalled games.</param> /// <param name="p_gmdGameMode">The game mode currently being managed.</param> /// <param name="p_mrpModRepository">The repository we are logging in to.</param> /// <param name="p_dmtMonitor">The download monitor to use to track task progress.</param> /// <param name="p_umgUpdateManager">The update manager to use to perform updates.</param> /// <param name="p_mmgModManager">The <see cref="ModManager"/> to use to manage mods.</param> /// <param name="p_pmgPluginManager">The <see cref="PluginManager"/> to use to manage plugins.</param> public MainFormVM(IEnvironmentInfo p_eifEnvironmentInfo, GameModeRegistry p_gmrInstalledGames, IGameMode p_gmdGameMode, IModRepository p_mrpModRepository, DownloadMonitor p_dmtMonitor, ActivateModsMonitor p_ammMonitor, UpdateManager p_umgUpdateManager, ModManager p_mmgModManager, IPluginManager p_pmgPluginManager) { EnvironmentInfo = p_eifEnvironmentInfo; GameMode = p_gmdGameMode; GameMode.GameLauncher.GameLaunching += new CancelEventHandler(GameLauncher_GameLaunching); ModManager = p_mmgModManager; ModRepository = p_mrpModRepository; UpdateManager = p_umgUpdateManager; ModManagerVM = new ModManagerVM(p_mmgModManager, p_eifEnvironmentInfo.Settings, p_gmdGameMode.ModeTheme); DownloadMonitorVM = new DownloadMonitorVM(p_dmtMonitor, p_eifEnvironmentInfo.Settings, p_mmgModManager, p_mrpModRepository); ModActivationMonitor = p_ammMonitor; ActivateModsMonitorVM = new ActivateModsMonitorVM(p_ammMonitor, p_eifEnvironmentInfo.Settings, p_mmgModManager); if (GameMode.UsesPlugins) PluginManagerVM = new PluginManagerVM(p_pmgPluginManager, p_eifEnvironmentInfo.Settings, p_gmdGameMode, p_ammMonitor); HelpInfo = new HelpInformation(p_eifEnvironmentInfo); GeneralSettingsGroup gsgGeneralSettings = new GeneralSettingsGroup(p_eifEnvironmentInfo); foreach (IModFormat mftFormat in p_mmgModManager.ModFormats) gsgGeneralSettings.AddFileAssociation(mftFormat.Extension, mftFormat.Name); ModOptionsSettingsGroup mosModOptions = new ModOptionsSettingsGroup(p_eifEnvironmentInfo); List<ISettingsGroupView> lstSettingGroups = new List<ISettingsGroupView>(); lstSettingGroups.Add(new GeneralSettingsPage(gsgGeneralSettings)); lstSettingGroups.Add(new ModOptionsPage(mosModOptions)); DownloadSettingsGroup dsgDownloadSettings = new DownloadSettingsGroup(p_eifEnvironmentInfo, ModRepository); lstSettingGroups.Add(new DownloadSettingsPage(dsgDownloadSettings)); if (p_gmdGameMode.SettingsGroupViews != null) lstSettingGroups.AddRange(p_gmdGameMode.SettingsGroupViews); SettingsFormVM = new SettingsFormVM(p_gmdGameMode, p_eifEnvironmentInfo, lstSettingGroups); UpdateCommand = new Command("Update", String.Format("Update {0}", EnvironmentInfo.Settings.ModManagerName), UpdateProgramme); LogoutCommand = new Command("Logout", "Logout", Logout); List<Command> lstChangeGameModeCommands = new List<Command>(); List<IGameModeDescriptor> lstSortedModes = new List<IGameModeDescriptor>(p_gmrInstalledGames.RegisteredGameModes); lstSortedModes.Sort((x, y) => x.Name.CompareTo(y.Name)); foreach (IGameModeDescriptor gmdInstalledGame in lstSortedModes) { string strId = gmdInstalledGame.ModeId; string strName = gmdInstalledGame.Name; string strDescription = String.Format("Change game to {0}", gmdInstalledGame.Name); Image imgCommandIcon = new Icon(gmdInstalledGame.ModeTheme.Icon, 32, 32).ToBitmap(); lstChangeGameModeCommands.Add(new Command(strId, strName, strDescription, imgCommandIcon, () => ChangeGameMode(strId), true)); } lstChangeGameModeCommands.Add(new Command("Change Default Game...", "Change Default Game", () => ChangeGameMode(CHANGE_DEFAULT_GAME_MODE))); lstChangeGameModeCommands.Add(new Command("Rescan Installed Games...", "Rescan Installed Games", () => ChangeGameMode(RESCAN_INSTALLED_GAMES))); ChangeGameModeCommands = lstChangeGameModeCommands; }
/// <summary> /// Searches for game mode factories in the specified path, and loads /// any factories that are found into a registry. /// </summary> /// <returns>A registry containing all of the discovered game mode factories.</returns> public static GameModeRegistry DiscoverSupportedGameModes(EnvironmentInfo environmentInfo) { Trace.TraceInformation("Discovering Game Mode Factories..."); Trace.Indent(); var gameModesPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "GameModes"); if (!Directory.Exists(gameModesPath)) { Directory.CreateDirectory(gameModesPath); } Trace.TraceInformation("Looking in: {0}", gameModesPath); var assemblies = Directory.GetFiles(gameModesPath, "*.dll"); //If there are no assemblies detected then an exception must be thrown //to prevent a divide by zero exception further along if (!assemblies.Any()) { var debugMessage = string.Empty; #if DEBUG debugMessage = @"Compile the Game Modes directory in the solution."; #endif throw new GameModeRegistryException(gameModesPath, debugMessage); } var registry = new GameModeRegistry(); foreach (var assembly in assemblies) { Trace.TraceInformation("Checking: {0}", Path.GetFileName(assembly)); Trace.Indent(); var gameMode = Assembly.LoadFrom(assembly); try { var types = gameMode.GetExportedTypes(); foreach (var type in types) { if (!typeof(IGameModeFactory).IsAssignableFrom(type) || type.IsAbstract) { continue; } Trace.TraceInformation("Initializing: {0}", type.FullName); Trace.Indent(); var constructor = type.GetConstructor(new Type[] { typeof(IEnvironmentInfo) }); if (constructor == null) { Trace.TraceInformation("No constructor accepting one argument of type IEnvironmentInfo found."); Trace.Unindent(); continue; } var gmfGameModeFactory = (IGameModeFactory)constructor.Invoke(new object[] { environmentInfo }); registry.RegisterGameMode(gmfGameModeFactory); Trace.Unindent(); } } catch (FileNotFoundException e) { Trace.TraceError($"Cannot load {assembly}: cannot find dependency {e.FileName}"); // some dependencies were missing, so we couldn't load the assembly // given that these are plugins we don't have control over the dependencies: // we may not even know what they (we can get their name, but if it's a custom // dll not part of the client code base, we can't provide it even if we wanted to) // there's nothing we can do, so simply skip the assembly } Trace.Unindent(); } Trace.Unindent(); return(registry); }
/// <summary> /// A simple constructor that initializes the object with the given dependencies. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_gdvGameDetector">The discoverer to use to find the game installation path.</param> /// <param name="p_gmrSupportedGameModes">The list of supported game modes.</param> public GameDetectionVM(IEnvironmentInfo p_eifEnvironmentInfo, GameDiscoverer p_gdvGameDetector, GameModeRegistry p_gmrSupportedGameModes) { EnvironmentInfo = p_eifEnvironmentInfo; GameDetector = p_gdvGameDetector; SupportedGameModes = p_gmrSupportedGameModes; }
/// <summary> /// Gets a registry of installed game modes. /// </summary> /// <param name="p_gmrSupportedGameModes">The games modes supported by the mod manager.</param> /// <returns>A registry of installed game modes.</returns> protected GameModeRegistry GetInstalledGameModes(GameModeRegistry p_gmrSupportedGameModes) { if (!m_eifEnvironmentInfo.Settings.InstalledGamesDetected) { GameDiscoverer gdrGameDetector = new GameDiscoverer(); GameDetectionVM vmlGameDetection = new GameDetectionVM(m_eifEnvironmentInfo, gdrGameDetector, p_gmrSupportedGameModes); GameDetectionForm frmGameDetector = new GameDetectionForm(vmlGameDetection); gdrGameDetector.Find(p_gmrSupportedGameModes.RegisteredGameModeFactories); frmGameDetector.ShowDialog(); if (gdrGameDetector.Status != TaskStatus.Complete) return null; if (gdrGameDetector.DiscoveredGameModes.Count == 0) return null; m_eifEnvironmentInfo.Settings.InstalledGames.Clear(); Int32 j = 0; foreach (GameDiscoverer.GameInstallData gidGameMode in gdrGameDetector.DiscoveredGameModes) { if ((gidGameMode != null) && (gidGameMode.GameMode != null)) { IGameModeFactory gmfGameModeFactory = p_gmrSupportedGameModes.GetGameMode(gidGameMode.GameMode.ModeId); m_eifEnvironmentInfo.Settings.InstallationPaths[gidGameMode.GameMode.ModeId] = gmfGameModeFactory.GetInstallationPath(gidGameMode.GameInstallPath); m_eifEnvironmentInfo.Settings.ExecutablePaths[gidGameMode.GameMode.ModeId] = gmfGameModeFactory.GetExecutablePath(gidGameMode.GameInstallPath); m_eifEnvironmentInfo.Settings.InstalledGames.Add(gidGameMode.GameMode.ModeId); } else { MessageBox.Show(string.Format("An error occured during the scan of the game {0} : {1}", gdrGameDetector.DiscoveredGameModes[j].GameMode.ModeId, Environment.NewLine + "The object GameMode is NULL")); } j++; } m_eifEnvironmentInfo.Settings.InstalledGamesDetected = true; m_eifEnvironmentInfo.Settings.Save(); } GameModeRegistry gmrInstalledGameModes = GameModeRegistry.LoadInstalledGameModes(p_gmrSupportedGameModes, m_eifEnvironmentInfo); return gmrInstalledGameModes; }
/// <summary> /// A simple constructor that initializes the object with the given dependencies. /// </summary> /// <param name="p_gmrSupportedGameModes">The games modes supported by the mod manager.</param> /// <param name="p_gmrInstalledGameModes">The game modes factories for installed games.</param> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> public GameModeSelector(GameModeRegistry p_gmrSupportedGameModes, GameModeRegistry p_gmrInstalledGameModes, IEnvironmentInfo p_eifEnvironmentInfo) { SupportedGameModes = p_gmrSupportedGameModes; InstalledGameModes = p_gmrInstalledGameModes; EnvironmentInfo = p_eifEnvironmentInfo; }