Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
nested_sarcs[file] = []
nested_sarcs[file].append(real_data)
for file, sarcs in nested_sarcs.items():
merged_bytes = merge_sarcs(file, sarcs)[1]
if Path(file).suffix.startswith('.s') and not file.endswith('.sarc'):
merged_bytes = util.compress(merged_bytes)
new_sarc.add_file(file, merged_bytes)
files_added.append(file)
for file in [file for file in all_files if file not in files_added]:
for opened_sarc in [open_sarc for open_sarc in opened_sarcs \
if file in open_sarc.list_files()]:
new_sarc.add_file(file, opened_sarc.get_file_data(file).tobytes())
break
if 'Bootup.pack' in file_name:
for merger in [merger() for merger in mergers.get_mergers() if merger.is_bootup_injector()]:
inject = merger.get_bootup_injection()
if not inject:
continue
file, data = inject
try:
new_sarc.delete_file(file)
except KeyError:
pass
new_sarc.add_file(file, data)
return (file_name, new_sarc.get_bytes())
def get_mod_edits(self, params=None):
mod = BcmlMod.from_json(params["mod"])
edits = {}
merger_list = sorted({m() for m in mergers.get_mergers()}, key=lambda m: m.NAME)
for merger in merger_list:
edits[merger.friendly_name] = merger.get_mod_edit_info(mod)
return {key: sorted({str(v) for v in value}) for key, value in edits.items()}
if Path(file).suffix.startswith(".s") and not file.endswith(".sarc"):
merged_bytes = util.compress(merged_bytes)
new_sarc.files[file] = merged_bytes
files_added.add(file)
for file in [file for file in all_files if file not in files_added]:
for opened_sarc in [
open_sarc
for open_sarc in opened_sarcs
if (file in [f.name for f in open_sarc.get_files()])
]:
new_sarc.files[file] = oead.Bytes(opened_sarc.get_file(file).data)
break
if "Bootup.pack" in file_name:
for merger in [
merger() for merger in mergers.get_mergers() if merger.is_bootup_injector()
]:
inject = merger.get_bootup_injection()
if not inject:
continue
file, data = inject
new_sarc.files[file] = data
return (file_name, bytes(new_sarc.write()[1]))
def enable(mods):
all_mergers = [merger() for merger in mergers.get_mergers()]
remergers = []
partials = {}
for mod in mods:
for merger in all_mergers:
if merger.is_mod_logged(mod):
if merger not in remergers:
remergers.append(merger)
if merger.can_partial_remerge():
if merger.NAME not in partials:
partials[merger.NAME] = set()
partials[merger.NAME] |= set(merger.get_mod_affected(mod))
for mod in mods:
install.enable_mod(mod, wait_merge=True)
for merger in mergers.sort_mergers(remergers):
if merger.NAME in partials:
merger.set_options({'only_these': partials[merger.NAME]})
if not self.listWidget.selectedItems():
return
mod = self.listWidget.selectedItems()[0].data(QtCore.Qt.UserRole)
if mod not in self._mod_infos:
rules = util.RulesParser()
if util.is_mod_disabled(mod):
rules.read(str(mod.path / 'rules.txt.disable'))
else:
rules.read(str(mod.path / 'rules.txt'))
font_met = QtGui.QFontMetrics(self.lblModInfo.font())
path = str(mod.path)
while font_met.boundingRect(f'Path: {path}.....').width() >= self.lblModInfo.width():
path = path[:-1]
changes = []
for merger in {cls() for cls in mergers.get_mergers()}:
if merger.is_mod_logged(mod):
changes.append(merger.NAME if not merger.NAME == 'rstb' else 'RSTB')
mod_info = [
f'<b>Name</b>: {mod.name}',
f'<b>Priority:</b> {mod.priority}',
f'<b>Path:</b> {path}...',
'<b>Description:</b> {}'.format(
str(rules["Definition"]["description"]).strip(' "\'')),
f'<b>Changes:</b> {", ".join(changes)}'
]
if util.is_mod_disabled(mod):
mod_info.insert(0, '<b><span style="color:#d32f2f">DISABLED</span></b>')
if 'url' in rules['Definition']:
mod_info.insert(3, util.get_mod_link_meta(rules))
try:
preview = util.get_mod_preview(mod, rules)
def enable_mod(mod: BcmlMod, wait_merge: bool = False):
print(f'Enabling {mod.name}...')
rules_path: Path = mod.path / 'rules.txt.disable'
rules_path.rename(rules_path.with_suffix(''))
# refresh_merges()
if not wait_merge:
print(f'Remerging affected files...')
remergers = []
partials = {}
for merger in [merger() for merger in mergers.get_mergers()]:
if merger.is_mod_logged(mod):
remergers.append(merger)
if merger.can_partial_remerge():
partials[merger.NAME] = merger.get_mod_affected(mod)
for merger in remergers:
if merger.NAME in partials:
merger.set_options({'only_these': partials[merger.NAME]})
merger.perform_merge()
refresh_cemu_mods()
print(f'{mod.name} enabled')
:type new_priority: int
:param wait_merge: Resort priorities but don't remerge anything yet, defaults to False.
:type wait_merge: bool, optional
:param verbose: Whether to display more detailed output, defaults to False.
:type verbose: bool, optional
"""
mod = util.get_mod_info(path / 'rules.txt')
print(
f'Changing priority of {mod.name} from {mod.priority} to {new_priority}...')
mods = util.get_installed_mods()
if new_priority > mods[len(mods) - 1][1]:
new_priority = len(mods) - 1
mods.remove(mod)
mods.insert(new_priority - 100, util.BcmlMod(mod.name, new_priority, path))
all_mergers = [merger() for merger in mergers.get_mergers()]
remergers = set()
partials = {}
for merger in all_mergers:
if merger.is_mod_logged(mod):
remergers.add(merger)
if merger.can_partial_remerge():
partials[merger.NAME] = set(merger.get_mod_affected(mod))
print('Resorting other affected mods...')
for mod in mods:
if mod.priority != (mods.index(mod) + 100):
adjusted_priority = mods.index(mod) + 100
mods.remove(mod)
mods.insert(adjusted_priority - 100,
BcmlMod(mod.name, adjusted_priority, mod.path))
if verbose:
return
else:
print(f'Error: {str(mod)} is neither a valid file nor a directory')
return
pool: Pool = None
try:
rules = util.RulesParser()
rules.read(tmp_dir / 'rules.txt')
mod_name = str(rules['Definition']['name']).strip(' "\'')
print(f'Identified mod: {mod_name}')
logs = tmp_dir / 'logs'
if logs.exists():
print('This mod supports Quick Install! Loading changes...')
for merger in [merger() for merger in mergers.get_mergers() \
if merger.NAME in options['disable']]:
if merger.is_mod_logged(BcmlMod('', 0, tmp_dir)):
(tmp_dir / 'logs' / merger.log_name()).unlink()
else:
pool = Pool(cpu_count())
generate_logs(tmp_dir=tmp_dir, verbose=verbose, options=options, original_pool=pool)
except Exception as e: # pylint: disable=broad-except
if hasattr(e, 'error_text'):
raise e
clean_error = RuntimeError()
try:
name = mod_name
except NameError:
name = 'your mod, the name of which could not be detected'
clean_error.error_text = (f'There was an error while processing {name}. '
'This could indicate there is a problem with the mod itself, '
def install_all(result: dict):
mods = []
from multiprocessing import Pool, cpu_count
pool = Pool(cpu_count())
for i, mod in enumerate(result['paths']):
mods.append(install.install_mod(
mod,
verbose=False,
options=result['options'],
wait_merge=True,
insert_priority=result['insert_priority'] + i
))
all_mergers = [merge_class() for merge_class in mergers.get_mergers()]
merges = set()
partials = {}
for mod in mods:
for merger in all_mergers:
if merger.is_mod_logged(mod):
merges.add(merger)
if merger.can_partial_remerge():
if not merger.NAME in partials:
partials[merger.NAME] = set()
partials[merger.NAME] |= set(merger.get_mod_affected(mod))
for merger in mergers.sort_mergers(merges):
if merger.NAME in result['options']:
merger.set_options(result['options'][merger.NAME])
if merger.NAME in partials:
merger.set_options({'only_these': partials[merger.NAME]})
merger.set_pool(pool)
"""
Uninstalls the mod currently installed at the specified path and updates merges as needed
:param mod: The mod to remove, as a path or a BcmlMod.
:param wait_merge: Resort mods but don't remerge anything yet, defaults to False.
:type wait_merge: bool, optional
:param verbose: Whether to display more detailed output, defaults to False.
:type verbose: bool, optional
"""
path = Path(mod) if isinstance(mod, str) else mod.path if isinstance(mod, BcmlMod) else mod
mod_name, mod_priority, _ = util.get_mod_info(path / 'rules.txt') \
if not isinstance(mod, BcmlMod) else mod
print(f'Uninstalling {mod_name}...')
remergers = set()
partials = {}
for merger in [merger() for merger in mergers.get_mergers()]:
if merger.is_mod_logged(BcmlMod(mod_name, mod_priority, path)):
remergers.add(merger)
if merger.can_partial_remerge():
partials[merger.NAME] = merger.get_mod_affected(mod)
shutil.rmtree(str(path))
next_mod = util.get_mod_by_priority(mod_priority + 1)
if next_mod:
print('Adjusting mod priorities...')
change_mod_priority(next_mod, mod_priority,
wait_merge=True, verbose=verbose)
print()
if not wait_merge:
pool = Pool(cpu_count())
for merger in mergers.sort_mergers(remergers):