collection_edit: backup of the player's package outside the collections folder, start on it handled

This commit is contained in:
cthangover committed 2026-10-22 19:14:56 +02:00
1 parent f68ed6b0ac
commit 9ea7cd65e2
1 file changed
+14 -2
@@ -46,6 +46,7 @@ namespace Mods.CollectionEditTest
private readonly List<string> failures = new(); private readonly List<string> failures = new();
private readonly List<string> enteredScenes = new(); private readonly List<string> enteredScenes = new();
private readonly List<(string From, string To)> movedAside = new(); private readonly List<(string From, string To)> movedAside = new();
private bool startedOnPlayerPackage;
private int passed; private int passed;
private int step; private int step;
private double elapsed; private double elapsed;
@@ -114,6 +115,14 @@ namespace Mods.CollectionEditTest
return; return;
Check($"game '{GameId}' entered ('{enteredScenes[0]}')", true); Check($"game '{GameId}' entered ('{enteredScenes[0]}')", true);
Check("a freshly entered game matches its collection", !GameCatalog.IsActiveOutdated()); Check("a freshly entered game matches its collection", !GameCatalog.IsActiveOutdated());
MoveUserPackageAside();
// A player's own package of the game (say, with the editors added) was what
// the game started on: then the editors may already be loaded and New game
// need not switch the set. The package is restored at the end.
startedOnPlayerPackage = movedAside.Count > 0;
if (startedOnPlayerPackage)
GameLogger.Log("TEST", "CollectionEditTest: the game started on the player's own package; the before/switch checks are skipped");
else
Check($"'{AddedMod}' is not loaded before the edit", !EditorsLoaded); Check($"'{AddedMod}' is not loaded before the edit", !EditorsLoaded);
AddEditorsToCollection(); AddEditorsToCollection();
@@ -158,6 +167,7 @@ namespace Mods.CollectionEditTest
if (Busy || ActiveGame.Id != GameId || enteredScenes.Count == 0) if (Busy || ActiveGame.Id != GameId || enteredScenes.Count == 0)
return; return;
var reload = ModManager.Instance.LastReload; var reload = ModManager.Instance.LastReload;
if (!startedOnPlayerPackage)
Check("New game after the edit switched the mod set", reload?.Applied == true && reload.Plan?.Load.Contains(AddedMod) == true); Check("New game after the edit switched the mod set", reload?.Applied == true && reload.Plan?.Load.Contains(AddedMod) == true);
Check($"'{AddedMod}' is loaded after the edit", EditorsLoaded); Check($"'{AddedMod}' is loaded after the edit", EditorsLoaded);
Check($"'{StudioMod}' is loaded after the edit", ModRegistry.Instance.Mods.ContainsKey(StudioMod)); Check($"'{StudioMod}' is loaded after the edit", ModRegistry.Instance.Mods.ContainsKey(StudioMod));
@@ -178,7 +188,6 @@ namespace Mods.CollectionEditTest
/// </summary> /// </summary>
private void AddEditorsToCollection() private void AddEditorsToCollection()
{ {
MoveUserPackageAside();
var source = GameCatalog.LoadCollections()[GameId]; var source = GameCatalog.LoadCollections()[GameId];
var edited = JsonSerializer.Deserialize<ModCollection>(JsonSerializer.Serialize(source)); var edited = JsonSerializer.Deserialize<ModCollection>(JsonSerializer.Serialize(source));
edited.Package = source.Package; edited.Package = source.Package;
@@ -192,7 +201,10 @@ namespace Mods.CollectionEditTest
private void MoveUserPackageAside() private void MoveUserPackageAside()
{ {
var root = ModCollectionStore.UserPath; // UserPath ends with a separator: without the trim the "parent" is the
// collections folder itself, the backup was scanned as a package and
// Cleanup's RemoveUser(GameId) deleted the player's package with it.
var root = ModCollectionStore.UserPath.TrimEnd('/', '\\');
foreach (var path in new[] { Path.Combine(root, GameId), Path.Combine(root, GameId + ".zip") }) foreach (var path in new[] { Path.Combine(root, GameId), Path.Combine(root, GameId + ".zip") })
{ {
var aside = Path.Combine(Path.GetDirectoryName(root) ?? root, $"collection_edit_backup_{Path.GetFileName(path)}"); var aside = Path.Combine(Path.GetDirectoryName(root) ?? root, $"collection_edit_backup_{Path.GetFileName(path)}");