static void Main(string[] args) { var keepRunning = args.Length > 0 && args[0] == "--background"; var asmName = Assembly.GetExecutingAssembly().GetName(); var logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.File($"{asmName.Name}.log") .CreateLogger(); PatcherConfig configuration; if (!File.Exists(PatcherConfig.FILE_PATH)) { logger.Error($"{PatcherConfig.FILE_PATH} doesn't exist. Creating default configuration..."); configuration = new PatcherConfig() { FilesDir = "path/to/mkdd/files/directory", ModsDir = "path/to/mods/directory", BinDir = "path/to/mods/directory/.bin", OutDir = "path/to/mkdd/files/directory", CacheDir = "path/to/mods/directory/.cache", ArcPackPath = "Tools/LunaboyRarcTools/ArcPack.exe", ArcExtractPath = "Tools/LunaboyRarcTools/ArcExtract.exe", }; } else { configuration = PatcherConfig.Load(PatcherConfig.FILE_PATH); } logger.Information($"{asmName.Name} {asmName.Version.Major}.{asmName.Version.Minor}.{asmName.Version.Revision} by TGE ({DateTime.Now.Year})\n"); #if !DEBUG try { #endif var modDb = new ModDb(logger, configuration, configuration.ModsDir); var patcher = new Patcher(logger, configuration, modDb); patcher.Patch(MergeOrder.TopToBottom); if (keepRunning) { while (true) { patcher.Patch(MergeOrder.TopToBottom); Console.WriteLine("Press any key to patch"); Console.ReadKey(); } } #if !DEBUG } catch (Exception e) { logger.Fatal($"An unhandled exception occured: {e.Message}\nThe program will now exit."); } #endif }
void IEnvironmentManager.ExecuteUpdater(PatcherConfig patcherConfig) { //the patcher directory will contain the patcher executable file aswell as it's dependencies var patcherDirectory = GetTempDirectory(patcherConfig.ProjectId).CreateSubdirectory("patcher"); //copy patcher assembly var patcherAssembly = new FileInfo(Assembly.GetAssembly(typeof(WindowsPatcher)).Location); var targetLocation = Path.Combine(patcherDirectory.FullName, Path.GetFileNameWithoutExtension(patcherAssembly.Name) + ".exe"); if (File.Exists(targetLocation)) { File.Delete(targetLocation); } patcherAssembly.CopyTo(targetLocation); //copy dependencies CopyFileSameName(Assembly.GetAssembly(typeof(UpdateController <>)).Location, patcherDirectory); CopyFileSameName(Assembly.GetAssembly(typeof(JsonConvert)).Location, patcherDirectory); var arguments = new List <string>(); ActionConfig = patcherConfig; File.WriteAllText(Path.Combine(patcherDirectory.FullName, "patcher.cfg"), JsonConvert.SerializeObject(this, typeof(WindowsPatcherConfig), Formatting.Indented, Program.JsonSerializerSettings)); arguments.Add("/config patcher.cfg"); if (CustomUi != null) { //copy custom ui assemblies to subfolder var updaterUiDirectory = patcherDirectory.CreateSubdirectory("updaterUi"); var customUiFilename = Path.Combine(updaterUiDirectory.FullName, "CustomUi.dll"); File.Copy(CustomUi.AssemblyPath, customUiFilename); if (CustomUi.RequiredLibraries?.Count > 0) { foreach (var requiredLibrary in CustomUi.RequiredLibraries) { CopyFileSameName(requiredLibrary, updaterUiDirectory); } } arguments.Add("/updaterUi updaterUi\\CustomUi.dll"); } if (Language == null) { Language = WindowsUpdaterTranslation.English; } if (Language is ImplementedUpdaterTranslation implementedUpdaterTranslation) { arguments.Add("/language " + implementedUpdaterTranslation.KeyName); } else { File.WriteAllText(Path.Combine(patcherDirectory.FullName, "language.json"), JsonConvert.SerializeObject(Language.Values)); arguments.Add("/languageFile language.json"); } var currentProcess = Process.GetCurrentProcess(); arguments.Add("/hostProcess " + currentProcess.Id); var startInfo = new ProcessStartInfo(patcherAssembly.FullName, "patch " + string.Join(" ", arguments)) { UseShellExecute = true, //required for runas WorkingDirectory = patcherDirectory.FullName }; if (RunAsAdministrator) { startInfo.Verb = "runas"; } var process = Process.Start(startInfo); if (process == null) { throw new InvalidOperationException("Unable to start patcher process."); } //close this application _applicationCloser?.ExitApplication(); }
public GuiConfig() { Patcher = new PatcherConfig(); Mods = new List <GuiModConfig>(); }
public void ExecuteUpdater(PatcherConfig patcherConfig) { throw new NotImplementedException(); }