@@ -129,115 +129,122 @@ private async Task InstallBepInEx(Server server)
129129
130130 if ( await yesNoDialog . ShowAsync ( ) is ContentDialogResult . Primary )
131131 {
132- string workingDir = Directory . GetCurrentDirectory ( ) ;
133- ModInfo bixMod = new ( ) ;
134- foreach ( ModInfo mod in Mods . ModList )
132+ try
135133 {
136- if ( mod . Full_Name == "BepInEx-BepInExPack_V_Rising" )
137- bixMod = mod ;
138- }
134+ string workingDir = Directory . GetCurrentDirectory ( ) ;
135+ ModInfo bixMod = new ( ) ;
136+ foreach ( ModInfo mod in Mods . ModList )
137+ {
138+ if ( mod . Uuid4 == "b86fcaaf-297a-45c8-82a0-fcbd7806fdc4" )
139+ bixMod = mod ;
140+ }
139141
140- foreach ( Mod downloadedMod in VsmSettings . DownloadedMods )
141- {
142- if ( downloadedMod . Uuid4 == bixMod . Uuid4 )
142+ foreach ( Mod downloadedMod in VsmSettings . DownloadedMods )
143143 {
144- if ( Directory . Exists ( workingDir + @"\Mods\temp" ) )
145- Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
144+ if ( downloadedMod . Uuid4 == bixMod . Uuid4 && downloadedMod . Downloaded == true )
145+ {
146+ if ( Directory . Exists ( workingDir + @"\Mods\temp" ) )
147+ Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
146148
147- Directory . CreateDirectory ( workingDir + @"\Mods\temp" ) ;
148- ZipFile . ExtractToDirectory ( workingDir + @"\Mods\" + downloadedMod . ArchiveName , workingDir + @"\Mods\temp" , true ) ;
149+ Directory . CreateDirectory ( workingDir + @"\Mods\temp" ) ;
150+ ZipFile . ExtractToDirectory ( workingDir + @"\Mods\" + downloadedMod . ArchiveName , workingDir + @"\Mods\temp" , true ) ;
149151
150- string [ ] dirs1 = Directory . GetDirectories ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
151- string [ ] files1 = Directory . GetFiles ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
152- foreach ( string file in files1 )
153- File . Move ( file , server . Path + @"\" + Path . GetFileName ( file ) , true ) ;
152+ string [ ] dirs1 = Directory . GetDirectories ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
153+ string [ ] files1 = Directory . GetFiles ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
154+ foreach ( string file in files1 )
155+ File . Move ( file , server . Path + @"\" + Path . GetFileName ( file ) , true ) ;
154156
155- foreach ( string dir in dirs1 )
156- {
157- DirectoryInfo dirInfo = new ( dir ) ;
158- if ( Directory . Exists ( server . Path + @"\" + dirInfo . Name ) )
159- Directory . Delete ( server . Path + @"\" + dirInfo . Name , true ) ;
160- Directory . Move ( dir , server . Path + @"\" + dirInfo . Name ) ;
157+ foreach ( string dir in dirs1 )
158+ {
159+ DirectoryInfo dirInfo = new ( dir ) ;
160+ if ( Directory . Exists ( server . Path + @"\" + dirInfo . Name ) )
161+ Directory . Delete ( server . Path + @"\" + dirInfo . Name , true ) ;
162+ Directory . Move ( dir , server . Path + @"\" + dirInfo . Name ) ;
163+ }
164+
165+ Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
166+ server . InstalledMods . Add ( bixMod . Uuid4 ) ;
167+ server . BepInExInstalled = true ;
168+ server . BepInExVersion = bixMod . Versions [ 0 ] . Version_Number ;
169+ bixMod . Installed = true ;
170+ MainSettings . Save ( VsmSettings ) ;
171+
172+ _ = new ContentDialog
173+ {
174+ Owner = this ,
175+ Title = "BepInEx - Install" ,
176+ Content = $ "BepInEx was installed on { server . Name } .",
177+ CloseButtonText = "Ok" ,
178+ DefaultButton = ContentDialogButton . Close
179+ } . ShowAsync ( ) ;
180+
181+ return ;
161182 }
183+ }
162184
163- Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
164- server . InstalledMods . Add ( bixMod . Uuid4 ) ;
165- server . BepInExInstalled = true ;
166- server . BepInExVersion = bixMod . Versions [ 0 ] . Version_Number ;
167- bixMod . Installed = true ;
168- MainSettings . Save ( VsmSettings ) ;
185+ if ( ! Directory . Exists ( workingDir + @"\Mods" ) )
186+ Directory . CreateDirectory ( workingDir + @"\Mods" ) ;
169187
170- _ = new ContentDialog
171- {
172- Owner = this ,
173- Title = "BepInEx - Install" ,
174- Content = $ "BepInEx was installed on { server . Name } .",
175- CloseButtonText = "Ok" ,
176- DefaultButton = ContentDialogButton . Close
177- } . ShowAsync ( ) ;
178-
179- return ;
188+ using Stream stream = await hClient . GetStreamAsync ( bixMod . Versions [ 0 ] . Download_Url ) ;
189+ using ( var fileStream = File . Create ( workingDir + @"\Mods\" + bixMod . Versions [ 0 ] . Full_Name + ".zip" ) )
190+ {
191+ await stream . CopyToAsync ( fileStream ) ;
180192 }
181- }
182193
183- if ( ! Directory . Exists ( workingDir + @"\Mods" ) )
184- Directory . CreateDirectory ( workingDir + @"\Mods" ) ;
194+ Mod modToSave = new ( )
195+ {
196+ Downloaded = true ,
197+ ArchiveName = bixMod . Versions [ 0 ] . Full_Name + ".zip" ,
198+ Uuid4 = bixMod . Uuid4
199+ } ;
185200
186- using Stream stream = await hClient . GetStreamAsync ( bixMod . Versions [ 0 ] . Download_Url ) ;
187- using ( var fileStream = File . Create ( workingDir + @"\Mods\" + bixMod . Versions [ 0 ] . Full_Name + ".zip" ) )
188- {
189- await stream . CopyToAsync ( fileStream ) ;
190- }
201+ VsmSettings . DownloadedMods . Add ( modToSave ) ;
202+ int modIndex = Mods . ModList . IndexOf ( bixMod ) ;
203+ Mods . ModList [ modIndex ] . Downloaded = true ;
191204
192- Mod modToSave = new ( )
193- {
194- Downloaded = true ,
195- ArchiveName = bixMod . Versions [ 0 ] . Full_Name + ".zip" ,
196- Uuid4 = bixMod . Uuid4
197- } ;
205+ if ( Directory . Exists ( workingDir + @"\Mods\temp" ) )
206+ Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
198207
199- VsmSettings . DownloadedMods . Add ( modToSave ) ;
200- int modIndex = Mods . ModList . IndexOf ( bixMod ) ;
201- Mods . ModList [ modIndex ] . Downloaded = true ;
208+ Directory . CreateDirectory ( workingDir + @"\Mods\temp" ) ;
209+ ZipFile . ExtractToDirectory ( workingDir + @"\Mods\" + modToSave . ArchiveName , workingDir + @"\Mods\temp" , true ) ;
202210
203- if ( Directory . Exists ( workingDir + @"\Mods\temp" ) )
204- Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
211+ string [ ] dirs = Directory . GetDirectories ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
212+ string [ ] files = Directory . GetFiles ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
213+ foreach ( string file in files )
214+ {
215+ File . Move ( file , server . Path + @"\" + Path . GetFileName ( file ) , true ) ;
216+ }
205217
206- Directory . CreateDirectory ( workingDir + @"\Mods\temp" ) ;
207- ZipFile . ExtractToDirectory ( workingDir + @"\Mods\" + modToSave . ArchiveName , workingDir + @"\Mods\temp" , true ) ;
218+ foreach ( string dir in dirs )
219+ {
220+ DirectoryInfo dirInfo = new ( dir ) ;
221+ if ( Directory . Exists ( server . Path + @"\" + dirInfo . Name ) )
222+ Directory . Delete ( server . Path + @"\" + dirInfo . Name , true ) ;
223+ Directory . Move ( dir , server . Path + @"\" + dirInfo . Name ) ;
224+ }
208225
209- string [ ] dirs = Directory . GetDirectories ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
210- string [ ] files = Directory . GetFiles ( workingDir + @"\Mods\temp\BepInExPack_V_Rising" ) ;
211- foreach ( string file in files )
212- {
213- File . Move ( file , server . Path + @"\" + Path . GetFileName ( file ) , true ) ;
214- }
226+ Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
227+ server . InstalledMods . Add ( bixMod . Uuid4 ) ;
228+ server . BepInExInstalled = true ;
229+ server . BepInExVersion = bixMod . Versions [ 0 ] . Version_Number ;
230+ bixMod . Installed = true ;
231+ MainSettings . Save ( VsmSettings ) ;
215232
216- foreach ( string dir in dirs )
217- {
218- DirectoryInfo dirInfo = new ( dir ) ;
219- if ( Directory . Exists ( server . Path + @"\" + dirInfo . Name ) )
220- Directory . Delete ( server . Path + @"\" + dirInfo . Name , true ) ;
221- Directory . Move ( dir , server . Path + @"\" + dirInfo . Name ) ;
233+ _ = new ContentDialog
234+ {
235+ Owner = this ,
236+ Title = "BepInEx - Install" ,
237+ Content = $ "BepInEx was installed on { server . Name } .",
238+ CloseButtonText = "Ok" ,
239+ DefaultButton = ContentDialogButton . Close
240+ } . ShowAsync ( ) ;
241+
242+ return ;
222243 }
223-
224- Directory . Delete ( workingDir + @"\Mods\temp" , true ) ;
225- server . InstalledMods . Add ( bixMod . Uuid4 ) ;
226- server . BepInExInstalled = true ;
227- server . BepInExVersion = bixMod . Versions [ 0 ] . Version_Number ;
228- bixMod . Installed = true ;
229- MainSettings . Save ( VsmSettings ) ;
230-
231- _ = new ContentDialog
244+ catch ( Exception ex )
232245 {
233- Owner = this ,
234- Title = "BepInEx - Install" ,
235- Content = $ "BepInEx was installed on { server . Name } .",
236- CloseButtonText = "Ok" ,
237- DefaultButton = ContentDialogButton . Close
238- } . ShowAsync ( ) ;
239-
240- return ;
246+ MessageBox . Show ( "Error installing BepInEx: \n " + ex . Message , "Error" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
247+ }
241248
242249
243250 }
0 commit comments