Skip to content

Commit 83e72c1

Browse files
committed
Rename removal and replace methods to reference Linked items rather than library items
1 parent c986690 commit 83e72c1

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

src/NexusMods.Abstractions.Library/ILibraryService.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface ILibraryService
4545

4646
/// <summary>
4747
/// Installs a library item into a target loadout.
48-
/// To remove an item, use <see cref="RemoveLibraryItemFromLoadout(NexusMods.Abstractions.Loadouts.LibraryLinkedLoadoutItemId)"/>.
48+
/// To remove an item, use <see cref="RemoveLinkedItemFromLoadout"/>.
4949
/// </summary>
5050
/// <param name="libraryItem">The item to install.</param>
5151
/// <param name="targetLoadout">The target loadout.</param>
@@ -78,42 +78,42 @@ IJobTask<IInstallLoadoutItemJob, InstallLoadoutItemJobResult> InstallItem(
7878
/// Unlinks a single item added by <see cref="InstallItem"/> function call from a loadout.
7979
/// </summary>
8080
/// <param name="itemId">The <see cref="LibraryLinkedLoadoutItem"/> to remove from the loadout.</param>
81-
Task RemoveLibraryItemFromLoadout(LibraryLinkedLoadoutItemId itemId);
81+
Task RemoveLinkedItemFromLoadout(LibraryLinkedLoadoutItemId itemId);
8282

8383
/// <summary>
8484
/// Unlinks a number of items added by <see cref="InstallItem"/> function call from a loadout.
8585
/// </summary>
8686
/// <param name="itemIds">The <see cref="LibraryLinkedLoadoutItem"/>s to remove from the loadout.</param>
87-
Task RemoveLibraryItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds);
87+
Task RemoveLinkedItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds);
8888

8989
/// <summary>
9090
/// Unlinks a single item added by <see cref="InstallItem"/> function call from a loadout.
9191
/// </summary>
9292
/// <param name="itemId">The <see cref="LibraryLinkedLoadoutItem"/>s to remove from the loadout.</param>
9393
/// <param name="tx">Existing transaction to use</param>
94-
void RemoveLibraryItemFromLoadout(LibraryLinkedLoadoutItemId itemId, ITransaction tx);
94+
void RemoveLinkedItemFromLoadout(LibraryLinkedLoadoutItemId itemId, ITransaction tx);
9595

9696
/// <summary>
9797
/// Unlinks a number of items added by <see cref="InstallItem"/> function call from a loadout.
9898
/// </summary>
9999
/// <param name="itemIds">The <see cref="LibraryLinkedLoadoutItem"/>s to remove</param>
100100
/// <param name="tx">Existing transaction to use</param>
101-
void RemoveLibraryItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds, ITransaction tx);
101+
void RemoveLinkedItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds, ITransaction tx);
102102

103103
/// <summary>
104104
/// Removes library items (originally installed via <see cref="InstallItem"/>) from all
105105
/// loadouts using an existing transaction
106106
/// </summary>
107107
/// <param name="libraryItems">The library items to remove from the loadouts</param>
108108
/// <param name="tx">Existing transaction to use</param>
109-
void RemoveLibraryItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems, ITransaction tx);
109+
void RemoveLinkedItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems, ITransaction tx);
110110

111111
/// <summary>
112112
/// Removes library items (originally installed via <see cref="InstallItem"/>) from all
113113
/// loadouts with automatic transaction
114114
/// </summary>
115115
/// <param name="libraryItems">The library items to remove from the loadouts</param>
116-
Task RemoveLibraryItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems);
116+
Task RemoveLinkedItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems);
117117

118118
/// <summary>
119119
/// Replaces all occurrences of a library item with a new version in all loadouts
@@ -125,7 +125,7 @@ IJobTask<IInstallLoadoutItemJob, InstallLoadoutItemJobResult> InstallItem(
125125
/// <returns>
126126
/// If an error occurs at any step of the way, this returns a 'fail' enum.
127127
/// </returns>
128-
ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemInAllLoadouts(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem, ReplaceLibraryItemOptions options, ITransaction tx);
128+
ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemInAllLoadouts(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem, ReplaceLibraryItemOptions options, ITransaction tx);
129129

130130
/// <summary>
131131
/// Replaces all occurrences of a library item with a new version in all loadouts
@@ -136,7 +136,7 @@ IJobTask<IInstallLoadoutItemJob, InstallLoadoutItemJobResult> InstallItem(
136136
/// <returns>
137137
/// If an error occurs at any step of the way, this returns a 'fail' enum.
138138
/// </returns>
139-
ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options, ITransaction tx);
139+
ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options, ITransaction tx);
140140

141141
/// <summary>
142142
/// Replaces all occurrences of a library item with a new version in all loadouts
@@ -146,11 +146,11 @@ IJobTask<IInstallLoadoutItemJob, InstallLoadoutItemJobResult> InstallItem(
146146
/// <returns>
147147
/// If an error occurs at any step of the way, this returns a 'fail' enum.
148148
/// </returns>
149-
ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options);
149+
ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options);
150150
}
151151

152152
/// <summary>
153-
/// Represents the result of a <see cref="ILibraryService.ReplaceLibraryItemInAllLoadouts"/> operation.
153+
/// Represents the result of a <see cref="ILibraryService.ReplaceLinkedItemInAllLoadouts"/> operation.
154154
/// </summary>
155155
public enum LibraryItemReplacementResult
156156
{
@@ -166,7 +166,7 @@ public enum LibraryItemReplacementResult
166166
}
167167

168168
/// <summary>
169-
/// Options for the <see cref="ILibraryService.ReplaceLibraryItemInAllLoadouts(NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,ReplaceLibraryItemOptions,NexusMods.MnemonicDB.Abstractions.ITransaction)"/>
169+
/// Options for the <see cref="ILibraryService.ReplaceLinkedItemInAllLoadouts"/>
170170
/// API.
171171
/// </summary>
172172
public struct ReplaceLibraryItemOptions

src/NexusMods.App.UI/Pages/LoadoutPage/LoadoutViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public LoadoutViewModel(
183183
.ToArray();
184184

185185
if (ids.Length == 0) return;
186-
await _LibraryService.RemoveLibraryItemsFromLoadout(ids);
186+
await _LibraryService.RemoveLinkedItemsFromLoadout(ids);
187187
},
188188
awaitOperation: AwaitOperation.Sequential,
189189
initialCanExecute: false,

src/NexusMods.Library/LibraryService.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public async Task RemoveLibraryItems(IEnumerable<LibraryItem.ReadOnly> libraryIt
8181
{
8282
using var tx = _connection.BeginTransaction();
8383
var items = libraryItems.ToArray();
84-
RemoveLibraryItemsFromAllLoadouts(items, tx);
84+
RemoveLinkedItemsFromAllLoadouts(items, tx);
8585

8686
foreach (var item in items)
8787
tx.Delete(item.Id, recursive: true);
@@ -90,30 +90,30 @@ public async Task RemoveLibraryItems(IEnumerable<LibraryItem.ReadOnly> libraryIt
9090
await _gcRunner.RunWithMode(gcRunMode);
9191
}
9292

93-
public async Task RemoveLibraryItemFromLoadout(LibraryLinkedLoadoutItemId itemId)
93+
public async Task RemoveLinkedItemFromLoadout(LibraryLinkedLoadoutItemId itemId)
9494
{
9595
using var tx = _connection.BeginTransaction();
96-
RemoveLibraryItemFromLoadout(itemId, tx);
96+
RemoveLinkedItemFromLoadout(itemId, tx);
9797
await tx.Commit();
9898
}
9999

100-
public async Task RemoveLibraryItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds)
100+
public async Task RemoveLinkedItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds)
101101
{
102102
using var tx = _connection.BeginTransaction();
103-
RemoveLibraryItemsFromLoadout(itemIds, tx);
103+
RemoveLinkedItemsFromLoadout(itemIds, tx);
104104
await tx.Commit();
105105
}
106106

107-
public void RemoveLibraryItemFromLoadout(LibraryLinkedLoadoutItemId itemId, ITransaction tx)
107+
public void RemoveLinkedItemFromLoadout(LibraryLinkedLoadoutItemId itemId, ITransaction tx)
108108
=> tx.Delete(itemId, recursive: true);
109109

110-
public void RemoveLibraryItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds, ITransaction tx)
110+
public void RemoveLinkedItemsFromLoadout(IEnumerable<LibraryLinkedLoadoutItemId> itemIds, ITransaction tx)
111111
{
112112
foreach (var itemId in itemIds)
113113
tx.Delete(itemId, recursive: true);
114114
}
115115

116-
public void RemoveLibraryItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems, ITransaction tx)
116+
public void RemoveLinkedItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems, ITransaction tx)
117117
{
118118
foreach (var item in libraryItems)
119119
{
@@ -124,13 +124,13 @@ public void RemoveLibraryItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly>
124124
}
125125
}
126126

127-
public async Task RemoveLibraryItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems)
127+
public async Task RemoveLinkedItemsFromAllLoadouts(IEnumerable<LibraryItem.ReadOnly> libraryItems)
128128
{
129129
using var tx = _connection.BeginTransaction();
130-
RemoveLibraryItemsFromAllLoadouts(libraryItems, tx);
130+
RemoveLinkedItemsFromAllLoadouts(libraryItems, tx);
131131
await tx.Commit();
132132
}
133-
public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemInAllLoadouts(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem, ReplaceLibraryItemOptions options, ITransaction tx)
133+
public async ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemInAllLoadouts(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem, ReplaceLibraryItemOptions options, ITransaction tx)
134134
{
135135
try
136136
{
@@ -151,7 +151,7 @@ public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemInAllLoad
151151

152152
// 2. Unlink old mod using bulk removal
153153
foreach (var (_, libraryLinkedItem) in items)
154-
RemoveLibraryItemFromLoadout(libraryLinkedItem.Id, tx);
154+
RemoveLinkedItemFromLoadout(libraryLinkedItem.Id, tx);
155155

156156
// 3. Reinstall new mod in original loadouts
157157
foreach (var (loadout, _) in items)
@@ -165,14 +165,14 @@ public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemInAllLoad
165165
return LibraryItemReplacementResult.Success;
166166
}
167167

168-
public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options, ITransaction tx)
168+
public async ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options, ITransaction tx)
169169
{
170170
var replacementsArr = replacements.ToArray();
171171
try
172172
{
173173
foreach (var (oldItem, newItem) in replacementsArr)
174174
{
175-
var result = await ReplaceLibraryItemInAllLoadouts(oldItem, newItem, options.ToReplaceLibraryItemOptions(), tx);
175+
var result = await ReplaceLinkedItemInAllLoadouts(oldItem, newItem, options.ToReplaceLibraryItemOptions(), tx);
176176
if (result != LibraryItemReplacementResult.Success)
177177
return result; // failed due to some reason.
178178
}
@@ -185,10 +185,10 @@ public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemsInAllLoa
185185
return LibraryItemReplacementResult.Success;
186186
}
187187

188-
public async ValueTask<LibraryItemReplacementResult> ReplaceLibraryItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options)
188+
public async ValueTask<LibraryItemReplacementResult> ReplaceLinkedItemsInAllLoadouts(IEnumerable<(LibraryItem.ReadOnly oldItem, LibraryItem.ReadOnly newItem)> replacements, ReplaceLibraryItemsOptions options)
189189
{
190190
using var tx = _connection.BeginTransaction();
191-
var result = await ReplaceLibraryItemsInAllLoadouts(replacements, options, tx);
191+
var result = await ReplaceLinkedItemsInAllLoadouts(replacements, options, tx);
192192
await tx.Commit();
193193
return result;
194194
}

tests/Networking/NexusMods.Networking.NexusWebApi.Tests/ModUpdateServiceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public async Task GetNewestFileVersionObservable_ShouldNotifyOnLibraryItemRemove
203203
receivedRemove.Should().BeFalse();
204204

205205
// Now remove it from the library.
206-
await _libraryService.RemoveItems([libraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
206+
await _libraryService.RemoveLibraryItems([libraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
207207
receivedRemove.Should().BeTrue();
208208
}
209209

@@ -292,7 +292,7 @@ public async Task GetNewestModPageVersionObservable_ShouldNotifyOnLibraryItemRem
292292
receivedRemove.Should().BeFalse();
293293

294294
// Now remove it from the library.
295-
await _libraryService.RemoveItems([libraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
295+
await _libraryService.RemoveLibraryItems([libraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
296296
receivedRemove.Should().BeTrue();
297297
}
298298

@@ -409,7 +409,7 @@ public async Task GetNewestFileVersionObservable_ShouldNotifyOlderVersionWhenCur
409409
updateResults.Should().BeEmpty("Installing latest version should remove the update.");
410410

411411
// Now remove the current version from the library
412-
await _libraryService.RemoveItems([currentLibraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
412+
await _libraryService.RemoveLibraryItems([currentLibraryFile.AsLibraryItem()], GarbageCollectorRunMode.DoNotRun);
413413

414414
// Assert that the old version now has update notifications
415415
updateResults.Should().NotBeEmpty("Old version should receive updates after newer version is removed");

tests/NexusMods.App.GarbageCollection.DataModel.Tests/FindUsedFiles/MarkUsedLibraryFilesTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task ShouldMarkAndUnmarkFilesCorrectly()
6161
// Now delete the library item, and hopefully GC will clean up the rest.
6262
var libraryArchives = new[] { libraryArchive.AsLibraryFile().AsLibraryItem() };
6363
// ReSharper disable once RedundantArgumentDefaultValue
64-
await libraryService.RemoveItems(libraryArchives, GarbageCollectorRunMode.DoNotRun);
64+
await libraryService.RemoveLibraryItems(libraryArchives, GarbageCollectorRunMode.DoNotRun);
6565

6666
gc = CreateGC(archiveLocation);
6767
AssertAllLoadoutItemsAre(used: false, reason: "LoadoutFile with hash {0} should not be marked as used after Loadout AND Library deletion.", gc, loadout);

tests/NexusMods.DataModel.Tests/FileStoreTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task DeletingModWithSharedFileDoesNotCorrupt()
4949
var dataFileBHashBefore = dataFileBBefore.Value.Hash;
5050

5151
// Act
52-
await _libraryService.RemoveItems([libraryItemA.AsLibraryFile().AsLibraryItem()], GarbageCollectorRunMode.RunSynchronously);
52+
await _libraryService.RemoveLibraryItems([libraryItemA.AsLibraryFile().AsLibraryItem()], GarbageCollectorRunMode.RunSynchronously);
5353

5454
// Assert
5555
// Changing A should not affect B

tests/NexusMods.DataModel.Tests/LibraryServiceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public async Task ReplaceLibraryItemsInAllLoadouts_ShouldReplaceItemsAcrossLoado
184184
{
185185
IgnoreReadOnlyCollections = false,
186186
};
187-
var result = await _libraryService.ReplaceLibraryItemsInAllLoadouts(replacements, options);
187+
var result = await _libraryService.ReplaceLinkedItemsInAllLoadouts(replacements, options);
188188

189189
// Assert
190190
result.Should().Be(LibraryItemReplacementResult.Success);
@@ -251,7 +251,7 @@ public async Task ReplaceLibraryItemsInAllLoadouts_ShouldRespectReadOnlyCollecti
251251
{
252252
IgnoreReadOnlyCollections = true,
253253
};
254-
var result = await _libraryService.ReplaceLibraryItemsInAllLoadouts(replacements, options);
254+
var result = await _libraryService.ReplaceLinkedItemsInAllLoadouts(replacements, options);
255255

256256
// Assert
257257
result.Should().Be(LibraryItemReplacementResult.Success);

0 commit comments

Comments
 (0)