Skip to content

Commit

Permalink
Merge pull request #1129 from BEEmod/dev
Browse files Browse the repository at this point in the history
Version 4.35.1
  • Loading branch information
TeamSpen210 authored Jun 6, 2019
2 parents 9fcc0cf + 70284ff commit 21fea6c
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/gameMan.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def quit_application():
sys.exit()


def app_is_bee2(file: str) -> bool:
def should_backup_app(file: str) -> bool:
"""Check if the given application is Valve's, or ours.
We do this by checking for the PyInstaller archive.
Expand All @@ -257,12 +257,20 @@ def app_is_bee2(file: str) -> bool:
try:
f = open(file, 'rb')
except FileNotFoundError:
# Treat missing as ours - we don't want to back those up.
return True
# We don't want to backup missing files.
return False

SIZE = 4096

with f:
f.seek(4096, io.SEEK_END)
return b'MEI\014\013\012\013\016' in f.read(4096)
f.seek(0, io.SEEK_END)
if f.tell() < SIZE:
return False # Too small.

# Read out the last 4096 bytes, and look for the sig in there.
f.seek(-SIZE,io.SEEK_END)

return b'MEI\014\013\012\013\016' not in f.read(SIZE)


class Game:
Expand Down Expand Up @@ -715,17 +723,18 @@ def export(
elif name == 'Editoritems':
should_backup = not os.path.isfile(backup_path)
else:
# If the normal one is not ours, always backup.
norm_ours = app_is_bee2(item_path)
backup_ours = app_is_bee2(backup_path)
# Always backup the non-_original file, it'd be newer.
# But only if it's Valves - not our own.
should_backup = should_backup_app(item_path)
backup_is_good = should_backup_app(backup_path)
LOGGER.info(
'{}{}: normal={}, backup={}',
file, ext,
'BEE2' if norm_ours else 'Valve',
'BEE2' if backup_ours else 'Valve',
'Valve' if should_backup else 'BEE2',
'Valve' if backup_is_good else 'BEE2',
)

if norm_ours and backup_ours:
if not should_backup and not backup_is_good:
# It's a BEE2 application, we have a problem.
# Both the real and backup are bad, we need to get a
# new one.
Expand Down Expand Up @@ -754,9 +763,6 @@ def export(
webbrowser.open('steam://validate/' + str(self.steamID))
return False, vpk_success

# Always backup the non-_original file, it'd be newer.
should_backup = not norm_ours

if should_backup:
LOGGER.info('Backing up original {}!', name)
shutil.copy(item_path, backup_path)
Expand Down

0 comments on commit 21fea6c

Please sign in to comment.