11import functools
2- import json
3- import os
42import shutil
53import typing
64from pathlib import Path
75
86import mobase
9- import yaml
107from PyQt6 .QtCore import (
118 QCoreApplication ,
129 QDir ,
@@ -59,7 +56,7 @@ def __init__(self, name: str):
5956 self ._name = name
6057 from . import lslib_retriever , pak_parser
6158
62- self ._lslib_retriever = lslib_retriever .LSLibRetriever (self )
59+ self .lslib_retriever = lslib_retriever .LSLibRetriever (self )
6360 self ._pak_parser = pak_parser .BG3PakParser (self )
6461
6562 def init (self , organizer : mobase .IOrganizer ):
@@ -150,7 +147,6 @@ def create_progress_window(
150147
151148 def on_user_interface_initialized (self , window : QMainWindow ) -> None :
152149 self .main_window = window
153- pass
154150
155151 def on_settings_changed (
156152 self ,
@@ -161,24 +157,7 @@ def on_settings_changed(
161157 ) -> None :
162158 if self ._name != plugin_name :
163159 return
164- if new and setting == "check_for_lslib_updates" :
165- try :
166- self ._lslib_retriever .download_lslib_if_missing ()
167- finally :
168- self ._set_setting (setting , False )
169- elif new and setting == "force_reparse_metadata" :
170- try :
171- self .construct_modsettings_xml (
172- exec_path = "bin/bg3" , force_reparse_metadata = True
173- )
174- finally :
175- self ._set_setting (setting , False )
176- elif new and setting == "convert_jsons_to_yaml" :
177- try :
178- self ._convert_jsons_to_yaml ()
179- finally :
180- self ._set_setting (setting , False )
181- elif setting in {
160+ if setting in {
182161 "extract_full_package" ,
183162 "autobuild_paks" ,
184163 "remove_extracted_metadata" ,
@@ -197,7 +176,7 @@ def construct_modsettings_xml(
197176 ) -> bool :
198177 if (
199178 "bin/bg3" not in exec_path
200- or not self ._lslib_retriever .download_lslib_if_missing ()
179+ or not self .lslib_retriever .download_lslib_if_missing ()
201180 ):
202181 return True
203182 active_mods = self .active_mods ()
@@ -257,41 +236,6 @@ def retrieve_mod_metadata_in_new_thread(mod: mobase.IModInterface):
257236 shutil .copy (self .modsettings_path , self .modsettings_backup )
258237 return True
259238
260- def _convert_jsons_to_yaml (self ):
261- qInfo ("converting all json files to yaml" )
262- active_mods = self .active_mods ()
263- progress = self .create_progress_window (
264- "Converting all json files to yaml" , len (active_mods ) + 1
265- )
266- for mod in active_mods :
267- _convert_jsons_in_dir_to_yaml (Path (mod .absolutePath ()))
268- progress .setValue (progress .value () + 1 )
269- QApplication .processEvents ()
270- if progress .wasCanceled ():
271- qWarning ("conversion canceled by user" )
272- return
273- _convert_jsons_in_dir_to_yaml (self .overwrite_path )
274- progress .setValue (len (active_mods ) + 1 )
275- QApplication .processEvents ()
276- progress .close ()
277-
278239 def on_mod_installed (self , mod : mobase .IModInterface ) -> None :
279- if self ._lslib_retriever .download_lslib_if_missing ():
240+ if self .lslib_retriever .download_lslib_if_missing ():
280241 self ._pak_parser .get_metadata_for_files_in_mod (mod , True )
281-
282-
283- def _convert_jsons_in_dir_to_yaml (path : Path ):
284- for file in list (path .rglob ("*.json" )):
285- converted_path = file .parent / file .name .replace (".json" , ".yaml" )
286- try :
287- if not converted_path .exists () or os .path .getmtime (file ) > os .path .getmtime (
288- converted_path
289- ):
290- with open (file , "r" ) as json_file :
291- with open (converted_path , "w" ) as yaml_file :
292- yaml .dump (
293- json .load (json_file ), yaml_file , indent = 2 , sort_keys = False
294- )
295- qInfo (f"Converted { file } to YAML" )
296- except OSError as e :
297- qWarning (f"Error accessing file { converted_path } : { e } " )
0 commit comments