Пример #1
0
        /// <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);
        }
Пример #2
0
 /// <summary>
 /// Creates a new configuration if the config does not exist.
 /// </summary>
 private static void CreateNewConfigIfNotExist()
 {
     if (!LoaderConfigReader.ConfigurationExists())
     {
         LoaderConfigReader.WriteConfiguration(new LoaderConfig());
     }
 }
Пример #3
0
        /// <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();
        }
Пример #4
0
 public void Dispose()
 {
     if (OriginalConfig != null)
     {
         LoaderConfigReader.WriteConfiguration(OriginalConfig);
     }
     else
     {
         File.Delete(LoaderConfigReader.ConfigurationPath());
     }
 }
        /* Before Test */
        public TempLoaderConfigCreator()
        {
            _configReader = new LoaderConfigReader();

            if (_configReader.ConfigurationExists())
            {
                _originalConfig = _configReader.ReadConfiguration();
            }
            else
            {
                _configReader.WriteConfiguration(new LoaderConfig());
            }
        }
Пример #6
0
 private void DisplayFirstLaunchWarningIfNeeded()
 {
     ActionWrappers.ExecuteWithApplicationDispatcher(() =>
     {
         var loaderConfig = IoC.Get <LoaderConfig>();
         if (loaderConfig.FirstLaunch)
         {
             var firstLaunchWindow   = new FirstLaunch();
             firstLaunchWindow.Owner = Window.GetWindow(this);
             firstLaunchWindow.ShowDialog();
             loaderConfig.FirstLaunch = false;
             LoaderConfigReader.WriteConfiguration(loaderConfig);
         }
     });
 }
Пример #7
0
        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());
            }
        }
Пример #9
0
        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;
            }
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
 public void SaveConfig()
 {
     LoaderConfigReader.WriteConfiguration(LoaderConfig);
 }