/// <summary> /// Takes in the main line command arguments, and handles PatcherRunSettings CLI inputs. /// </summary> /// <typeparam name="TMod">Setter mod interface</typeparam> /// <typeparam name="TModGetter">Getter only mod interface</typeparam> /// <param name="settings">Patcher run settings</param> /// <param name="patcher">Patcher func that processes a load order, and returns a mod object to export.</param> /// <param name="userPreferences">Any custom user preferences</param> public void Patch <TMod, TModGetter>( RunSynthesisMutagenPatcher settings, PatcherFunction <TMod, TModGetter> patcher, UserPreferences?userPreferences = null) where TMod : class, IMod, TModGetter where TModGetter : class, IModGetter { try { System.Console.WriteLine("Prepping state."); WarmupAll.Init(); using var state = Utility.ToState <TMod, TModGetter>(settings, userPreferences ?? new UserPreferences()); System.Console.WriteLine("Running patch."); patcher(state); if (!settings.OutputPath.IsNullOrWhitespace()) { System.Console.WriteLine($"Writing to output: {settings.OutputPath}"); state.PatchMod.WriteToBinaryParallel(path: settings.OutputPath, param: GetWriteParams(state.RawLoadOrder.Select(x => x.ModKey))); } } catch (Exception ex) when(Environment.GetCommandLineArgs().Length == 0 && (userPreferences?.ActionsForEmptyArgs?.BlockAutomaticExit ?? false)) { System.Console.Error.WriteLine(ex); System.Console.Error.WriteLine("Error occurred. Press enter to exit"); System.Console.ReadLine(); } }
/// <summary> /// Takes in the main line command arguments, and handles PatcherRunSettings CLI inputs. /// </summary> /// <typeparam name="TMod">Setter mod interface</typeparam> /// <typeparam name="TModGetter">Getter only mod interface</typeparam> /// <param name="args">Main command line args</param> /// <param name="patcher">Patcher func that processes a load order, and returns a mod object to export.</param> /// <param name="userPreferences">Any custom user preferences</param> /// <returns>Int error code of the operation</returns> public int Patch <TMod, TModGetter>( string[] args, PatcherFunction <TMod, TModGetter> patcher, UserPreferences?userPreferences = null) where TMod : class, IMod, TModGetter where TModGetter : class, IModGetter { Console.WriteLine($"Mutagen version: {Versions.MutagenVersion}"); Console.WriteLine($"Mutagen sha: {Versions.MutagenSha}"); Console.WriteLine($"Synthesis version: {Versions.SynthesisVersion}"); Console.WriteLine($"Synthesis sha: {Versions.SynthesisSha}"); if (args.Length == 0) { var prefs = userPreferences ?? new UserPreferences(); if (prefs.ActionsForEmptyArgs != null) { try { Patch( GetDefaultRun(prefs, prefs.ActionsForEmptyArgs), patcher, prefs); } catch (Exception ex) { System.Console.Error.WriteLine(ex); if (prefs.ActionsForEmptyArgs.BlockAutomaticExit) { System.Console.Error.WriteLine("Error occurred. Press enter to exit"); System.Console.ReadLine(); } return(-1); } if (prefs.ActionsForEmptyArgs.BlockAutomaticExit) { System.Console.Error.WriteLine("Press enter to exit"); System.Console.ReadLine(); } return(0); } } var parser = new Parser((s) => { s.IgnoreUnknownArguments = true; }); return(parser.ParseArguments(args, typeof(RunSynthesisMutagenPatcher)) .MapResult( (RunSynthesisMutagenPatcher settings) => { try { System.Console.WriteLine(settings.ToString()); Patch( settings, patcher, userPreferences); } catch (Exception ex) { System.Console.Error.WriteLine(ex); return -1; } return 0; }, _ => { return -1; })); }