Clone the modlist so we don't delete everything on a re-install

This commit is contained in:
Timothy Baldridge 2020-01-05 21:35:12 -07:00
parent b8a6db5211
commit 38f4825099
3 changed files with 22 additions and 2 deletions

View File

@ -365,16 +365,26 @@ namespace Wabbajack.Common
public static void ToCERAS<T>(this T obj, string filename, SerializerConfig config)
{
byte[] final;
final = ToCERAS(obj, config);
File.WriteAllBytes(filename, final);
}
public static byte[] ToCERAS<T>(this T obj, SerializerConfig config)
{
byte[] final;
var ceras = new CerasSerializer(config);
byte[] buffer = null;
ceras.Serialize(obj, ref buffer);
using(var m1 = new MemoryStream(buffer))
using (var m1 = new MemoryStream(buffer))
using (var m2 = new MemoryStream())
{
BZip2.Compress(m1, m2, false, 9);
m2.Seek(0, SeekOrigin.Begin);
File.WriteAllBytes(filename, m2.ToArray());
final = m2.ToArray();
}
return final;
}
public static T FromCERAS<T>(this Stream data, SerializerConfig config)

View File

@ -344,6 +344,10 @@ namespace Wabbajack.Lib
public async Task OptimizeModlist()
{
Utils.Log("Optimizing Modlist directives");
// Clone the modlist so our changes don't modify the original data
ModList = ModList.Clone();
var indexed = ModList.Directives.ToDictionary(d => d.To);
UpdateTracker.NextStep("Looking for files to delete");

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Ceras;
using Compression.BSA;
@ -120,6 +121,11 @@ namespace Wabbajack.Lib
/// Whether readme is a website
/// </summary>
public bool ReadmeIsWebsite;
public ModList Clone()
{
return new MemoryStream(this.ToCERAS(CerasConfig.Config)).FromCERAS<ModList>(CerasConfig.Config);
}
}
public class Directive