@@ -4,9 +4,7 @@ import { ModalCard } from "../all";
4
4
import R2Error from " ../../model/errors/R2Error" ;
5
5
import { ProfileImportExport } from " ../../r2mm/mods/ProfileImportExport" ;
6
6
import ExportMod from " ../../model/exports/ExportMod" ;
7
- import path from " path" ;
8
7
import Profile from " ../../model/Profile" ;
9
- import FileUtils from " ../../utils/FileUtils" ;
10
8
import FsProvider from " ../../providers/generic/file/FsProvider" ;
11
9
import ThunderstoreDownloaderProvider from " ../../providers/ror2/downloading/ThunderstoreDownloaderProvider" ;
12
10
import StatusEnum from " ../../model/enums/StatusEnum" ;
@@ -150,9 +148,16 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
150
148
const profileContent = this .profileImportContent ;
151
149
const localListenerId = this .listenerId + 1 ;
152
150
this .listenerId = localListenerId ;
153
- document .addEventListener (' created-profile' , ((event : CustomEvent ) =>
154
- this .profileCreatedCallback (event , localListenerId , profileContent ! , [this .profileImportFilePath ! ])
155
- ) as EventListener , {once: true });
151
+ document .addEventListener (' created-profile' , ((event : CustomEvent ) => {
152
+ if (this .listenerId === localListenerId ) {
153
+ const isUpdate: boolean = this .importUpdateSelection === ' UPDATE' ;
154
+ if (this .prepareDirectoryForProfileImporting (event .detail , localListenerId , profileContent ! , isUpdate )) {
155
+ this .isProfileBeingImported = true ;
156
+ this .importProfileMods (event .detail , isUpdate , profileContent ! , [this .profileImportFilePath ! ], this .downloadImportedProfileMods );
157
+ this .closeModal ();
158
+ }
159
+ }
160
+ }) as EventListener , {once: true });
156
161
this .newProfileName = profileContent ! .getProfileName ();
157
162
this .activeStep = ' ADDING_PROFILE' ;
158
163
}
@@ -186,71 +191,6 @@ export default class ImportProfileModal extends mixins(ProfilesMixin) {
186
191
return read ;
187
192
}
188
193
189
- profileCreatedCallback(event : CustomEvent , localListenerId : number , parsed : ExportFormat , files : string []) {
190
- if (this .listenerId === localListenerId ) {
191
- (async () => {
192
- let profileName: string = event .detail ;
193
- if (profileName !== ' ' ) {
194
- if (this .importUpdateSelection === ' UPDATE' ) {
195
- profileName = " _profile_update" ;
196
- if (await fs .exists (path .join (Profile .getDirectory (), profileName ))) {
197
- await FileUtils .emptyDirectory (path .join (Profile .getDirectory (), profileName ));
198
- await fs .rmdir (path .join (Profile .getDirectory (), profileName ));
199
- }
200
- await this .$store .dispatch (' profiles/setSelectedProfile' , { profileName: profileName , prewarmCache: true });
201
- }
202
- if (parsed .getMods ().length > 0 ) {
203
- this .isProfileBeingImported = true ;
204
- setTimeout (async () => {
205
- await this .downloadImportedProfileMods (parsed .getMods (), async () => {
206
- if (files [0 ].endsWith (' .r2z' )) {
207
- await this .extractZippedProfileFile (files [0 ], profileName );
208
- }
209
- if (this .importUpdateSelection === ' UPDATE' ) {
210
- this .activeProfileName = event .detail ;
211
- try {
212
- await FileUtils .emptyDirectory (path .join (Profile .getDirectory (), event .detail ));
213
- } catch (e ) {
214
- console .log (" Failed to empty directory:" , e );
215
- }
216
- await fs .rmdir (path .join (Profile .getDirectory (), event .detail ));
217
- await fs .rename (path .join (Profile .getDirectory (), profileName ), path .join (Profile .getDirectory (), event .detail ));
218
- }
219
- await this .$store .dispatch (' profiles/setSelectedProfile' , { profileName: event .detail , prewarmCache: true });
220
- this .closeModal ();
221
- });
222
- }, 100 );
223
- }
224
- }
225
- })();
226
- }
227
- }
228
-
229
- async extractZippedProfileFile(file : string , profileName : string ) {
230
- const entries = await ZipProvider .instance .getEntries (file );
231
- for (const entry of entries ) {
232
- if (entry .entryName .startsWith (' config/' ) || entry .entryName .startsWith (" config\\ " )) {
233
- await ZipProvider .instance .extractEntryTo (
234
- file ,
235
- entry .entryName ,
236
- path .join (
237
- Profile .getDirectory (),
238
- profileName ,
239
- ' BepInEx'
240
- )
241
- );
242
- } else if (entry .entryName .toLowerCase () !== " export.r2x" ) {
243
- await ZipProvider .instance .extractEntryTo (
244
- file ,
245
- entry .entryName ,
246
- path .join (
247
- Profile .getDirectory (),
248
- profileName
249
- )
250
- )
251
- }
252
- }
253
- }
254
194
255
195
async downloadImportedProfileMods(modList : ExportMod [], callback ? : () => void ) {
256
196
const settings = this .$store .getters [' settings' ];
0 commit comments