diff --git a/Synthesis.Bethesda.Execution/Modules/SolutionPatcherModule.cs b/Synthesis.Bethesda.Execution/Modules/SolutionPatcherModule.cs index d4ee8b8d..c1851907 100644 --- a/Synthesis.Bethesda.Execution/Modules/SolutionPatcherModule.cs +++ b/Synthesis.Bethesda.Execution/Modules/SolutionPatcherModule.cs @@ -1,4 +1,5 @@ -using Autofac; +using Autofac; +using Mutagen.Bethesda.Synthesis.Projects; using Noggog.Autofac; using Synthesis.Bethesda.Execution.Patchers.Git.Services; using Synthesis.Bethesda.Execution.Patchers.Solution; @@ -18,5 +19,12 @@ protected override void Load(ContainerBuilder builder) .NotInjection() .AsImplementedInterfaces() .AsSelf(); + + builder.RegisterAssemblyTypes(typeof(CreateTemplatePatcherSolution).Assembly) + .InNamespacesOf( + typeof(CreateTemplatePatcherSolution)) + .NotInjection() + .AsImplementedInterfaces() + .AsSelf(); } } \ No newline at end of file diff --git a/Synthesis.Bethesda.GUI/Settings/BackupSettings.cs b/Synthesis.Bethesda.GUI/Settings/BackupSettings.cs index c9ec83ab..e9d074d5 100644 --- a/Synthesis.Bethesda.GUI/Settings/BackupSettings.cs +++ b/Synthesis.Bethesda.GUI/Settings/BackupSettings.cs @@ -34,19 +34,55 @@ public BackupSettings( public void Start() { - _initRepository.Init(RepoDirectory); - CreateGitIgnore(); - using var repo = _repositoryCheckouts.Get(RepoDirectory); - StageIfExists(GitIgnorePath, repo.Repository); - StageIfExists(PipelineSettings, repo.Repository); - StageIfExists(GuiSettings, repo.Repository); try { + _initRepository.Init(RepoDirectory); + } + catch (LibGit2SharpException e) + { + _logger.Warning(e, "Could not initiate backup repository."); + return; + } + try + { + CreateGitIgnore(); + using var repo = _repositoryCheckouts.Get(RepoDirectory); + StageIfExists(GitIgnorePath, repo.Repository); + StageIfExists(PipelineSettings, repo.Repository); + StageIfExists(GuiSettings, repo.Repository); repo.Repository.Commit("Settings changed"); } catch (EmptyCommitException) { } + catch (Exception ex) + { + HandleException(ex); + } + } + + private void HandleException(Exception? ex) + { + switch (ex) + { + case LibGit2SharpException: + case NullReferenceException: + WipeBackup(ex); + break; + case AggregateException agg: + HandleException(agg.InnerException); + break; + case null: + return; + default: + throw ex; + } + } + + private void WipeBackup(Exception ex) + { + _logger.Warning(ex, "Wiping backup settings."); + _fileSystem.Directory.DeleteEntireFolder(RepoDirectory); } private void CreateGitIgnore() diff --git a/Synthesis.Bethesda.GUI/ViewModels/Patchers/Initialization/Solution/NewSolutionInitVm.cs b/Synthesis.Bethesda.GUI/ViewModels/Patchers/Initialization/Solution/NewSolutionInitVm.cs index 822c79f0..f5a3bb85 100644 --- a/Synthesis.Bethesda.GUI/ViewModels/Patchers/Initialization/Solution/NewSolutionInitVm.cs +++ b/Synthesis.Bethesda.GUI/ViewModels/Patchers/Initialization/Solution/NewSolutionInitVm.cs @@ -1,6 +1,5 @@ using System.IO; using System.Reactive.Linq; -using Mutagen.Bethesda.Environments.DI; using Mutagen.Bethesda.Synthesis.Projects; using Noggog; using Noggog.WPF; @@ -33,7 +32,6 @@ public class NewSolutionInitVm : ASolutionInitializer public string ProjectNameWatermark => _projectNameWatermark.Value; public NewSolutionInitVm( - IGameCategoryContext gameCategoryContext, IPatcherFactory patcherFactory, IValidateProjectPath validateProjectPath, CreateTemplatePatcherSolution createTemplatePatcherSolution)