Esempio n. 1
0
        public async Task Run(RunSynthesisPatcher settings, CancellationToken cancel)
        {
            if (cancel.IsCancellationRequested)
            {
                return;
            }

            var internalSettings = RunSynthesisMutagenPatcher.Factory(settings);

            internalSettings.ExtraDataFolder = PathToExtraData;

            var args = Parser.Default.FormatCommandLine(internalSettings);

            try
            {
                using ProcessWrapper process = ProcessWrapper.Create(
                          new ProcessStartInfo(PathToExecutable, args)
                {
                    WorkingDirectory = Path.GetDirectoryName(PathToExecutable) !
                },
                          cancel);
                using var outputSub = process.Output.Subscribe(_output);
                using var errSub    = process.Error.Subscribe(_error);
                var result = await process.Run();

                if (result != 0)
                {
                    throw new CliUnsuccessfulRunException(
                              result,
                              $"Process exited in failure: {process.StartInfo.FileName} {internalSettings}");
                }
            }
Esempio n. 2
0
        public async Task Run(RunSynthesisPatcher settings, CancellationToken?cancel = null)
        {
            if (_assembly == null)
            {
                throw new ArgumentException("Tried to run a code snippet patcher that did not have an assembly.");
            }
            Type?type = _assembly.GetType(ClassName);

            if (type == null)
            {
                throw new ArgumentException("Could not find compiled class within assembly.");
            }
            var patcherCodeClass = System.Activator.CreateInstance(type);
            var userPrefs        = new UserPreferences()
            {
                Cancel = cancel ?? CancellationToken.None
            };
            var internalSettings = RunSynthesisMutagenPatcher.Factory(settings);

            using var synthesisState = ConstructStateFactory(settings.GameRelease)(internalSettings, userPrefs);
            Task t = (Task)type.InvokeMember("Run",
                                             BindingFlags.Default | BindingFlags.InvokeMethod,
                                             null,
                                             patcherCodeClass,
                                             new[]
            {
                synthesisState,
            });
            await t;

            synthesisState.PatchMod.WriteToBinaryParallel(
                settings.OutputPath,
                new BinaryWriteParameters()
            {
                ModKey = BinaryWriteParameters.ModKeyOption.NoCheck,
                MastersListOrdering = new BinaryWriteParameters.MastersListOrderingByLoadOrder(synthesisState.LoadOrder.Where(i => i.Enabled).Select(i => i.ModKey))
            });
        }