示例#1
0
 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);
         }
     }
 }
示例#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>
        /// 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);
        }
示例#4
0
 /// <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();
 }
        public void Execute(object parameter)
        {
            // Select EXE
            string exePath = SelectEXEFile();

            if (String.IsNullOrEmpty(exePath) || !File.Exists(exePath))
            {
                return;
            }

            // Get file information and populate initial application details.
            var fileInfo = FileVersionInfo.GetVersionInfo(exePath);
            IApplicationConfig config = new ApplicationConfig(Path.GetFileName(fileInfo.FileName), fileInfo.ProductName, exePath);

            // Set AppName if empty & Ensure no duplicate ID.
            if (String.IsNullOrEmpty(config.AppName))
            {
                config.AppName = config.AppId;
            }

            UpdateIdIfDuplicate(config);

            // Get paths.
            string applicationConfigDirectory = new LoaderConfigReader().ReadConfiguration().ApplicationConfigDirectory;
            string applicationDirectory       = Path.Combine(applicationConfigDirectory, config.AppId);
            string applicationConfigFile      = Path.Combine(applicationDirectory, ApplicationConfig.ConfigFileName);

            // Write file to disk.
            Directory.CreateDirectory(applicationDirectory);
            ApplicationConfig.WriteConfiguration(applicationConfigFile, (ApplicationConfig)config);

            // Select this config.
            _lastConfigFileLocation = applicationConfigFile;
            _addAppViewModel.MainPageViewModel.ApplicationsChanged += Handler;
        }
        /// <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);
        }
示例#7
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();
        }
示例#8
0
        /// <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));
        }
示例#9
0
        /// <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));
        }
示例#10
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());
            }
        }
示例#12
0
        /// <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();
            }
        }
示例#13
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);
         }
     });
 }
示例#14
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;
            }
        }
示例#15
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);
        }
示例#16
0
 public void SaveConfig()
 {
     LoaderConfigReader.WriteConfiguration(LoaderConfig);
 }
示例#17
0
 /* Before Test */
 public LoaderConfigReaderTest()
 {
     _configReader        = new LoaderConfigReader();
     _loaderConfigCreator = new TempLoaderConfigCreator();
 }