From c7908fe08e332e19a5f8a2349585e958c0c19d19 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Tue, 31 May 2022 17:14:27 -0600 Subject: [PATCH] Can install compile install verify TPF! --- Wabbajack.Compiler/CompilerSettings.cs | 2 ++ .../CompilerSettingsInferencer.cs | 6 +++- Wabbajack.Compiler/MO2Compiler.cs | 4 +-- Wabbajack.Installer/AInstaller.cs | 1 + Wabbajack.Paths.IO/AbsolutePathExtensions.cs | 31 ++++++++++++++++--- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Wabbajack.Compiler/CompilerSettings.cs b/Wabbajack.Compiler/CompilerSettings.cs index b86e3185..bd29589f 100644 --- a/Wabbajack.Compiler/CompilerSettings.cs +++ b/Wabbajack.Compiler/CompilerSettings.cs @@ -17,6 +17,8 @@ public class CompilerSettings public AbsolutePath ModListImage { get; set; } public bool UseGamePaths { get; set; } + + public bool UseTextureRecompression { get; set; } = false; public Game[] OtherGames { get; set; } = Array.Empty(); public TimeSpan MaxVerificationTime { get; set; } = TimeSpan.FromMinutes(1); diff --git a/Wabbajack.Compiler/CompilerSettingsInferencer.cs b/Wabbajack.Compiler/CompilerSettingsInferencer.cs index df916cf2..3f4aa213 100644 --- a/Wabbajack.Compiler/CompilerSettingsInferencer.cs +++ b/Wabbajack.Compiler/CompilerSettingsInferencer.cs @@ -27,7 +27,7 @@ public class CompilerSettingsInferencer public async Task InferFromRootPath(AbsolutePath rootPath) { var mo2File = rootPath.Combine(Consts.MO2IniName).LoadIniFile(); - var profile = mo2File["General"]["selected_profile"]; + var profile = mo2File["General"]["selected_profile"].FromMO2Ini(); return await InferModListFromLocation(rootPath.Combine(Consts.MO2Profiles, profile, Consts.ModListTxt)); } @@ -88,6 +88,10 @@ public class CompilerSettingsInferencer if ((generalModData["notes"]?.Contains(Consts.WABBAJACK_NOMATCH_INCLUDE) ?? false) || (generalModData["comments"]?.Contains(Consts.WABBAJACK_NOMATCH_INCLUDE) ?? false)) cs.NoMatchInclude = cs.NoMatchInclude.Append(modFolder.RelativeTo(mo2Folder)).ToArray(); + + if ((generalModData["notes"]?.Contains(Consts.WABBAJACK_INCLUDE) ?? false) || + (generalModData["comments"]?.Contains(Consts.WABBAJACK_INCLUDE) ?? false)) + cs.Include = cs.Include.Append(modFolder.RelativeTo(mo2Folder)).ToArray(); } _logger.LogInformation("Finding other profiles"); diff --git a/Wabbajack.Compiler/MO2Compiler.cs b/Wabbajack.Compiler/MO2Compiler.cs index 4492744b..7225a731 100644 --- a/Wabbajack.Compiler/MO2Compiler.cs +++ b/Wabbajack.Compiler/MO2Compiler.cs @@ -313,8 +313,8 @@ public class MO2Compiler : ACompiler new DropAll(this) }; - //if (DisableTextureResizing) - // steps = steps.Where(s => !(s is MatchSimilarTextures)).ToList(); + if (!_settings.UseTextureRecompression) + steps = steps.Where(s => s is not MatchSimilarTextures).ToList(); return steps; } diff --git a/Wabbajack.Installer/AInstaller.cs b/Wabbajack.Installer/AInstaller.cs index 914861f8..66ddb4e9 100644 --- a/Wabbajack.Installer/AInstaller.cs +++ b/Wabbajack.Installer/AInstaller.cs @@ -251,6 +251,7 @@ public abstract class AInstaller await using var s = await sf.GetStream(); await using var of = directive.Directive.To.RelativeTo(_configuration.Install) .Open(FileMode.Create, FileAccess.Write); + _logger.LogInformation("Recompressing {Filename}", tt.To.FileName); await ImageLoader.Recompress(s, tt.ImageState.Width, tt.ImageState.Height, tt.ImageState.Format, of, token); } diff --git a/Wabbajack.Paths.IO/AbsolutePathExtensions.cs b/Wabbajack.Paths.IO/AbsolutePathExtensions.cs index 1320d8d3..b1d34ef4 100644 --- a/Wabbajack.Paths.IO/AbsolutePathExtensions.cs +++ b/Wabbajack.Paths.IO/AbsolutePathExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security.AccessControl; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -22,9 +23,27 @@ public static class AbsolutePathExtensions { var path = file.ToNativePath(); if (File.Exists(path)) - File.Delete(path); + { + try + { + File.Delete(path); + } + catch (UnauthorizedAccessException ex) + { + var fi = new FileInfo(path); + if (fi.IsReadOnly) + { + fi.IsReadOnly = false; + File.Delete(path); + } + else + { + throw; + } + } + } if (Directory.Exists(path)) - Directory.Delete(path, true); + file.DeleteDirectory(); } public static long Size(this AbsolutePath file) @@ -188,17 +207,19 @@ public static class AbsolutePathExtensions if (!path.DirectoryExists()) return; if (dontDeleteIfNotEmpty && (path.EnumerateFiles().Any() || path.EnumerateDirectories().Any())) return; - foreach (string directory in Directory.GetDirectories(path.ToString())) + foreach (var directory in Directory.GetDirectories(path.ToString())) { DeleteDirectory(directory.ToAbsolutePath(), dontDeleteIfNotEmpty); } - try { Directory.Delete(path.ToString(), true); } - catch (IOException) + catch (IOException) { + var di = new DirectoryInfo(path.ToString()); + if (di.Attributes.HasFlag(FileAttributes.ReadOnly)) + di.Attributes &= ~FileAttributes.ReadOnly; Directory.Delete(path.ToString(), true); } catch (UnauthorizedAccessException)