mirror of
https://github.com/Faraphel/Atlas-Install.git
synced 2025-07-05 20:28:27 +02:00
fixed untouched patched file content being erased if the mode was set to "edit"
This commit is contained in:
parent
e403d1dce1
commit
69aa29c630
1 changed files with 7 additions and 6 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
from io import BytesIO
|
||||||
from typing import Generator, IO
|
from typing import Generator, IO
|
||||||
|
|
||||||
from source.mkw.Patch import *
|
from source.mkw.Patch import *
|
||||||
|
@ -45,13 +46,15 @@ class PatchFile(PatchObject):
|
||||||
|
|
||||||
# if the file is a special file
|
# if the file is a special file
|
||||||
if self.full_path.name.startswith("#"):
|
if self.full_path.name.startswith("#"):
|
||||||
print(f"special file : {self} [install to {game_subpath}]")
|
# print(f"special file : {self} [install to {game_subpath}]")
|
||||||
return
|
return
|
||||||
|
|
||||||
# apply operation on the file
|
# apply operation on the file
|
||||||
patch_source: Path = self.get_source_path(game_subpath)
|
patch_source: Path = self.get_source_path(game_subpath)
|
||||||
patch_name: str = game_subpath.name
|
patch_name: str = game_subpath.name
|
||||||
patch_content: IO = open(patch_source, "rb")
|
patch_content: BytesIO = BytesIO(open(patch_source, "rb").read())
|
||||||
|
# the file is converted into a BytesIO because if the mode is "edit",
|
||||||
|
# the file is overwritten and if the content is untouched, the file will only be lost
|
||||||
|
|
||||||
for operation_name, operation in self.configuration.get("operation", {}).items():
|
for operation_name, operation in self.configuration.get("operation", {}).items():
|
||||||
# process every operation and get the new patch_path (if the name is changed)
|
# process every operation and get the new patch_path (if the name is changed)
|
||||||
|
@ -63,11 +66,10 @@ class PatchFile(PatchObject):
|
||||||
match self.configuration["mode"]:
|
match self.configuration["mode"]:
|
||||||
# if the mode is copy, replace the subfile in the game by the PatchFile
|
# if the mode is copy, replace the subfile in the game by the PatchFile
|
||||||
case "copy" | "edit":
|
case "copy" | "edit":
|
||||||
print(f"[copy] copying {self} to {game_subpath}")
|
# print(f"[{self.configuration['mode']}] copying {self} to {game_subpath}")
|
||||||
|
|
||||||
game_subpath.parent.mkdir(parents=True, exist_ok=True)
|
game_subpath.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with open(game_subpath.parent / patch_name, "wb") as file:
|
with open(game_subpath.parent / patch_name, "wb") as file:
|
||||||
patch_content.seek(0)
|
|
||||||
file.write(patch_content.read())
|
file.write(patch_content.read())
|
||||||
|
|
||||||
# if the mode is match, replace all the subfiles that match match_regex by the PatchFile
|
# if the mode is match, replace all the subfiles that match match_regex by the PatchFile
|
||||||
|
@ -77,11 +79,10 @@ class PatchFile(PatchObject):
|
||||||
if not game_subfile.relative_to(extracted_game.path):
|
if not game_subfile.relative_to(extracted_game.path):
|
||||||
raise PathOutsidePatch(game_subfile, extracted_game.path)
|
raise PathOutsidePatch(game_subfile, extracted_game.path)
|
||||||
# patch the game with the subpatch
|
# patch the game with the subpatch
|
||||||
print(f"[match] copying {self} to {game_subfile}")
|
# print(f"[match] copying {self} to {game_subfile}")
|
||||||
|
|
||||||
game_subfile.parent.mkdir(parents=True, exist_ok=True)
|
game_subfile.parent.mkdir(parents=True, exist_ok=True)
|
||||||
with open(game_subfile, "wb") as file:
|
with open(game_subfile, "wb") as file:
|
||||||
patch_content.seek(0)
|
|
||||||
file.write(patch_content.read())
|
file.write(patch_content.read())
|
||||||
|
|
||||||
# ignore if mode is "ignore", useful if the file is used as a resource for an operation
|
# ignore if mode is "ignore", useful if the file is used as a resource for an operation
|
||||||
|
|
Loading…
Reference in a new issue