moved code and fixed critical bug.

This commit is contained in:
Luca 2021-03-14 15:51:52 +01:00
parent b81b99b842
commit 9a796f31c7
3 changed files with 40 additions and 54 deletions

View File

@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.Common;
@ -7,21 +9,53 @@ namespace Wabbajack.Lib.CompilationSteps
public class IgnoreSaveFiles : MO2CompilationStep
{
private AbsolutePath[] _profilePaths;
private readonly bool _includeSaves;
private readonly string _tag;
private readonly AbsolutePath _sourcePath;
public IgnoreSaveFiles(ACompiler compiler) : base(compiler)
{
_tag = Consts.WABBAJACK_INCLUDE_SAVES;
_sourcePath = compiler.SourcePath;
string rootDirectory = (string)_sourcePath;
try
{
_includeSaves = File.Exists(((String)Directory.EnumerateFiles(rootDirectory, _tag).ToList().First())) ? true : false;
}
catch // Cant get a .First() if the list is empty, which it is when the files doesn't exist.
{
_includeSaves = false;
}
_profilePaths =
MO2Compiler.SelectedProfiles.Select(p => MO2Compiler.SourcePath.Combine("profiles", p, "saves")).ToArray();
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
if (!_profilePaths.Any(p => source.File.AbsoluteName.InFolder(p)))
return null;
if (_includeSaves)
{
foreach (var folderpath in _profilePaths)
{
if (!source.AbsolutePath.InFolder(folderpath)) continue;
var result = source.EvolveTo<InlineFile>();
result.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath);
return result;
}
}
else
{
if (!_profilePaths.Any(p => source.File.AbsoluteName.InFolder(p)))
return null;
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = "Ignore Save files";
return result;
}
return null;
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = "Ignore Save files";
return result;
}
}
}

View File

@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;
namespace Wabbajack.Lib.CompilationSteps
{
public class IncludeSavesOption: MO2CompilationStep
{
private readonly string _tag;
private readonly AbsolutePath _sourcePath;
private AbsolutePath[] _profileSavePaths;
private readonly bool _includeSaves;
public IncludeSavesOption(ACompiler compiler, string tag) : base(compiler)
{
_tag = tag;
_sourcePath = compiler.SourcePath;
string rootDirectory = (string)_sourcePath;
_includeSaves = File.Exists(((String)Directory.EnumerateFiles(rootDirectory, _tag).ToList().First())) ? true : false;
_profileSavePaths =
MO2Compiler.SelectedProfiles.Select(p => MO2Compiler.SourcePath.Combine("profiles", p, "saves")).ToArray();
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
if (_includeSaves)
{
foreach (var folderpath in _profileSavePaths)
{
if (!source.AbsolutePath.InFolder(folderpath)) continue;
var result = source.EvolveTo<InlineFile>();
result.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath);
return result;
}
}
return null;
}
}
}

View File

@ -426,7 +426,6 @@ namespace Wabbajack.Lib
new IgnoreGameFilesIfGameFolderFilesExist(this),
new IncludePropertyFiles(this),
//new IncludeSteamWorkshopItems(this),
new IncludeSavesOption(this,Consts.WABBAJACK_INCLUDE_SAVES),
new IgnoreSaveFiles(this),
new IgnoreStartsWith(this, "logs\\"),
new IgnoreStartsWith(this, "downloads\\"),