Esempio n. 1
0
    /// <summary>
    /// Searches for the application configuration corresponding to the current
    /// executing application
    /// </summary>
    private IApplicationConfig FindThisApplication()
    {
        var configurations = ApplicationConfig.GetAllApplications(LoaderConfig.GetApplicationConfigDirectory());
        var fullPath       = NormalizePath(Environment.CurrentProcessLocation.Value);

        Logger.LogWriteLineAsync($"Current Process Location: {fullPath}");

        foreach (var configuration in configurations)
        {
            var application = configuration.Config;
            var appLocation = ApplicationConfig.GetAbsoluteAppLocation(configuration);

            if (string.IsNullOrEmpty(appLocation))
            {
                continue;
            }

            var fullAppLocation = NormalizePath(appLocation);
            if (fullAppLocation.Equals(fullPath, StringComparison.OrdinalIgnoreCase))
            {
                return(application);
            }
        }

        return(null);
    }
Esempio n. 2
0
        public TestData()
        {
            // Backup config and override on filesystem with new.
            OriginalConfig = IConfig <LoaderConfig> .FromPathOrDefault(Paths.LoaderConfigPath);

            TestConfig = MakeTestConfig();
            IConfig <LoaderConfig> .ToPath(TestConfig, Paths.LoaderConfigPath);

            try
            {
                // Populate configurations.
                ModConfigurations = ModConfig.GetAllMods().Select(x => x.Config).ToArray();
                AppConfigurations = ApplicationConfig.GetAllApplications().Select(x => x.Config).ToArray();

                ThisApplication = new ApplicationConfig(IdOfThisApp,
                                                        "Reloaded Mod Loader Tests",
                                                        Environment.CurrentProcessLocation.Value,
                                                        new[] { TestModConfigA.ModId, TestModConfigB.ModId, TestModConfigD.ModId });

                ConfigurationPathOfThisApp = Path.Combine(TestConfig.ApplicationConfigDirectory, IdOfThisApp, ApplicationConfig.ConfigFileName);
                IConfig <ApplicationConfig> .ToPath(ThisApplication, ConfigurationPathOfThisApp);

                // Populate nonexisting dependencies.
                NonexistingDependencies.Add(TestModB.Program.NonexistingDependencyName);
                NonexistingDependencies.Add(TestModC.Program.NonexistingDependencyName);
            }
            catch (Exception)
            {
                IConfig <LoaderConfig> .ToPath(OriginalConfig, Paths.LoaderConfigPath);

                throw;
            }
        }
Esempio n. 3
0
    private static void LaunchApplicationAndExit(string applicationToLaunch)
    {
        // Acquire arguments
        var loaderConfig = IoC.Get <LoaderConfig>();

        loaderConfig.UpdatePaths(Paths.CurrentProgramFolder, Resources.ErrorLoaderNotFound.Get());
        IConfig <LoaderConfig> .ToPath(loaderConfig, Paths.LoaderConfigPath);

        _commandLineArguments.TryGetValue(Constants.ParameterArguments, out var arguments);
        arguments ??= "";
        applicationToLaunch = Path.GetFullPath(applicationToLaunch);

        var application = ApplicationConfig.GetAllApplications(loaderConfig.GetApplicationConfigDirectory()).FirstOrDefault(x => ApplicationConfig.GetAbsoluteAppLocation(x) == applicationToLaunch);

        if (application != null)
        {
            arguments = $"{arguments} {application.Config.AppArguments}";
        }

        // Show warning for Wine users.
        if (Shared.Environment.IsWine)
        {
            // Set up UI Resources, since they're needed for the dialog.
            if (CompatibilityDialogs.WineShowLaunchDialog())
            {
                StartGame(applicationToLaunch, arguments);
            }
        }
        else
        {
            StartGame(applicationToLaunch, arguments);
        }
    }
Esempio n. 4
0
        private void LaunchApplicationAndExit(string applicationToLaunch)
        {
            // Acquire arguments
            _commandLineArguments.TryGetValue(Constants.ParameterArguments, out var arguments);
            if (arguments == null)
            {
                arguments = "";
            }

            applicationToLaunch = Path.GetFullPath(applicationToLaunch);
            var application = ApplicationConfig.GetAllApplications(IoC.Get <LoaderConfig>().ApplicationConfigDirectory).FirstOrDefault(x => Path.GetFullPath(x.Config.AppLocation) == applicationToLaunch);

            if (application != null)
            {
                arguments = $"{arguments} {application.Config.AppArguments}";
            }

            // Show warning for Wine users.
            if (Shared.Environment.IsWine)
            {
                // Set up UI Resources, since they're needed for the dialog.
                SetupResources();
                if (CompatibilityDialogs.WineShowLaunchDialog())
                {
                    StartGame(applicationToLaunch, arguments);
                }
            }
            else
            {
                StartGame(applicationToLaunch, arguments);
            }
        }
    /* Static API */

    /// <summary>
    /// Returns a complete list of all processes running Reloaded.
    /// </summary>
    /// <param name="processes">List of all processes running Reloaded.</param>
    /// <returns>True if there is more than one process, else false.</returns>
    public static bool GetAllProcesses(out IEnumerable <Process> processes)
    {
        var applications = ApplicationConfig.GetAllApplications();
        var trackers     = applications.Select(x => new ApplicationInstanceTracker(ApplicationConfig.GetAbsoluteAppLocation(x)));

        processes = trackers.SelectMany(x => x.GetProcesses().ReloadedProcesses);

        return(processes.Any());
    }
Esempio n. 6
0
        /// <summary>
        /// Populates the application list governed by <see cref="Applications"/>.
        /// </summary>
        private void GetApplications(CancellationToken cancellationToken = default)
        {
            try
            {
                var appConfigs = ApplicationConfig.GetAllApplications(ConfigDirectory, cancellationToken);
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                _context.Post(() => Collections.ModifyObservableCollection(Applications, appConfigs));
            }
            catch (Exception) { }
        }
Esempio n. 7
0
    private static void CreateTemplate(CreateTemplateOptions createTemplate)
    {
        if (createTemplate.Type == TemplateType.Application)
        {
            var apps    = ApplicationConfig.GetAllApplications();
            var appById = apps.FirstOrDefault(x => x.Config.AppId == createTemplate.Id);

            if (appById == null)
            {
                Console.WriteLine($"Possible Applications");
                foreach (var app in apps)
                {
                    Console.WriteLine($"Id: {app.Config.AppId} | Name: {app.Config.AppName}");
                }

                var cmdLine = Parser.Default.FormatCommandLine(new CreateTemplateOptions()
                {
                    Id   = apps[0].Config.AppId,
                    Type = TemplateType.Application
                });

                Console.WriteLine($"Example Usage: `Reloaded.Community.Tool.exe {cmdLine}`");
            }
            else
            {
                Console.WriteLine("Copy Text Below, Save as .json file.\n" +
                                  "====================================");

                var config = TryGetGameBananaUpdateConfig(appById);
                SerializeAndPrint(new AppItem()
                {
                    AppId        = appById.Config.AppId,
                    AppName      = appById.Config.AppName,
                    AppStatus    = Status.Ok,
                    Hash         = Hashing.ToString(xxHash64.ComputeHash(File.ReadAllBytes(ApplicationConfig.GetAbsoluteAppLocation(appById)))),
                    GameBananaId = config.GameId
                });
            }
        }
        else
        {
            throw new Exception("Not Supported");
        }
    }
Esempio n. 8
0
        /// <summary>
        /// Entry point for the application.
        /// </summary>
        public App()
        {
            PopulateCommandLineArgs();

            /* Check if Kill Process */
            if (_commandLineArguments.TryGetValue(Constants.ParameterKill, out string processId))
            {
                var process = Process.GetProcessById(Convert.ToInt32(processId));
                process.Kill();

                ActionWrappers.SleepOnConditionWithTimeout(() => process.HasExited, 1000, 32);
            }

            /* Check if Launch Process */
            if (_commandLineArguments.TryGetValue(Constants.ParameterLaunch, out string applicationToLaunch))
            {
                // Acquire arguments
                _commandLineArguments.TryGetValue(Constants.ParameterArguments, out var arguments);
                if (arguments == null)
                {
                    arguments = "";
                }

                applicationToLaunch = Path.GetFullPath(applicationToLaunch);
                var application = ApplicationConfig.GetAllApplications().FirstOrDefault(x => Path.GetFullPath(x.Object.AppLocation) == applicationToLaunch);
                if (application != null)
                {
                    arguments = $"{arguments} {application.Object.AppArguments}";
                }

                // Launch the application.
                var launcher = ApplicationLauncher.FromLocationAndArguments(applicationToLaunch, arguments);
                launcher.Start();

                // Quit the process.
                Environment.Exit(0);
            }

            // Move Contents involving UI elements to LoadCompleted
            this.Startup += OnStartup;
        }
Esempio n. 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;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Searches for the application configuration corresponding to the current
        /// executing application
        /// </summary>
        private IApplicationConfig FindThisApplication()
        {
            var configurations = ApplicationConfig.GetAllApplications(LoaderConfig.ApplicationConfigDirectory);
            var fullPath       = NormalizePath(Environment.CurrentProcessLocation.Value);

            foreach (var configuration in configurations)
            {
                var application = configuration.Config;
                var appLocation = application.AppLocation;

                if (string.IsNullOrEmpty(appLocation))
                {
                    continue;
                }

                var fullAppLocation = NormalizePath(application.AppLocation);
                if (fullAppLocation == fullPath)
                {
                    return(application);
                }
            }

            return(null);
        }
Esempio n. 11
0
        /// <summary>
        /// Searches for the application configuration corresponding to the current
        /// executing application
        /// </summary>
        private IApplicationConfig FindThisApplication()
        {
            var configurations = ApplicationConfig.GetAllApplications(LoaderConfig.ApplicationConfigDirectory);
            var fullPath       = Path.GetFullPath(Process.GetCurrentProcess().GetExecutablePath());

            foreach (var configuration in configurations)
            {
                var application = configuration.Object;
                var appLocation = application.AppLocation;

                if (String.IsNullOrEmpty(appLocation))
                {
                    continue;
                }

                var fullAppLocation = Path.GetFullPath(application.AppLocation);
                if (fullAppLocation == fullPath)
                {
                    return(application);
                }
            }

            return(null);
        }