mirror of
https://github.com/derrod/legendary.git
synced 2024-12-31 12:05:27 +00:00
[cli/core] Do not delete merely incomplete saves unless user says so
This commit is contained in:
parent
658cc94dbe
commit
106ed16a49
|
@ -408,7 +408,7 @@ class LegendaryCLI:
|
||||||
logger.error('Login failed! Cannot continue with download process.')
|
logger.error('Login failed! Cannot continue with download process.')
|
||||||
exit(1)
|
exit(1)
|
||||||
logger.info(f'Cleaning saves...')
|
logger.info(f'Cleaning saves...')
|
||||||
self.core.clean_saves(self._resolve_aliases(args.app_name))
|
self.core.clean_saves(self._resolve_aliases(args.app_name), args.delete_incomplete)
|
||||||
|
|
||||||
def sync_saves(self, args):
|
def sync_saves(self, args):
|
||||||
if not self.core.login():
|
if not self.core.login():
|
||||||
|
@ -1941,6 +1941,9 @@ def main():
|
||||||
sync_saves_parser.add_argument('--disable-filters', dest='disable_filters', action='store_true',
|
sync_saves_parser.add_argument('--disable-filters', dest='disable_filters', action='store_true',
|
||||||
help='Disable save game file filtering')
|
help='Disable save game file filtering')
|
||||||
|
|
||||||
|
clean_saves_parser.add_argument('--delete-incomplete', dest='delete_incomplete', action='store_true',
|
||||||
|
help='Delete incomplete save files')
|
||||||
|
|
||||||
import_parser.add_argument('--disable-check', dest='disable_check', action='store_true',
|
import_parser.add_argument('--disable-check', dest='disable_check', action='store_true',
|
||||||
help='Disables completeness check of the to-be-imported game installation '
|
help='Disables completeness check of the to-be-imported game installation '
|
||||||
'(useful if the imported game is a much older version or missing files)')
|
'(useful if the imported game is a much older version or missing files)')
|
||||||
|
|
|
@ -851,7 +851,7 @@ class LegendaryCore:
|
||||||
|
|
||||||
self.log.info('Successfully completed savegame download.')
|
self.log.info('Successfully completed savegame download.')
|
||||||
|
|
||||||
def clean_saves(self, app_name=''):
|
def clean_saves(self, app_name='', delete_incomplete=False):
|
||||||
savegames = self.egs.get_user_cloud_saves(app_name=app_name)
|
savegames = self.egs.get_user_cloud_saves(app_name=app_name)
|
||||||
files = savegames['files']
|
files = savegames['files']
|
||||||
deletion_list = []
|
deletion_list = []
|
||||||
|
@ -886,17 +886,25 @@ class LegendaryCore:
|
||||||
m = self.load_manifest(r.content)
|
m = self.load_manifest(r.content)
|
||||||
# check if all required chunks are present
|
# check if all required chunks are present
|
||||||
chunk_fnames = set()
|
chunk_fnames = set()
|
||||||
|
missing_chunks = 0
|
||||||
|
total_chunks = m.chunk_data_list.count
|
||||||
for chunk in m.chunk_data_list.elements:
|
for chunk in m.chunk_data_list.elements:
|
||||||
cpath_p = fname.split('/', 3)[:3]
|
cpath_p = fname.split('/', 3)[:3]
|
||||||
cpath_p.append(chunk.path)
|
cpath_p.append(chunk.path)
|
||||||
cpath = '/'.join(cpath_p)
|
cpath = '/'.join(cpath_p)
|
||||||
if cpath not in files:
|
|
||||||
self.log.error(f'Chunk missing, marking manifest for deletion.')
|
|
||||||
deletion_list.append(fname)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
chunk_fnames.add(cpath)
|
chunk_fnames.add(cpath)
|
||||||
else:
|
if cpath not in files:
|
||||||
|
missing_chunks += 1
|
||||||
|
|
||||||
|
if (0 < missing_chunks < total_chunks and delete_incomplete) or missing_chunks == total_chunks:
|
||||||
|
self.log.error(f'Chunk(s) missing, marking manifest for deletion.')
|
||||||
|
deletion_list.append(fname)
|
||||||
|
continue
|
||||||
|
elif 0 < missing_chunks < total_chunks:
|
||||||
|
self.log.error(f'Some chunk(s) missing, optionally run "legendary download-saves" to obtain a backup '
|
||||||
|
f'of the corrupted save, then re-run this command with "--delete-incomplete" to remove '
|
||||||
|
f'it from the cloud save service.')
|
||||||
|
|
||||||
used_chunks |= chunk_fnames
|
used_chunks |= chunk_fnames
|
||||||
|
|
||||||
# check for orphaned chunks (not used in any manifests)
|
# check for orphaned chunks (not used in any manifests)
|
||||||
|
|
Loading…
Reference in a new issue