@@ -78,63 +78,55 @@ import ProfileModList from '../../r2mm/mods/ProfileModList';
78
78
combo : ThunderstoreCombo ,
79
79
store : Store <any >
80
80
): Promise <void > {
81
- return new Promise (async (resolve , reject ) => {
81
+ const assignId = await store .dispatch (
82
+ ' download/addDownload' ,
83
+ [` ${combo .getMod ().getName ()} (${combo .getVersion ().getVersionNumber ().toString ()}) ` ]
84
+ );
82
85
83
- const assignId = await store .dispatch (
84
- ' download/addDownload' ,
85
- [` ${combo .getMod ().getName ()} (${combo .getVersion ().getVersionNumber ().toString ()}) ` ]
86
+ let downloadedMods: ThunderstoreCombo [] = [];
87
+ try {
88
+ downloadedMods = await ThunderstoreDownloaderProvider .instance .download (
89
+ profile ,
90
+ combo ,
91
+ store .state .download .ignoreCache ,
92
+ (downloadProgress : number , modName : string , status : number , err : R2Error | null ) => {
93
+ try {
94
+ DownloadMixin .downloadProgressCallback (store , assignId , downloadProgress , modName , status , err );
95
+ } catch (e ) {
96
+ throw e ;
97
+ }
98
+ }
86
99
);
87
-
88
- setTimeout (async () => {
89
- let downloadedMods: ThunderstoreCombo [] = [];
100
+ } catch (e ) {
101
+ store .commit (' download/updateDownload' , { assignId , failed: true });
102
+ throw e ;
103
+ }
104
+ await ProfileModList .requestLock (async () => {
105
+ let currentDownloadIndex = 0 ;
106
+ for (const combo of downloadedMods ) {
90
107
try {
91
- downloadedMods = await ThunderstoreDownloaderProvider .instance .download (
92
- profile ,
93
- combo ,
94
- store .state .download .ignoreCache ,
95
- (downloadProgress : number , modName : string , status : number , err : R2Error | null ) => {
96
- try {
97
- DownloadMixin .downloadProgressCallback (store , assignId , downloadProgress , modName , status , err );
98
- } catch (e ) {
99
- reject (e );
100
- }
101
- }
102
- );
108
+ await store .dispatch (' download/installModAfterDownload' , {profile , combo });
103
109
} catch (e ) {
104
110
store .commit (' download/updateDownload' , { assignId , failed: true });
105
- return reject ( e );
111
+ throw R2Error . fromThrownValue ( e , ` Failed to install mod [${ combo . getMod (). getFullName ()}] ` );
106
112
}
107
- await ProfileModList .requestLock (async () => {
108
- let currentDownloadIndex = 0 ;
109
- for (const combo of downloadedMods ) {
110
- try {
111
- await store .dispatch (' download/installModAfterDownload' , {profile , combo });
112
- } catch (e ) {
113
- store .commit (' download/updateDownload' , { assignId , failed: true });
114
- return reject (
115
- R2Error .fromThrownValue (e , ` Failed to install mod [${combo .getMod ().getFullName ()}] ` )
116
- );
117
- }
118
- store .commit (' download/updateDownload' , {
119
- assignId ,
120
- modName: combo .getMod ().getName (),
121
- installProgress: ThunderstoreDownloaderProvider .instance .generateProgressPercentage (100 , currentDownloadIndex , downloadedMods .length )
122
- });
123
- currentDownloadIndex ++ ;
124
- }
125
- const modList = await ProfileModList .getModList (profile );
126
- if (modList instanceof R2Error ) {
127
- store .commit (' download/updateDownload' , { assignId , failed: true });
128
- return reject (modList );
129
- }
130
- const err = await ConflictManagementProvider .instance .resolveConflicts (modList , profile );
131
- if (err instanceof R2Error ) {
132
- store .commit (' download/updateDownload' , { assignId , failed: true });
133
- return reject (err );
134
- }
135
- return resolve ();
113
+ store .commit (' download/updateDownload' , {
114
+ assignId ,
115
+ modName: combo .getMod ().getName (),
116
+ installProgress: ThunderstoreDownloaderProvider .instance .generateProgressPercentage (100 , currentDownloadIndex , downloadedMods .length )
136
117
});
137
- }, 1 );
118
+ currentDownloadIndex ++ ;
119
+ }
120
+ const modList = await ProfileModList .getModList (profile );
121
+ if (modList instanceof R2Error ) {
122
+ store .commit (' download/updateDownload' , { assignId , failed: true });
123
+ throw modList ;
124
+ }
125
+ const err = await ConflictManagementProvider .instance .resolveConflicts (modList , profile );
126
+ if (err instanceof R2Error ) {
127
+ store .commit (' download/updateDownload' , { assignId , failed: true });
128
+ throw err ;
129
+ }
138
130
});
139
131
}
140
132
0 commit comments