Skip to content

Commit

Permalink
Generalize do_install
Browse files Browse the repository at this point in the history
do_install previously required appending an appropriate component.Mod
class to self.mods. This could create issues in subclasses because they
might end up with the wrong type of component in self.mods.

Instead, just try/finally and refresh at the end. This removes the
requirement for a specific mod class instantiation in do_install.
  • Loading branch information
cyberrumor committed Dec 15, 2024
1 parent 2bfd020 commit 25eb748
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions ammo/controller/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,38 +840,35 @@ def install_download(index, download) -> None:
for file in next(extract_to.iterdir()).iterdir():
file.rename(extract_to / file.name)

# Add the freshly install mod to self.mods so that an error doesn't prevent
# any successfully installed mods from appearing during 'install all'.
self.mods.append(
Mod(
location=extract_to,
game_root=self.game.directory,
)
)

if index == "all":
errors = []
for i, download in enumerate(self.downloads):
if download.visible:
try:
install_download(i, download)
except Warning as e:
errors.append(str(e))
if errors:
raise Warning("\n".join(errors))
else:
index = int(index)
try:
download = self.downloads[index]
except IndexError as e:
raise Warning(e)
try:
if index == "all":
errors = []
for i, download in enumerate(self.downloads):
if download.visible:
try:
install_download(i, download)
except Warning as e:
errors.append(str(e))
if errors:
raise Warning("\n".join(errors))
else:
index = int(index)
try:
download = self.downloads[index]
except IndexError as e:
raise Warning(e)

if not download.visible:
raise Warning("You can only install visible downloads.")
if not download.visible:
raise Warning("You can only install visible downloads.")

install_download(index, download)
install_download(index, download)

self.do_refresh()
finally:
# Add freshly installed mods to self.mods so that an error doesn't prevent
# any successfully installed mods from appearing during 'install all'.
# This is better than adding to self.mods during install_download because
# subclasses of ModController might use a different class than component.Mod.
self.do_refresh()

@requires_sync
def do_tools(self) -> None:
Expand Down

0 comments on commit 25eb748

Please sign in to comment.