Skip to content

Commit

Permalink
improve patch logging
Browse files Browse the repository at this point in the history
  • Loading branch information
th3w1zard1 committed Nov 7, 2023
1 parent c62ec75 commit a5b15dd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pykotor/tslpatcher/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def lookup_resource(
return BinaryReader.load_file(output_container_path / patch.saveas)
return capsule.resource(*ResourceIdentifier.from_path(patch.saveas))
except OSError as e:
self.log.add_error(repr(e))
self.log.add_error(f"Could not load source file to {patch.action.lower().strip()}: {e!r}")
return None

def handle_override_type(self, patch: PatcherModifications):
Expand All @@ -274,7 +274,7 @@ def handle_override_type(self, patch: PatcherModifications):
shutil.move(override_resource_path, new_filepath)
except Exception as e: # noqa: BLE001
# Handle exceptions such as permission errors or file in use.
self.log.add_error(f"Could not rename file to {new_filepath.name}: {e!r}")
self.log.add_error(f"Could not rename '{patch.saveas}' to '{new_filepath.name}' in the Override folder: {e!r}")
elif override_type == OverrideType.WARN:
self.log.add_warning(f"A resource located at '{override_resource_path}' is shadowing this mod's changes in {patch.destination}!")

Expand All @@ -288,14 +288,15 @@ def should_patch(
container_type = "folder" if capsule is None else "archive"

if patch.replace_file and exists:
self.log.add_note(f"{patch.action[:-1]}ing '{patch.sourcefile}' and replacing existing file '{patch.saveas}' in the '{local_folder}' {container_type}")
saveas = f"'{patch.saveas}' " if patch.saveas != patch.sourcefile else ""
self.log.add_note(f"{patch.action[:-1]}ing '{patch.sourcefile}' and replacing existing file {saveas}in the '{local_folder}' {container_type}")
return True

if not patch.skip_if_not_replace and not patch.replace_file and exists:
self.log.add_note(f"{patch.action[:-1]}ing existing file '{patch.saveas}' in the '{local_folder}' {container_type}")
return True

if patch.skip_if_not_replace and not patch.replace_file and exists: # [InstallList] only?
if patch.skip_if_not_replace and not patch.replace_file and exists: # [InstallList] only
self.log.add_warning(f"'{patch.saveas}' already exists in the '{local_folder}' {container_type}. Skipping file...")
return False

Expand All @@ -304,7 +305,7 @@ def should_patch(
return False

# In capsules, I haven't seen any TSLPatcher mods reach this point. I know TSLPatcher at least supports this portion for non-capsules.
# Most mods will use an [InstallList] to ensure the files exist in the game path before patching anyways, but not all.
# Most mods will use an [InstallList] to ensure the files exist before patching anyways, but not all.
save_type: str = "adding" if capsule is not None else "saving"
saving_as_str = f"as '{patch.saveas}' " if patch.saveas != patch.sourcefile else ""
self.log.add_note(f"{patch.action[:-1]}ing '{patch.sourcefile}' and {save_type} {saving_as_str}to the '{local_folder}' {container_type}")
Expand Down Expand Up @@ -333,6 +334,8 @@ def install(self) -> None:
if data_to_patch_bytes is None: # check None instead of `not data_to_patch_bytes` as sometimes mods will installlist empty files.
self.log.add_error(f"Could not locate resource to {patch.action.lower().strip()}: '{patch.sourcefile}'")
continue
if not data_to_patch_bytes:
self.log.add_warning(f"'{patch.sourcefile}' has no content/data and is completely empty.")

patched_bytes_data = patch.apply(data_to_patch_bytes, memory, self.log, self.game())
if capsule is not None:
Expand Down
1 change: 0 additions & 1 deletion pykotor/tslpatcher/mods/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import shutil
from typing import TYPE_CHECKING
from pykotor.common.stream import BinaryReader

from pykotor.tools.path import CaseAwarePath, PurePath
from pykotor.tslpatcher.mods.template import PatcherModifications
Expand Down

0 comments on commit a5b15dd

Please sign in to comment.