/// <summary> /// Downloads a specific file. /// </summary> public async Task DownloadAndExtract(DownloadProgressChangedEventHandler progressChanged) { // Start the modification download. byte[] data; using (WebClient client = new WebClient()) { client.DownloadProgressChanged += progressChanged; data = await client.DownloadDataTaskAsync(Uri); } /* Extract to Temp Directory */ string temporaryDirectory = GetTemporaryDirectory(); var archiveExtractor = new ArchiveExtractor(); await archiveExtractor.ExtractPackageAsync(data, temporaryDirectory); /* Get name of package. */ var configReader = new ConfigReader <ModConfig>(); var configs = configReader.ReadConfigurations(temporaryDirectory, ModConfig.ConfigFileName); var loaderConfig = LoaderConfigReader.ReadConfiguration(); foreach (var config in configs) { string configId = config.Object.ModId; string configDirectory = Path.GetDirectoryName(config.Path); string targetDirectory = Path.Combine(loaderConfig.ModConfigDirectory, configId); IOEx.MoveDirectory(configDirectory, targetDirectory); } Directory.Delete(temporaryDirectory, true); }
/// <summary> /// Sets up viewmodels to be used in the individual mod loader pages. /// </summary> private static async Task SetupViewModelsAsync() { _ = Task.Run(BasicDllInjector.PreloadAddresses); // Fire and Forget var loaderConfig = LoaderConfigReader.ReadConfiguration(); IoC.Kernel.Bind <LoaderConfig>().ToConstant(loaderConfig); IoC.GetConstant <MainPageViewModel>(); IoC.GetConstant <AddAppViewModel>(); // Consumes MainPageViewModel, make sure it goes after it. IoC.GetConstant <ManageModsViewModel>(); // Consumes MainPageViewModel, LoaderConfig IoC.GetConstant <SettingsPageViewModel>(); // Consumes ManageModsViewModel, AddAppViewModel try { var helper = await NugetHelper.FromSourceUrlAsync(SharedConstants.NuGetApiEndpoint); IoC.Kernel.Rebind <NugetHelper>().ToConstant(helper); IoC.GetConstant <DownloadModsViewModel>(); // Consumes ManageModsViewModel, NugetHelper } catch (Exception) { // Probably no internet access. } /* Set loader DLL path. */ SetLoaderPaths(loaderConfig, Path.GetDirectoryName(Environment.GetCommandLineArgs()[0])); LoaderConfigReader.WriteConfiguration(loaderConfig); }
private string GetBootstrapperPath(Process process) { // If the LoaderConfig is not bound, read it from disk. if (!IoC.IsExplicitlyBound <LoaderConfig>()) { if (process.Is64Bit()) { return(LoaderConfigReader.ReadConfiguration().Bootstrapper64Path); } else { return(LoaderConfigReader.ReadConfiguration().Bootstrapper32Path); } } else { if (process.Is64Bit()) { return(IoC.Get <LoaderConfig>().Bootstrapper64Path); } else { return(IoC.Get <LoaderConfig>().Bootstrapper32Path); } } }
/// <summary> /// Loader constructor used for testing the loader. /// </summary> public Loader(bool isTesting = false) { IsTesting = isTesting; LoaderConfig = LoaderConfigReader.ReadConfiguration(); Manager = new PluginManager(this); Console = new Console(); }
/// <summary> /// Creates a new configuration if the config does not exist. /// </summary> private static LoaderConfig CreateNewConfigIfNotExist() { var configReader = new LoaderConfigReader(); if (!configReader.ConfigurationExists()) configReader.WriteConfiguration(new LoaderConfig()); return configReader.ReadConfiguration(); }
/// <summary> /// Finds all mods on the filesystem, parses them and returns a list of all mods. /// </summary> /// <param name="modDirectory">(Optional) Directory containing all of the mods.</param> public static List <PathGenericTuple <ModConfig> > GetAllMods(string modDirectory = null, CancellationToken token = default) { if (modDirectory == null) { modDirectory = LoaderConfigReader.ReadConfiguration().ModConfigDirectory; } return(_modConfigReader.ReadConfigurations(modDirectory, ConfigFileName, token)); }
/// <summary> /// Finds all apps on the filesystem, parses them and returns a list of /// all apps. /// </summary> /// <param name="appDirectory">(Optional) Directory containing all of the applications.</param> public static List <PathGenericTuple <ApplicationConfig> > GetAllApplications(string appDirectory = null, CancellationToken token = default) { if (appDirectory == null) { appDirectory = LoaderConfigReader.ReadConfiguration().ApplicationConfigDirectory; } return(_appConfigReader.ReadConfigurations(appDirectory, ConfigFileName, token)); }
/* Before Test */ public TempLoaderConfigCreator() { _configReader = new LoaderConfigReader(); if (_configReader.ConfigurationExists()) { _originalConfig = _configReader.ReadConfiguration(); } else { _configReader.WriteConfiguration(new LoaderConfig()); } }
/// <summary> /// Initialize loader used by the actual loader. /// </summary> public Loader() { IsTesting = false; LoaderConfig = LoaderConfigReader.ReadConfiguration(); Manager = new PluginManager(this); Console = new Console(); if (LoaderConfig.ShowConsole) { Console.ShowConsole(); Console.PrintBanner(); } }
public void ReadWriteConfig() { // Read back config first. (It will exist because of constructor) var config = new LoaderConfig(); // Add some random app support entries. config.ModSupportMatrix.Add("reloaded.sample.app", new string[] { "sample.mod.a", "sample.mod.b" }); config.ApplicationConfigDirectory = "Apps"; config.ModConfigDirectory = "Mods"; config.PluginConfigDirectory = "Plugins"; config.InstallDirectory = Environment.CurrentDirectory; // Write and read back the config. _configReader.WriteConfiguration(config); var newConfig = _configReader.ReadConfiguration(); Assert.Equal(config, newConfig); }
/* After Test */ public void Dispose() { // Delete all temp loader directories. var currentLoaderConfig = _configReader.ReadConfiguration(); TryCatchIgnoreCode(() => Directory.Delete(currentLoaderConfig.ApplicationConfigDirectory, true)); TryCatchIgnoreCode(() => Directory.Delete(currentLoaderConfig.ModConfigDirectory, true)); TryCatchIgnoreCode(() => Directory.Delete(currentLoaderConfig.PluginConfigDirectory, true)); if (_originalConfig != null) { _configReader.WriteConfiguration(_originalConfig); } else { File.Delete(_configReader.ConfigurationPath()); } }
public TestData() { // Backup config and override on filesystem with new. bool configExists = File.Exists(LoaderConfigReader.ConfigurationPath()); if (configExists) { OriginalConfig = LoaderConfigReader.ReadConfiguration(); } TestConfig = MakeTestConfig(); LoaderConfigReader.WriteConfiguration(TestConfig); try { // Populate configurations. ModConfigurations = ModConfig.GetAllMods().Select(x => x.Object).ToArray(); AppConfigurations = ApplicationConfig.GetAllApplications().Select(x => x.Object).ToArray(); ThisApplication = new ApplicationConfig(IdOfThisApp, "Reloaded Mod Loader Tests", Process.GetCurrentProcess().GetExecutablePath(), new[] { TestModConfigA.ModId, TestModConfigB.ModId, TestModConfigD.ModId }); ConfigurationPathOfThisApp = Path.Combine(TestConfig.ApplicationConfigDirectory, IdOfThisApp, ApplicationConfig.ConfigFileName); ApplicationConfig.WriteConfiguration(ConfigurationPathOfThisApp, ThisApplication); // Populate nonexisting dependencies. NonexistingDependencies.Add(TestModB.Program.NonexistingDependencyName); NonexistingDependencies.Add(TestModC.Program.NonexistingDependencyName); } catch (Exception) { if (OriginalConfig != null) { LoaderConfigReader.WriteConfiguration(OriginalConfig); } throw; } }
/// <summary> /// Cleans up App/Loader/Mod Configurations from nonexisting /// references such as removed mods. /// </summary> private static void CleanupConfigurations(LoaderConfig loaderConfig) { var modConfigLoader = new ConfigLoader<ModConfig>(); var appConfigLoader = new ConfigLoader<ApplicationConfig>(); var loaderConfigReader = new LoaderConfigReader(); foreach (var modConfiguration in modConfigLoader.ReadConfigurations(loaderConfig.ModConfigDirectory, ModConfig.ConfigFileName)) { modConfiguration.Object.CleanupConfig(modConfiguration.Path); modConfigLoader.WriteConfiguration(modConfiguration.Path, modConfiguration.Object); } foreach (var appConfiguration in appConfigLoader.ReadConfigurations(loaderConfig.ApplicationConfigDirectory, ApplicationConfig.ConfigFileName)) { appConfiguration.Object.CleanupConfig(appConfiguration.Path); appConfigLoader.WriteConfiguration(appConfiguration.Path, appConfiguration.Object); } var loaderConfiguration = loaderConfigReader.ReadConfiguration(); loaderConfiguration.CleanupConfig(loaderConfigReader.ConfigurationPath()); loaderConfigReader.WriteConfiguration(loaderConfiguration); }