Skip to content

Commit

Permalink
Remove explicit references to "Data"
Browse files Browse the repository at this point in the history
Use game.data.name or mod.game_data.name instead. This will help add
Morrowind support later.
  • Loading branch information
cyberrumor committed Feb 4, 2024
1 parent d30aaef commit 92b582b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
11 changes: 7 additions & 4 deletions ammo/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __post_init__(self) -> None:
match file.is_dir():
case True:
match file.name.lower():
case "data":
case "data" | "data files":
self.install_dir = self.game_root

case "edit scripts":
Expand All @@ -71,10 +71,10 @@ def __post_init__(self) -> None:
self.install_dir = self.game_root

# Determine which folder to populate self.files from. For fomods, only
# care about files inside of a Data folder which may or may not exist.
# care about files inside of a game_data.name folder which may or may not exist.
location = self.location
if self.fomod:
location = location / "Data"
location = location / self.game_data.name

# Populate self.files
for parent_dir, _, files in os.walk(location):
Expand All @@ -84,7 +84,10 @@ def __post_init__(self) -> None:

if f.suffix.lower() in (".esp", ".esl", ".esm") and not f.is_dir():
# Only associate plugins if the plugins are under a data dir.
if loc_parent == self.location or loc_parent.name.lower() == "data":
if (
loc_parent == self.location
or loc_parent.name.lower() == self.game_data.name.lower()
):
self.plugins.append(f.name)

self.files.append(loc_parent / f)
Expand Down
7 changes: 4 additions & 3 deletions ammo/fomod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ def _get_nodes(self) -> list[ElementTree.Element]:
def _install_files(self, selected_nodes: list) -> None:
"""
Copy the chosen files 'selected_nodes' from given mod at 'index'
to that mod's Data folder.
to that mod's game files folder.
"""
data = self.mod.location / "Data"
data = self.mod.location / self.mod.game_data.name

# delete the old configuration if it exists
shutil.rmtree(data, ignore_errors=True)
Expand All @@ -375,7 +375,8 @@ def _install_files(self, selected_nodes: list) -> None:
break
full_source = full_source / folder

# get the 'destination' folder from the xml. This path is relative to Data.
# get the 'destination' folder from the xml. This path is relative to
# the mod's game files folder.
full_destination = reduce(
lambda path, name: path / name,
node.get("destination").split("\\"),
Expand Down
2 changes: 1 addition & 1 deletion ammo/game_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _manage_game(self, index: int) -> None:
case "Skyrim":

def enabled_formula(line) -> bool:
return len(line.strip()) > 0 and not line.strip()[0].startswith("*")
return not line.strip().startswith("*")

case _:

Expand Down
1 change: 1 addition & 0 deletions ammo/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def normalize(destination: Path, dest_prefix: Path) -> Path:
file = destination.name
local_path = str(path).split(str(dest_prefix))[-1].lower()
for i in [
"Data Files",
"Data",
"DynDOLOD",
"Plugins",
Expand Down
21 changes: 11 additions & 10 deletions ammo/mod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def _get_validated_components(self, component: ComponentEnum) -> list:
f"""\
Expected {[i.value for i in list(ComponentEnum)]},
got {component} of type {type(component)}
"""
"""
)
)

Expand Down Expand Up @@ -408,7 +408,7 @@ def _stage(self) -> dict:
# destination: (mod_name, source)
result = {}
# Iterate through enabled mods in order.
for mod in [i for i in self.mods if i.enabled]:
for mod in (i for i in self.mods if i.enabled):
# Iterate through the source files of the mod
for src in mod.files:
# Get the sanitized full path relative to the game.directory.
Expand Down Expand Up @@ -438,7 +438,7 @@ def _remove_empty_dirs(self):
except OSError:
pass

def _clean_data_dir(self):
def _clean_game_dir(self):
"""
Removes all links and deletes empty folders.
"""
Expand All @@ -461,7 +461,7 @@ def configure(self, index: int) -> None:

# Since there must be a hard refresh after the fomod wizard to load the mod's new
# files, deactivate this mod and commit changes. This prevents a scenario where
# the user could re-configure a fomod (thereby changing mod.location/Data),
# the user could re-configure a fomod (thereby changing mod.location/self.game.data.name),
# and quit ammo without running 'commit', which could leave broken symlinks in their
# game.directory.

Expand All @@ -477,7 +477,7 @@ def configure(self, index: int) -> None:

# Clean up previous configuration, if it exists.
try:
shutil.rmtree(mod.location / "Data")
shutil.rmtree(mod.location / self.game.data.name)
except FileNotFoundError:
pass

Expand Down Expand Up @@ -619,7 +619,7 @@ def rename(self, component: RenameEnum, index: int, name: str) -> None:
raise Warning(f"A mod named {str(new_location)} already exists!")

# Remove symlinks instead of breaking them.
self._clean_data_dir()
self._clean_game_dir()

# Move the folder, update the mod.
mod.location.rename(new_location)
Expand Down Expand Up @@ -688,7 +688,8 @@ def get_plugin_files(plugin):
(
file.name == plugin.name and not file.is_dir(),
file.parent == mod.location
or file.parent.name.lower() == "data",
or file.parent.name.lower()
== self.game.data.name.lower(),
)
):
yield file
Expand Down Expand Up @@ -761,7 +762,7 @@ def has_extra_folder(path) -> bool:
files[0].is_dir(),
files[0].name.lower()
not in [
"data",
self.game.data.name.lower(),
"skse",
"bashtags",
"docs",
Expand Down Expand Up @@ -808,7 +809,7 @@ def install_download(index, download) -> None:
if has_extra_folder(extract_to):
# It is reasonable to conclude an extra directory can be eliminated.
# This is needed for mods like skse that have a version directory
# between the mod's base folder and the Data folder.
# between the mod's base folder and the self.game.data.name folder.
for file in next(extract_to.iterdir()).iterdir():
file.rename(extract_to / file.name)

Expand Down Expand Up @@ -872,7 +873,7 @@ def commit(self) -> None:
"""
self._save_order()
stage = self._stage()
self._clean_data_dir()
self._clean_game_dir()

count = len(stage)
skipped_files = []
Expand Down

0 comments on commit 92b582b

Please sign in to comment.