13
13
namespace NexusMods . Abstractions . Library ;
14
14
15
15
/// <summary>
16
- /// Represents the library.
16
+ /// Represents the library, this class provides access to various functionalities
17
+ /// that are accessible from within a 'library' related view.
17
18
/// </summary>
18
19
[ PublicAPI ]
19
20
public interface ILibraryService
@@ -28,30 +29,171 @@ public interface ILibraryService
28
29
/// </summary>
29
30
IJobTask < IAddLocalFile , LocalFile . ReadOnly > AddLocalFile ( AbsolutePath absolutePath ) ;
30
31
32
+ /// <summary>
33
+ /// Returns all loadouts that contain the given library item.
34
+ /// </summary>
35
+ /// <param name="libraryItem">The item to search for.</param>
36
+ /// <remarks>
37
+ /// The loadout and linked item to the current item.
38
+ /// </remarks>
39
+ IEnumerable < ( Loadout . ReadOnly loadout , LibraryLinkedLoadoutItem . ReadOnly linkedItem ) > LoadoutsWithLibraryItem ( LibraryItem . ReadOnly libraryItem ) ;
40
+
31
41
/// <summary>
32
42
/// Adds a library file.
33
43
/// </summary>
34
44
Task < LibraryFile . New > AddLibraryFile ( ITransaction transaction , AbsolutePath source ) ;
35
45
36
46
/// <summary>
37
47
/// Installs a library item into a target loadout.
48
+ /// To remove an installed item, use <see cref="RemoveLinkedItemFromLoadout"/>.
38
49
/// </summary>
39
50
/// <param name="libraryItem">The item to install.</param>
40
51
/// <param name="targetLoadout">The target loadout.</param>
41
52
/// <param name="parent">If specified the installed item will be placed in this group, otherwise it will default to the user's local collection</param>
42
53
/// <param name="installer">The Library will use this installer to install the item</param>
43
- /// <param name="fallbackInstaller">Fallback installer instead of the default advanced installer</param>
44
- IJobTask < IInstallLoadoutItemJob , LoadoutItemGroup . ReadOnly > InstallItem (
54
+ /// <param name="fallbackInstaller">The installer to use if the default installer fails</param>
55
+ /// <param name="transaction">The transaction to attach the installation to. Install is only completed when transaction is completed.</param>
56
+ /// <remarks>
57
+ /// Job returns a result with null <see cref="LoadoutItemGroup.ReadOnly"/> after
58
+ /// if supplied an external transaction via <paramref name="transaction"/>,
59
+ /// since it is the caller's responsibility to complete that transaction.
60
+ /// </remarks>
61
+ IJobTask < IInstallLoadoutItemJob , InstallLoadoutItemJobResult > InstallItem (
45
62
LibraryItem . ReadOnly libraryItem ,
46
63
LoadoutId targetLoadout ,
47
64
Optional < LoadoutItemGroupId > parent = default ,
48
65
ILibraryItemInstaller ? installer = null ,
49
- ILibraryItemInstaller ? fallbackInstaller = null ) ;
66
+ ILibraryItemInstaller ? fallbackInstaller = null ,
67
+ ITransaction ? transaction = null ) ;
50
68
51
69
/// <summary>
52
70
/// Removes a number of items from the library.
71
+ /// This will automatically unlink the loadouts from the items are part of.
53
72
/// </summary>
54
73
/// <param name="libraryItems">The items to remove from the library.</param>
55
74
/// <param name="gcRunMode">Defines how the garbage collector should be run</param>
56
- Task RemoveItems ( IEnumerable < LibraryItem . ReadOnly > libraryItems , GarbageCollectorRunMode gcRunMode = GarbageCollectorRunMode . RunAsynchronously ) ;
75
+ Task RemoveLibraryItems ( IEnumerable < LibraryItem . ReadOnly > libraryItems , GarbageCollectorRunMode gcRunMode = GarbageCollectorRunMode . RunAsynchronously ) ;
76
+
77
+ /// <summary>
78
+ /// Removes a single linked loadout item from its loadout,
79
+ /// managing the transaction automatically.
80
+ /// </summary>
81
+ /// <param name="itemId">The ID of the linked loadout item to remove from the loadout.</param>
82
+ Task RemoveLinkedItemFromLoadout ( LibraryLinkedLoadoutItemId itemId ) ;
83
+
84
+ /// <summary>
85
+ /// Removes multiple linked loadout items from their loadout,
86
+ /// managing the transaction automatically.
87
+ /// </summary>
88
+ /// <param name="itemIds">The IDs of the linked loadout items to remove from their loadout.</param>
89
+ Task RemoveLinkedItemsFromLoadout ( IEnumerable < LibraryLinkedLoadoutItemId > itemIds ) ;
90
+
91
+ /// <summary>
92
+ /// Removes a single linked loadout item from a loadout,
93
+ /// using the provided transaction.
94
+ /// </summary>
95
+ /// <param name="itemId">The ID of the linked loadout item to remove from its loadout.</param>
96
+ /// <param name="tx">Existing transaction to use for this operation.</param>
97
+ void RemoveLinkedItemFromLoadout ( LibraryLinkedLoadoutItemId itemId , ITransaction tx ) ;
98
+
99
+ /// <summary>
100
+ /// Removes multiple linked loadout items from their loadout,
101
+ /// using the provided transaction.
102
+ /// </summary>
103
+ /// <param name="itemIds">The IDs of the linked loadout items to remove from their loadout.</param>
104
+ /// <param name="tx">Existing transaction to use for this operation.</param>
105
+ void RemoveLinkedItemsFromLoadout ( IEnumerable < LibraryLinkedLoadoutItemId > itemIds , ITransaction tx ) ;
106
+
107
+ /// <summary>
108
+ /// Removes all linked loadout items from all loadouts,
109
+ /// using the provided transaction.
110
+ /// </summary>
111
+ /// <param name="libraryItems">The library items whose associated linked loadout items should be removed.</param>
112
+ /// <param name="tx">Existing transaction to use for this operation.</param>
113
+ void RemoveLinkedItemsFromAllLoadouts ( IEnumerable < LibraryItem . ReadOnly > libraryItems , ITransaction tx ) ;
114
+
115
+ /// <summary>
116
+ /// Removes all linked loadout items from all loadouts,
117
+ /// managing the transaction automatically.
118
+ /// </summary>
119
+ /// <param name="libraryItems">The library items whose associated linked loadout items should be removed.</param>
120
+ Task RemoveLinkedItemsFromAllLoadouts ( IEnumerable < LibraryItem . ReadOnly > libraryItems ) ;
121
+
122
+ /// <summary>
123
+ /// Replaces linked loadout items across all loadouts with installations of a different library item.
124
+ /// </summary>
125
+ /// <param name="oldItem">The library item whose linked loadout items should be replaced.</param>
126
+ /// <param name="newItem">The replacement library item from which to install the new linked loadout items from.</param>
127
+ /// <param name="options">Options controlling how to replace the linked loadout items.</param>
128
+ /// <param name="tx">The transaction to use for this operation.</param>
129
+ /// <returns>
130
+ /// A result indicating success or failure of the replacement operation.
131
+ /// </returns>
132
+ ValueTask < LibraryItemReplacementResult > ReplaceLinkedItemsInAllLoadouts ( LibraryItem . ReadOnly oldItem , LibraryItem . ReadOnly newItem , ReplaceLibraryItemOptions options , ITransaction tx ) ;
133
+
134
+ /// <summary>
135
+ /// Replaces multiple sets of linked loadout items across all loadouts with new versions.
136
+ /// </summary>
137
+ /// <param name="replacements">The pairs of library items (old and new) whose linked loadout items should be replaced.</param>
138
+ /// <param name="options">Options controlling how to replace the linked loadout items.</param>
139
+ /// <param name="tx">The transaction to use for this operation.</param>
140
+ /// <returns>
141
+ /// A result indicating success or failure of the replacement operation.
142
+ /// </returns>
143
+ ValueTask < LibraryItemReplacementResult > ReplaceLinkedItemsInAllLoadouts ( IEnumerable < ( LibraryItem . ReadOnly oldItem , LibraryItem . ReadOnly newItem ) > replacements , ReplaceLibraryItemsOptions options , ITransaction tx ) ;
144
+
145
+ /// <summary>
146
+ /// Replaces multiple sets of linked loadout items across all loadouts with new versions,
147
+ /// managing the transaction automatically.
148
+ /// </summary>
149
+ /// <param name="replacements">The pairs of library items (old and new) whose linked loadout items should be replaced.</param>
150
+ /// <param name="options">Options controlling how to replace the linked loadout items.</param>
151
+ /// <returns>
152
+ /// A result indicating success or failure of the replacement operation.
153
+ /// </returns>
154
+ ValueTask < LibraryItemReplacementResult > ReplaceLinkedItemsInAllLoadouts ( IEnumerable < ( LibraryItem . ReadOnly oldItem , LibraryItem . ReadOnly newItem ) > replacements , ReplaceLibraryItemsOptions options ) ;
155
+ }
156
+
157
+ /// <summary>
158
+ /// Represents the result of a <see cref="ILibraryService.ReplaceLinkedItemsInAllLoadouts(NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,NexusMods.Abstractions.Library.ReplaceLibraryItemOptions,NexusMods.MnemonicDB.Abstractions.ITransaction)"/> operation.
159
+ /// </summary>
160
+ public enum LibraryItemReplacementResult
161
+ {
162
+ /// <summary>
163
+ /// The operation was successful.
164
+ /// </summary>
165
+ Success ,
166
+
167
+ /// <summary>
168
+ /// The operation failed (unknown reason).
169
+ /// </summary>
170
+ FailedUnknownReason ,
171
+ }
172
+
173
+ /// <summary>
174
+ /// Options for the <see cref="ILibraryService.ReplaceLinkedItemsInAllLoadouts(NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,NexusMods.Abstractions.Library.Models.LibraryItem.ReadOnly,NexusMods.Abstractions.Library.ReplaceLibraryItemOptions,NexusMods.MnemonicDB.Abstractions.ITransaction)"/>
175
+ /// API.
176
+ /// </summary>
177
+ public struct ReplaceLibraryItemOptions
178
+ {
179
+ /// <summary>
180
+ /// Skips items in ReadOnly collections such as collections from Nexus Mods.
181
+ /// </summary>
182
+ public bool IgnoreReadOnlyCollections { get ; set ; }
183
+ }
184
+
185
+ /// <summary>
186
+ /// Options controlling how multiple sets of linked loadout items are replaced across loadouts.
187
+ /// </summary>
188
+ public struct ReplaceLibraryItemsOptions
189
+ {
190
+ /// <summary>
191
+ /// Skips items in ReadOnly collections such as collections from Nexus Mods.
192
+ /// </summary>
193
+ public bool IgnoreReadOnlyCollections { get ; set ; }
194
+
195
+ /// <summary>
196
+ /// Gets the <see cref="ReplaceLibraryItemOptions"/> for this <see cref="ReplaceLibraryItemsOptions"/>
197
+ /// </summary>
198
+ public ReplaceLibraryItemOptions ToReplaceLibraryItemOptions ( ) => new ( ) { IgnoreReadOnlyCollections = IgnoreReadOnlyCollections } ;
57
199
}
0 commit comments