mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Can remap game folder files
This commit is contained in:
parent
0c0cbbab4f
commit
2be1771d89
@ -24,5 +24,20 @@ namespace Wabbajack.Common.Test
|
||||
|
||||
tempFile.Path.MoveTo(tempFile2.Path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanGetTopParentOfPath()
|
||||
{
|
||||
var path = (RelativePath)"foo/bar";
|
||||
Assert.Equal((RelativePath)"foo", path.TopParent);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanGetTopParentOfSinglePath()
|
||||
{
|
||||
var path = (RelativePath)"foo";
|
||||
Assert.Equal((RelativePath)"foo", path.TopParent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,10 +180,20 @@ namespace Wabbajack.Common
|
||||
|
||||
result = GetByMO2ArchiveName(someName);
|
||||
if (result != null) return result;
|
||||
|
||||
result = GetByMO2Name(someName);
|
||||
if (result != null) return result;
|
||||
|
||||
|
||||
return int.TryParse(someName, out int id) ? GetBySteamID(id) : null;
|
||||
}
|
||||
|
||||
private static GameMetaData? GetByMO2Name(string gameName)
|
||||
{
|
||||
gameName = gameName.ToLower();
|
||||
return Games.Values.FirstOrDefault(g => g.MO2Name?.ToLower() == gameName);
|
||||
}
|
||||
|
||||
public static bool TryGetByFuzzyName(string someName, [MaybeNullWhen(false)] out GameMetaData gameMetaData)
|
||||
{
|
||||
var result = TryGetByFuzzyName(someName);
|
||||
|
@ -208,12 +208,10 @@ namespace Wabbajack.Common
|
||||
|
||||
public RelativePath RelativeTo(AbsolutePath p)
|
||||
{
|
||||
if (_path.Substring(0, p._path.Length + 1) != p._path + "\\")
|
||||
{
|
||||
throw new InvalidDataException("Not a parent path");
|
||||
}
|
||||
|
||||
return new RelativePath(_path.Substring(p._path.Length + 1));
|
||||
var relPath = Path.GetRelativePath(p._path, _path);
|
||||
if (relPath == _path)
|
||||
throw new ArgumentException($"{_path} is not a subpath of {p._path}");
|
||||
return new RelativePath(relPath);
|
||||
}
|
||||
|
||||
public async Task<string> ReadAllTextAsync()
|
||||
@ -413,6 +411,8 @@ namespace Wabbajack.Common
|
||||
|
||||
public async Task CopyOrLinkIfOverSizeAsync(AbsolutePath newFile)
|
||||
{
|
||||
if (newFile.Parent != default)
|
||||
newFile.Parent.CreateDirectory();
|
||||
await CopyToAsync(newFile);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace Wabbajack.Lib.Tasks
|
||||
public static async Task<bool> Execute(AbsolutePath mo2Folder)
|
||||
{
|
||||
var iniPath = mo2Folder.Combine(Consts.ModOrganizer2Ini);
|
||||
if (iniPath.Exists)
|
||||
if (!iniPath.Exists)
|
||||
{
|
||||
Utils.Log($"Game folder conversion failed, {Consts.ModOrganizer2Ini} does not exist in {mo2Folder}");
|
||||
return false;
|
||||
|
@ -2,18 +2,21 @@
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Wabbajack.Test
|
||||
{
|
||||
public class TasksTests
|
||||
public class TasksTests : ACompilerTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task CanRemapGameFolder()
|
||||
{
|
||||
await using var tempFolder = await TempFolder.Create();
|
||||
var gameff = tempFolder.Dir.Combine(Consts.GameFolderFilesDir);
|
||||
gameff.CreateDirectory();
|
||||
|
||||
await tempFolder.Dir.Combine("some_file.txt").WriteAllTextAsync("some_file");
|
||||
await tempFolder.Dir.Combine("steam_api64.dll").WriteAllTextAsync("steam_api");
|
||||
await gameff.Combine("some_file.txt").WriteAllTextAsync("some_file");
|
||||
await gameff.Combine("steam_api64.dll").WriteAllTextAsync("steam_api");
|
||||
|
||||
|
||||
var meta = Game.SkyrimSpecialEdition.MetaData();
|
||||
@ -25,11 +28,22 @@ namespace Wabbajack.Test
|
||||
$"pathDouble={meta.GameLocation().ToString().Replace(@"\", @"\\")}",
|
||||
$"pathForward={meta.GameLocation().ToString().Replace(@"\", @"/")}");
|
||||
|
||||
await MigrateGameFolder.Execute(tempFolder.Dir);
|
||||
|
||||
Assert.True(await MigrateGameFolder.Execute(tempFolder.Dir));
|
||||
|
||||
Assert.Equal("some_file", await gameff.Combine("some_file.txt").ReadAllTextAsync());
|
||||
Assert.Equal("steam_api", await gameff.Combine("steam_api64.dll").ReadAllTextAsync());
|
||||
Assert.Equal(Hash.FromBase64("k5EWx/9Woqg="), await gameff.Combine(@"Data\Skyrim - Interface.bsa").FileHashAsync());
|
||||
|
||||
var ini = tempFolder.Dir.Combine(Consts.ModOrganizer2Ini).LoadIniFile();
|
||||
Assert.Equal(gameff, (AbsolutePath)(string)ini.General.gamePath);
|
||||
Assert.Equal(gameff, (AbsolutePath)(string)ini.General.pathDouble);
|
||||
Assert.Equal(gameff, (AbsolutePath)(string)ini.General.pathForward);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public TasksTests(ITestOutputHelper helper) : base(helper)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user