@@ -210,44 +210,50 @@ public void LoadModsDirectory(string modsDir)
210210 modDirectories . Add ( modsDir ) ;
211211
212212 //Unzip mods
213- foreach ( string ZipPath in Directory . GetFiles ( modsDir , "*.zip" ) )
213+ if ( PMLConfig . ZipModLoad )
214214 {
215- //Get the full path from the mods dir path
216- string ZipExtractPath = Path . GetFullPath ( modsDir ) ;
217-
218- //Ensure that the mods dir path has a path seperator else add it.
219- //This stops a path traversal attack from the zip file
220- if ( ! ZipExtractPath . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) , StringComparison . Ordinal ) )
215+ foreach ( string ZipPath in Directory . GetFiles ( modsDir , "*.zip" ) )
221216 {
222- ZipExtractPath += Path . DirectorySeparatorChar ;
223- }
217+ //Get the full path from the mods dir path
218+ string ZipExtractPath = Path . GetFullPath ( modsDir ) ;
224219
225- //Open zip file index and extract only dll files
226- using ( ZipArchive Archive = ZipFile . OpenRead ( ZipPath ) )
227- {
228- foreach ( ZipArchiveEntry Entry in Archive . Entries )
220+ //Ensure that the mods dir path has a path seperator else add it.
221+ //This stops a path traversal attack from the zip file
222+ if ( ! ZipExtractPath . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) , StringComparison . Ordinal ) )
229223 {
230- if ( Entry . FullName . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) )
231- {
232- string DestinationPath = Path . GetFullPath ( Path . Combine ( modsDir , Entry . Name ) ) ;
233-
234- //If the mod exists, delete it and replace with this one.
235- if ( File . Exists ( DestinationPath ) )
236- {
237- File . Delete ( DestinationPath ) ;
238- }
224+ ZipExtractPath += Path . DirectorySeparatorChar ;
225+ }
239226
240- //Check the Destination is in the mods dir, then extract
241- if ( DestinationPath . StartsWith ( modsDir , StringComparison . Ordinal ) )
227+ //Open zip file index and extract only dll files
228+ using ( ZipArchive Archive = ZipFile . OpenRead ( ZipPath ) )
229+ {
230+ foreach ( ZipArchiveEntry Entry in Archive . Entries )
231+ {
232+ if ( Entry . FullName . EndsWith ( ".dll" , StringComparison . OrdinalIgnoreCase ) )
242233 {
243- Entry . ExtractToFile ( DestinationPath ) ;
234+ string DestinationPath = Path . GetFullPath ( Path . Combine ( modsDir , Entry . Name ) ) ;
235+
236+ //If the mod exists, delete it and replace with this one.
237+ if ( File . Exists ( DestinationPath ) )
238+ {
239+ File . Delete ( DestinationPath ) ;
240+ }
241+
242+ //Check the Destination is in the mods dir, then extract
243+ if ( DestinationPath . StartsWith ( modsDir , StringComparison . Ordinal ) )
244+ {
245+ Entry . ExtractToFile ( DestinationPath ) ;
246+ }
244247 }
245248 }
246249 }
247- }
248250
249- //Delete Zip archive once we are done as we have the DLL's now
250- File . Delete ( ZipPath ) ;
251+ //Delete Zip archive once we are done as we have the DLL's now
252+ if ( PMLConfig . ZipModMode )
253+ {
254+ File . Delete ( ZipPath ) ;
255+ }
256+ }
251257 }
252258
253259 // Load mods
0 commit comments