14
14
using NexusMods . Abstractions . Loadouts . Synchronizers ;
15
15
using NexusMods . App . UI . Controls . GameWidget ;
16
16
using NexusMods . App . UI . Controls . MiniGameWidget ;
17
- using NexusMods . App . UI . Pages . LoadoutPage ;
18
17
using NexusMods . App . UI . Resources ;
19
18
using NexusMods . App . UI . Windows ;
20
19
using NexusMods . App . UI . WorkspaceSystem ;
26
25
using System . Reactive ;
27
26
using System . Reactive . Linq ;
28
27
using DynamicData . Aggregation ;
28
+ using NexusMods . Abstractions . Library ;
29
+ using NexusMods . Abstractions . Library . Models ;
30
+ using NexusMods . Abstractions . NexusModsLibrary . Models ;
29
31
using NexusMods . Abstractions . Settings ;
30
32
using NexusMods . App . UI . Extensions ;
31
33
using NexusMods . App . UI . Overlays ;
32
34
using NexusMods . App . UI . Overlays . AlphaWarning ;
33
35
using NexusMods . App . UI . Pages . LibraryPage ;
36
+ using NexusMods . Collections ;
34
37
using NexusMods . CrossPlatform . Process ;
38
+ using NexusMods . Paths ;
35
39
using NexusMods . Telemetry ;
36
40
37
41
namespace NexusMods . App . UI . Pages . MyGames ;
@@ -41,6 +45,8 @@ public class MyGamesViewModel : APageViewModel<IMyGamesViewModel>, IMyGamesViewM
41
45
{
42
46
private const string TrelloPublicRoadmapUrl = "https://trello.com/b/gPzMuIr3/nexus-mods-app-roadmap" ;
43
47
48
+ private readonly ILibraryService _libraryService ;
49
+ private readonly CollectionDownloader _collectionDownloader ;
44
50
private readonly IWindowManager _windowManager ;
45
51
private readonly IJobMonitor _jobMonitor ;
46
52
@@ -65,6 +71,10 @@ public MyGamesViewModel(
65
71
var settingsManager = serviceProvider . GetRequiredService < ISettingsManager > ( ) ;
66
72
var experimentalSettings = settingsManager . Get < ExperimentalSettings > ( ) ;
67
73
74
+ var libraryDataProviders = serviceProvider . GetServices < ILibraryDataProvider > ( ) . ToArray ( ) ;
75
+
76
+ _collectionDownloader = serviceProvider . GetRequiredService < CollectionDownloader > ( ) ;
77
+ _libraryService = serviceProvider . GetRequiredService < ILibraryService > ( ) ;
68
78
_jobMonitor = serviceProvider . GetRequiredService < IJobMonitor > ( ) ;
69
79
70
80
TabTitle = Language . MyGames ;
@@ -123,8 +133,24 @@ public MyGamesViewModel(
123
133
{
124
134
if ( GetJobRunningForGameInstallation ( installation ) . IsT2 ) return ;
125
135
136
+ var filesToDelete = libraryDataProviders . SelectMany ( dataProvider => dataProvider . GetAllFiles ( gameId : installation . Game . GameId ) ) . ToArray ( ) ;
137
+ var totalSize = filesToDelete . Sum ( static Size ( file ) => file . Size ) ;
138
+
139
+ var collections = CollectionDownloader . GetCollections ( conn . Db , installation . Game . GameId ) ;
140
+
141
+ var overlay = new RemoveGameOverlayViewModel
142
+ {
143
+ GameName = installation . Game . Name ,
144
+ NumDownloads = filesToDelete . Length ,
145
+ SumDownloadsSize = totalSize ,
146
+ NumCollections = collections . Length ,
147
+ } ;
148
+
149
+ var result = await overlayController . EnqueueAndWait ( overlay ) ;
150
+ if ( ! result . ShouldRemoveGame ) return ;
151
+
126
152
vm . State = GameWidgetState . RemovingGame ;
127
- await Task . Run ( async ( ) => await RemoveAllLoadouts ( installation ) ) ;
153
+ await Task . Run ( async ( ) => await RemoveGame ( installation , shouldDeleteDownloads : result . ShouldDeleteDownloads , filesToDelete , collections ) ) ;
128
154
vm . State = GameWidgetState . DetectedGame ;
129
155
130
156
Tracking . AddEvent ( Events . Game . RemoveGame , new EventMetadata ( name : installation . Game . Name ) ) ;
@@ -206,9 +232,17 @@ private OneOf<None, CreateLoadoutJob, UnmanageGameJob> GetJobRunningForGameInsta
206
232
return OneOf < None , CreateLoadoutJob , UnmanageGameJob > . FromT0 ( new None ( ) ) ;
207
233
}
208
234
209
- private async Task RemoveAllLoadouts ( GameInstallation installation )
235
+ private async Task RemoveGame ( GameInstallation installation , bool shouldDeleteDownloads , LibraryFile . ReadOnly [ ] filesToDelete , CollectionMetadata . ReadOnly [ ] collections )
210
236
{
211
237
await installation . GetGame ( ) . Synchronizer . UnManage ( installation ) ;
238
+
239
+ if ( ! shouldDeleteDownloads ) return ;
240
+ await _libraryService . RemoveItems ( filesToDelete . Select ( file => file . AsLibraryItem ( ) ) ) ;
241
+
242
+ foreach ( var collection in collections )
243
+ {
244
+ await _collectionDownloader . DeleteCollection ( collection ) ;
245
+ }
212
246
}
213
247
214
248
private async Task ManageGame ( GameInstallation installation )
0 commit comments