public void Dispose() { if (OriginalConfig != null) { LoaderConfigReader.WriteConfiguration(OriginalConfig); } else { File.Delete(LoaderConfigReader.ConfigurationPath()); } }
/* 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); }