1111import traceback
1212import urllib .request
1313import zipfile
14- from configparser import SectionProxy
1514from functools import cached_property
1615from pathlib import Path
1716from typing import Any , Callable , Optional
@@ -283,6 +282,7 @@ def map_files(
283282 map_files (self ._overwrite_path )
284283 progress .setValue (len (active_mods ) + 1 )
285284 QApplication .processEvents ()
285+ progress .close ()
286286 return mappings
287287
288288 @cached_property
@@ -317,7 +317,7 @@ def _divine_command(self):
317317
318318 @cached_property
319319 def _folder_pattern (self ):
320- return re .compile ("Data|Script Extender|bin" )
320+ return re .compile ("Data|Script Extender|bin|Mods " )
321321
322322 @cached_property
323323 def _tools_dir (self ):
@@ -395,10 +395,6 @@ def _create_progress_window(
395395 progress .show ()
396396 return progress
397397
398- def _refresh_attr (self , setting : str ):
399- if hasattr (self , setting ):
400- delattr (self , setting )
401-
402398 def _on_settings_changed (
403399 self ,
404400 plugin_name : str ,
@@ -426,8 +422,8 @@ def _on_settings_changed(
426422 "remove_extracted_metadata" ,
427423 "force_load_dlls" ,
428424 "log_diff" ,
429- }:
430- self . _refresh_attr ( f"_{ setting } " )
425+ } and hasattr ( self , f"_ { setting } " ) :
426+ delattr ( self , f"_{ setting } " )
431427
432428 def _on_user_interface_initialized (self , window : QMainWindow ) -> None :
433429 self ._main_window = window
@@ -515,6 +511,7 @@ def get_runnable(mod: mobase.IModInterface):
515511 QtCore .QThread .msleep (100 )
516512 progress .setValue (num_active_mods )
517513 QApplication .processEvents (QEventLoop .ProcessEventsFlag .AllEvents , 100 )
514+ progress .close ()
518515 qInfo (f"writing mod load order to { self ._modsettings_path } " )
519516 self ._modsettings_path .write_text (
520517 (
@@ -639,44 +636,48 @@ def extract_data(output_file: Path) -> bool:
639636 return False
640637 return True
641638
642- def parse_meta_lsx (meta_file : Path , section : SectionProxy ):
643- root = (
644- ElementTree .parse (meta_file ).getroot ().find (".//node[@id='ModuleInfo']" )
645- )
646- if root is None :
647- qInfo (f"No ModuleInfo node found in meta.lsx for { mod .name ()} " )
648- return
649- folder_name = get_attr_value (root , "Folder" )
650- if file .is_dir ():
651- self ._mod_cache [file ] = (
652- len (list (file .glob (f"*/{ folder_name } /**" ))) > 1
653- or len (list (file .glob ("Public/Engine/Timeline/MaterialGroups/*" )))
654- > 0
655- )
656- elif file not in self ._mod_cache :
657- # a mod which has a meta.lsx and is not an override mod meets at least one of three conditions:
658- # 1. it has files in Public/Engine/Timeline/MaterialGroups, or
659- # 2. it has files in Mods/<folder_name>/ other than the meta.lsx file, or
660- # 3. it has files in Public/<folder_name>
661- result = run_divine (
662- f'list-package --use-regex -x "(/{ folder_name } /(?!meta\\ .lsx))|(Public/Engine/Timeline/MaterialGroups)"' ,
663- file ,
664- )
665- self ._mod_cache [file ] = (
666- result .returncode == 0 and result .stdout .strip () != ""
667- )
668- if self ._mod_cache [file ]:
669- for key in self ._types :
670- section [key ] = get_attr_value (root , key )
671- else :
672- qInfo (f"pak { file .name } determined to be an override mod" )
673- section ["override" ] = "True"
674- section ["Folder" ] = folder_name
675-
676639 def metadata_to_ini (condition : bool , to_parse : Callable [[], Path ]):
677640 config [file .name ] = {}
678641 if condition :
679- parse_meta_lsx (to_parse (), config [file .name ])
642+ root = (
643+ ElementTree .parse (to_parse ())
644+ .getroot ()
645+ .find (".//node[@id='ModuleInfo']" )
646+ )
647+ if root is None :
648+ qInfo (f"No ModuleInfo node found in meta.lsx for { mod .name ()} " )
649+ else :
650+ section = config [file .name ]
651+ folder_name = get_attr_value (root , "Folder" )
652+ if file .is_dir ():
653+ self ._mod_cache [file ] = (
654+ len (list (file .glob (f"*/{ folder_name } /**" ))) > 1
655+ or len (
656+ list (
657+ file .glob ("Public/Engine/Timeline/MaterialGroups/*" )
658+ )
659+ )
660+ > 0
661+ )
662+ elif file not in self ._mod_cache :
663+ # a mod which has a meta.lsx and is not an override mod meets at least one of three conditions:
664+ # 1. it has files in Public/Engine/Timeline/MaterialGroups, or
665+ # 2. it has files in Mods/<folder_name>/ other than the meta.lsx file, or
666+ # 3. it has files in Public/<folder_name>
667+ result = run_divine (
668+ f'list-package --use-regex -x "(/{ folder_name } /(?!meta\\ .lsx))|(Public/Engine/Timeline/MaterialGroups)"' ,
669+ file ,
670+ )
671+ self ._mod_cache [file ] = (
672+ result .returncode == 0 and result .stdout .strip () != ""
673+ )
674+ if self ._mod_cache [file ]:
675+ for key in self ._types :
676+ section [key ] = get_attr_value (root , key )
677+ else :
678+ qInfo (f"pak { file .name } determined to be an override mod" )
679+ section ["override" ] = "True"
680+ section ["Folder" ] = folder_name
680681 else :
681682 config [file .name ]["override" ] = "True"
682683 with open (meta_ini , "w+" , encoding = "utf-8" ) as f :
@@ -720,7 +721,9 @@ def metadata_to_ini(condition: bool, to_parse: Callable[[], Path]):
720721 False ,
721722 ):
722723 qInfo (f"packable dir: { file } " )
723- if (file .parent / f"{ file .name } .pak" ).exists ():
724+ if (file .parent / f"{ file .name } .pak" ).exists () or (
725+ file .parent / f"Mods/{ file .name } .pak"
726+ ).exists ():
724727 qInfo (
725728 f"pak with same name as packable dir exists in mod directory. not packing dir { file } "
726729 )
@@ -729,20 +732,17 @@ def metadata_to_ini(condition: bool, to_parse: Callable[[], Path]):
729732 build_pak = True
730733 if pak_path .exists ():
731734 pak_creation_time = os .path .getmtime (pak_path )
732-
733- def changes_since_creation ():
734- for root , _ , files in os .walk (file ):
735- for f in files :
736- file_path = os .path .join (root , f )
737- try :
738- if os .path .getmtime (file_path ) > pak_creation_time :
739- return True
740- except OSError as e :
741- qDebug (f"Error accessing file { file_path } : { e } " )
742- return True
743- return False
744-
745- build_pak = changes_since_creation ()
735+ for root , _ , files in os .walk (file ):
736+ for f in files :
737+ file_path = os .path .join (root , f )
738+ try :
739+ if os .path .getmtime (file_path ) > pak_creation_time :
740+ break
741+ except OSError as e :
742+ qDebug (f"Error accessing file { file_path } : { e } " )
743+ break
744+ else :
745+ build_pak = False
746746 if build_pak :
747747 pak_path .unlink (missing_ok = True )
748748 if run_divine (f'create-package -d "{ pak_path } "' , file ).returncode :
@@ -815,6 +815,7 @@ def reporthook(block_num: int, block_size: int, total_size: int) -> None:
815815 urllib .request .urlretrieve (
816816 assets ["browser_download_url" ], str (zip_path ), reporthook
817817 )
818+ progress .close ()
818819 downloaded = True
819820 for archive in old_archives :
820821 archive .unlink ()
@@ -857,6 +858,7 @@ def reporthook(block_num: int, block_size: int, total_size: int) -> None:
857858 )
858859 x_progress .setValue (x_progress .value () + 1 )
859860 QApplication .processEvents ()
861+ x_progress .close ()
860862 shutil .rmtree (self ._tools_dir / "Packed" , ignore_errors = True )
861863 except Exception as e :
862864 qDebug (f"Extraction failed: { e } " )
0 commit comments