From beb724dfdc3fdc395b1b63644f7f486f4172ed0b Mon Sep 17 00:00:00 2001 From: Peridexis Errant Date: Mon, 9 Feb 2015 11:06:43 +1100 Subject: [PATCH] Check can_rebuild faster and without false negatives. By just confirming all components are available, rather than rebuilding. This has a chance of breaking saves cases where the installed_raws.txt is incorrect, but will skip unlogged saves and is essential if saves are to update at all. --- core/baselines.py | 2 +- core/graphics.py | 29 +++++------------------------ 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/core/baselines.py b/core/baselines.py index f939935..a34d576 100644 --- a/core/baselines.py +++ b/core/baselines.py @@ -4,6 +4,7 @@ from __future__ import print_function, unicode_literals, absolute_import import os, glob, zipfile, fnmatch +from io import open from . import paths, update from .lnp import lnp @@ -135,7 +136,6 @@ def remove_vanilla_raws_from_pack(pack, folder): i += 1 except UnicodeDecodeError: pass - return i def remove_empty_dirs(pack, folder): diff --git a/core/graphics.py b/core/graphics.py index 92f232d..f505760 100644 --- a/core/graphics.py +++ b/core/graphics.py @@ -275,30 +275,11 @@ def can_rebuild(log_file, strict=True): """Test if user can exactly rebuild a raw folder, returning a bool.""" if not os.path.isfile(log_file): return not strict - mods.clear_temp() - mods_list = mods.read_installation_log(log_file) - add_to_mods_merge(logged_graphics(log_file)) - for m in mods_list: - mods.merge_a_mod(m) - save_raws = os.path.dirname(log_file) - gen_raws = paths.get('baselines', 'raw') - for root, _, files in os.walk(save_raws): - for k in files: - if not k.endswith('.txt'): - continue - f = os.path.relpath(os.path.join(root, k), save_raws) - if not os.path.isfile(os.path.join(gen_raws, f)): - return False - with open(os.path.join(gen_raws, f), mode='r', encoding='cp437', - errors='replace') as a: - with open(os.path.join(root, k), mode='r', encoding='cp437', - errors='replace') as b: - try: - if a.read() != b.read(): - return False - except UnicodeDecodeError: - return False - return True + if (logged_graphics(log_file) in [k[0] for k in read_graphics()] and + all(m in mods.read_mods() for m in + mods.read_installation_log(log_file))): + return True + return False def open_tilesets(): """Opens the tilesets folder."""