mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Implement basics of game folder remapping
This commit is contained in:
parent
3c671272b6
commit
0c0cbbab4f
@ -410,6 +410,11 @@ namespace Wabbajack.Common
|
||||
await file.CopyToAsync(dest);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CopyOrLinkIfOverSizeAsync(AbsolutePath newFile)
|
||||
{
|
||||
await CopyToAsync(newFile);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(Utils.RelativePathConverter))]
|
||||
|
53
Wabbajack.Lib/Tasks/MigrateGameFolder.cs
Normal file
53
Wabbajack.Lib/Tasks/MigrateGameFolder.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.Lib.Tasks
|
||||
{
|
||||
public class MigrateGameFolder
|
||||
{
|
||||
public static async Task<bool> Execute(AbsolutePath mo2Folder)
|
||||
{
|
||||
var iniPath = mo2Folder.Combine(Consts.ModOrganizer2Ini);
|
||||
if (iniPath.Exists)
|
||||
{
|
||||
Utils.Log($"Game folder conversion failed, {Consts.ModOrganizer2Ini} does not exist in {mo2Folder}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var newGamePath = mo2Folder.Combine(Consts.GameFolderFilesDir);
|
||||
newGamePath.CreateDirectory();
|
||||
var gameIni = iniPath.LoadIniFile();
|
||||
|
||||
if (!GameRegistry.TryGetByFuzzyName((string)gameIni.General.gameName, out var gameMeta))
|
||||
{
|
||||
Utils.Log($"Could not locate game for {gameIni.General.gameName}");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var orginGamePath = gameMeta.GameLocation();
|
||||
foreach (var file in gameMeta.GameLocation().EnumerateFiles())
|
||||
{
|
||||
var relPath = file.RelativeTo(orginGamePath);
|
||||
var newFile = relPath.RelativeTo(newGamePath);
|
||||
if (newFile.Exists)
|
||||
{
|
||||
Utils.Log($"Skipping {relPath} it already exists in the target path");
|
||||
continue;
|
||||
}
|
||||
|
||||
Utils.Log($"Copying/Linking {relPath}");
|
||||
await file.CopyOrLinkIfOverSizeAsync(newFile);
|
||||
}
|
||||
|
||||
Utils.Log("Remapping INI");
|
||||
var iniString = await iniPath.ReadAllTextAsync();
|
||||
iniString = iniString.Replace((string)orginGamePath, (string)newGamePath);
|
||||
iniString = iniString.Replace(((string)orginGamePath).Replace(@"\", @"\\"), ((string)newGamePath).Replace(@"\", @"\\"));
|
||||
iniString = iniString.Replace(((string)orginGamePath).Replace(@"\", @"/"), ((string)newGamePath).Replace(@"\", @"/"));
|
||||
await iniPath.WriteAllTextAsync(iniString);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
35
Wabbajack.Test/TasksTests.cs
Normal file
35
Wabbajack.Test/TasksTests.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Threading.Tasks;
|
||||
using Wabbajack.Common;
|
||||
using Wabbajack.Lib.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Wabbajack.Test
|
||||
{
|
||||
public class TasksTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CanRemapGameFolder()
|
||||
{
|
||||
await using var tempFolder = await TempFolder.Create();
|
||||
|
||||
await tempFolder.Dir.Combine("some_file.txt").WriteAllTextAsync("some_file");
|
||||
await tempFolder.Dir.Combine("steam_api64.dll").WriteAllTextAsync("steam_api");
|
||||
|
||||
|
||||
var meta = Game.SkyrimSpecialEdition.MetaData();
|
||||
await tempFolder.Dir.Combine(Consts.ModOrganizer2Ini)
|
||||
.WriteAllLinesAsync(
|
||||
"[General]",
|
||||
$"gameName={meta.MO2Name}",
|
||||
$"gamePath={meta.GameLocation()}",
|
||||
$"pathDouble={meta.GameLocation().ToString().Replace(@"\", @"\\")}",
|
||||
$"pathForward={meta.GameLocation().ToString().Replace(@"\", @"/")}");
|
||||
|
||||
await MigrateGameFolder.Execute(tempFolder.Dir);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user