tunic-tracker-redux/lib/saves.py

54 lines
1.9 KiB
Python
Raw Normal View History

import logging
import glob
import os
import re
# from collections import deque
def get_current_save_filename(saves_dir='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'):
"""Get the last modified save file in the saves directory.
Args:
saves_dir (str, optional): Path to the saves directory. Defaults to '/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'.
"""
try:
list_files = glob.glob(f'{saves_dir}/*.tunic')
except:
logging.error(
f'Something went wrong in looking for the saves directory at {saves_dir}')
try:
latest_save_path = max(list_files, key=os.path.getmtime)
except:
logging.warn('A save file was deleted.')
return
try:
latest_save_filename = re.search(
'([0-9]*)[a-z-]*~([0-9]*)\.tunic', latest_save_path)
except:
logging.error(f'Cannot perform regex successfully on save path: {latest_save_path}')
return
if latest_save_filename != None:
return (latest_save_filename[0], latest_save_filename[1])
return (None, None)
def get_visited_entrances(save_filename, saves_dir='/home/alice/Games/steam/steamapps/compatdata/553420/pfx/drive_c/users/steamuser/AppData/LocalLow/Andrew Shouldice/Secret Legend/SAVES'):
try:
with open(f'{saves_dir}/{save_filename}', 'r') as save:
save_file_text = save.read()
try:
save_entrances = re.findall('portal (.*)\|1\n', save_file_text)
except:
logging.error(
f'Unable to perform findall successfully on {save_filename}')
return
except:
logging.error(f'Could not find save file from path: {save_filename}')
return
return save_entrances