Skip to content

Commit

Permalink
Upgrade to latest Mutagen.
Browse files Browse the repository at this point in the history
This is partly to incorporate a few bug fixes (such as those relating to the archive list) but primarily to use the newer GameFinder, because Steam has changed their implementation and recent installs (after June 6) can no longer find the game.

Tidies up a few areas of the assembly info and versions. Unfortunately this causes .NET to use a new settings location, which can't be helped without a custom settings provider.
  • Loading branch information
focustense committed Jun 19, 2021
1 parent 501f819 commit 44b62f8
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 26 deletions.
7 changes: 7 additions & 0 deletions Focus.Apps.EasyNpc/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
if (BundlerSettings.Default.UpgradeRequired)
{
BundlerSettings.Default.Upgrade();
BundlerSettings.Default.UpgradeRequired = false;
BundlerSettings.Default.Save();
}

var isFirstLaunch =
e.Args.Contains("/forceintro", StringComparer.OrdinalIgnoreCase) ||
(string.IsNullOrEmpty(BundlerSettings.Default.ModRootDirectory) &&
Expand Down
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Build/BuildPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Windows;

using TKey = Mutagen.Bethesda.FormKey;
using TKey = Mutagen.Bethesda.Plugins.FormKey;

namespace Focus.Apps.EasyNpc.Build
{
Expand Down
12 changes: 12 additions & 0 deletions Focus.Apps.EasyNpc/Configuration/BundlerSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Focus.Apps.EasyNpc/Configuration/BundlerSettings.settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Focus.Apps.EasyNpc" GeneratedClassName="BundlerSettings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Focus.Apps.EasyNpc.Configuration" GeneratedClassName="BundlerSettings">
<Profiles />
<Settings>
<Setting Name="ModRootDirectory" Type="System.String" Scope="User">
Expand All @@ -12,5 +12,8 @@
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</Value>
</Setting>
<Setting Name="UpgradeRequired" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
7 changes: 4 additions & 3 deletions Focus.Apps.EasyNpc/Focus.Apps.EasyNpc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<UseWPF>true</UseWPF>
<AssemblyName>EasyNPC</AssemblyName>
<AssemblyTitle>Easy NPC</AssemblyTitle>
<Product>Focus Modding Tools</Product>
<Product>EasyMod</Product>
<Version>0.1.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down Expand Up @@ -37,8 +38,8 @@
</PackageReference>
<PackageReference Include="FontAwesome5" Version="2.1.1" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />
<PackageReference Include="Mutagen.Bethesda.Core.Windows" Version="0.29.3" />
<PackageReference Include="Mutagen.Bethesda.Skyrim" Version="0.29.3" />
<PackageReference Include="Mutagen.Bethesda.Core.Windows" Version="0.30.4" />
<PackageReference Include="Mutagen.Bethesda.Skyrim" Version="0.30.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="niflysharp" Version="1.2.8" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="3.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Main/Loader.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Windows.Controls;
using System.Windows.Input;

using TKey = Mutagen.Bethesda.FormKey;
using TKey = Mutagen.Bethesda.Plugins.FormKey;

namespace Focus.Apps.EasyNpc.Main
{
Expand Down
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Main/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Focus.Apps.EasyNpc.Mutagen;
using Focus.Apps.EasyNpc.Nifly;
using Focus.Apps.EasyNpc.Profile;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins;
using PropertyChanged;
using Serilog;
using Serilog.Core;
Expand Down
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Maintenance/MaintenancePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using System.Windows;

using TKey = Mutagen.Bethesda.FormKey;
using TKey = Mutagen.Bethesda.Plugins.FormKey;

namespace Focus.Apps.EasyNpc.Maintenance
{
Expand Down
19 changes: 13 additions & 6 deletions Focus.Apps.EasyNpc/Mutagen/MutagenAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using Focus.Apps.EasyNpc.GameData.Records;
using Focus.Apps.EasyNpc.Main;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Installs;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Plugins.Cache;
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Skyrim;
using Serilog;
using System;
Expand Down Expand Up @@ -41,12 +45,12 @@ public MutagenAdapter(ILogger log)
public IEnumerable<Tuple<string, bool>> GetAvailablePlugins()
{
return LoadOrder.GetListings(GameRelease.SkyrimSE, GameDataFolder, true)
.Select(x => Tuple.Create(x.ModKey.FileName, x.Enabled));
.Select(x => Tuple.Create(x.ModKey.FileName.String, x.Enabled));
}

public IEnumerable<string> GetLoadedPlugins()
{
return Environment.LoadOrder.Select(x => x.Key.FileName);
return Environment.LoadOrder.Select(x => x.Key.FileName.String);
}

public int GetLoadOrderIndex(string pluginName)
Expand All @@ -58,8 +62,8 @@ public int GetLoadOrderIndex(string pluginName)
public bool IsMaster(string pluginName)
{
var modKey = ModKey.FromNameAndExtension(pluginName);
return Environment.LoadOrder.TryGetValue(modKey, out var listing) &&
listing.Mod.ModHeader.Flags.HasFlag(SkyrimModHeader.HeaderFlag.Master);
var listing = Environment.LoadOrder.TryGetValue(modKey);
return listing != null && listing.Mod.ModHeader.Flags.HasFlag(SkyrimModHeader.HeaderFlag.Master);
}

public Task Load(IEnumerable<string> pluginNames)
Expand All @@ -69,8 +73,11 @@ public Task Load(IEnumerable<string> pluginNames)
var loadOrderKeys = pluginNames.Select(pluginName => ModKey.FromNameAndExtension(pluginName));
var loadOrder = LoadOrder.Import<ISkyrimModGetter>(GameDataFolder, loadOrderKeys, GameRelease.SkyrimSE);
var linkCache = loadOrder.ToImmutableLinkCache<ISkyrimMod, ISkyrimModGetter>();
Environment =
new GameEnvironmentState<ISkyrimMod, ISkyrimModGetter>(GameDataFolder, loadOrder, linkCache, true);
// If we actually managed to get here, then earlier code already managed to find the listings file.
var listingsFile = PluginListings.GetListingsFile(GameRelease.SkyrimSE);
var creationClubFile = CreationClubListings.GetListingsPath(GameRelease.SkyrimSE.ToCategory(), GameDataFolder);
Environment = new GameEnvironmentState<ISkyrimMod, ISkyrimModGetter>(
GameDataFolder, listingsFile, creationClubFile, loadOrder, linkCache, true);
Environment.LinkCache.Warmup<Npc>();
ArchiveProvider = new MutagenArchiveProvider(Environment);
MergedPluginBuilder = new MutagenMergedPluginBuilder(Environment, log);
Expand Down
14 changes: 8 additions & 6 deletions Focus.Apps.EasyNpc/Mutagen/MutagenArchiveProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Focus.Apps.EasyNpc.GameData.Files;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Archives;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Skyrim;
using Noggog;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -34,13 +37,13 @@ public void CopyToFile(string archivePath, string archiveFilePath, string outFil
if (file == null)
throw new Exception($"Couldn't find file {archiveFilePath} in archive {archivePath}");
using var fs = File.Create(outFilePath);
file.CopyDataTo(fs);
fs.Write(file.GetSpan());
fs.Flush(); // Is it necessary?
}

public IGameFileProvider CreateGameFileProvider()
{
return new VirtualGameFileProvider(environment.GameFolderPath, this);
return new VirtualGameFileProvider(environment.DataFolderPath, this);
}

public IEnumerable<string> GetArchiveFileNames(string archivePath, string path)
Expand All @@ -53,14 +56,13 @@ public IEnumerable<string> GetArchiveFileNames(string archivePath, string path)

public IEnumerable<string> GetLoadedArchivePaths()
{
// Currently, GetApplicableArchivePaths ignores the ModKey entirely and just reads every available BSA.
// This is actually fine for our purposes, but the code has to be aware of this to avoid duplication.
return Archive.GetApplicableArchivePaths(GameRelease.SkyrimSE, environment.GameFolderPath, ModKey.Null);
var dataFolderPath = new DirectoryPath(environment.DataFolderPath);
return Archive.GetApplicableArchivePaths(GameRelease.SkyrimSE, dataFolderPath).Select(x => x.Path);
}

public string ResolvePath(string archiveName)
{
return Path.Combine(environment.GameFolderPath, archiveName);
return Path.Combine(environment.DataFolderPath, archiveName);
}
}
}
7 changes: 5 additions & 2 deletions Focus.Apps.EasyNpc/Mutagen/MutagenExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Plugins.Cache;
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Skyrim;
using System.Linq;

namespace Focus.Apps.EasyNpc.Mutagen
{
static class MutagenExtensions
{
public static INpcGetter GetMasterNpc(this LoadOrder<IModListing<ISkyrimModGetter>> loadOrder, FormKey formKey)
public static INpcGetter GetMasterNpc(this ILoadOrder<IModListing<ISkyrimModGetter>> loadOrder, FormKey formKey)
{
return GetModNpc(loadOrder, formKey.ModKey, formKey);
}

public static INpcGetter GetModNpc(
this LoadOrder<IModListing<ISkyrimModGetter>> loadOrder, ModKey modKey, FormKey formKey)
this ILoadOrder<IModListing<ISkyrimModGetter>> loadOrder, ModKey modKey, FormKey formKey)
{
return loadOrder.GetIfEnabled(modKey).Mod.Npcs.TryGetValue(formKey);
}
Expand Down
4 changes: 3 additions & 1 deletion Focus.Apps.EasyNpc/Mutagen/MutagenMergedPluginBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using Focus.Apps.EasyNpc.Configuration;
using Focus.Apps.EasyNpc.Profile;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Plugins;
using Mutagen.Bethesda.Plugins.Records;
using Mutagen.Bethesda.Skyrim;
using Serilog;
using Serilog.Context;
Expand Down Expand Up @@ -31,7 +33,7 @@ public MergedPluginResult Build(
ProgressViewModel progress)
{
progress.StartStage("Backing up previous merge");
var mergeFilePath = Path.Combine(environment.GameFolderPath, MergeFileName);
var mergeFilePath = Path.Combine(environment.DataFolderPath, MergeFileName);
if (File.Exists(mergeFilePath))
{
var backupPath = $"{mergeFilePath}.{DateTime.Now:yyyyMMdd_HHmmss}.bak";
Expand Down
5 changes: 3 additions & 2 deletions Focus.Apps.EasyNpc/Mutagen/MutagenModPluginMapFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Focus.Apps.EasyNpc.GameData.Files;
using Mutagen.Bethesda;
using Mutagen.Bethesda.Archives;
using Mutagen.Bethesda.Skyrim;
using System.IO;
using System.Linq;
Expand All @@ -19,9 +20,9 @@ public ModPluginMap CreateForDirectory(string modRootDirectory)
{
var pluginNames = environment.LoadOrder.Select(x => x.Key.FileName);
var archiveNames = Archive
.GetApplicableArchivePaths(GameRelease.SkyrimSE, environment.GameFolderPath, ModKey.Null)
.GetApplicableArchivePaths(GameRelease.SkyrimSE, environment.DataFolderPath)
.Select(f => Path.GetFileName(f));
return ModPluginMap.ForDirectory(modRootDirectory, pluginNames, archiveNames);
return ModPluginMap.ForDirectory(modRootDirectory, pluginNames.Select(f => f.String), archiveNames);
}
}
}
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Profile/ProfilePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Windows.Controls;
using System.Windows.Input;

using TKey = Mutagen.Bethesda.FormKey;
using TKey = Mutagen.Bethesda.Plugins.FormKey;

namespace Focus.Apps.EasyNpc.Profile
{
Expand Down

0 comments on commit 44b62f8

Please sign in to comment.