comparison pytouhou/resource/loader.py @ 298:92a6fd2632f1

Improve heuristic to filter out non-game exes (like custom.exe).
author Thibaut Girka <thib@sitedethib.com>
date Tue, 06 Mar 2012 18:58:41 +0100
parents a09ac4650e0d
children 61adb5453e46
comparison
equal deleted inserted replaced
297:a09ac4650e0d 298:92a6fd2632f1
21 from pytouhou.formats.std import Stage 21 from pytouhou.formats.std import Stage
22 from pytouhou.formats.ecl import ECL 22 from pytouhou.formats.ecl import ECL
23 from pytouhou.formats.anm0 import ANM0 23 from pytouhou.formats.anm0 import ANM0
24 from pytouhou.formats.msg import MSG 24 from pytouhou.formats.msg import MSG
25 from pytouhou.formats.sht import SHT 25 from pytouhou.formats.sht import SHT
26 from pytouhou.formats.exe import SHT as EoSDSHT 26 from pytouhou.formats.exe import SHT as EoSDSHT, InvalidExeException
27 27
28 28
29 from pytouhou.resource.anmwrapper import AnmWrapper 29 from pytouhou.resource.anmwrapper import AnmWrapper
30
31 from pytouhou.utils.helpers import get_logger
32
33 logger = get_logger(__name__)
34
30 35
31 36
32 class Directory(object): 37 class Directory(object):
33 def __init__(self, path): 38 def __init__(self, path):
34 self.path = path 39 self.path = path
91 96
92 97
93 98
94 class Loader(object): 99 class Loader(object):
95 def __init__(self, game_dir=None): 100 def __init__(self, game_dir=None):
96 self.exe = None 101 self.exe_files = []
97 self.game_dir = game_dir 102 self.game_dir = game_dir
98 self.known_files = {} 103 self.known_files = {}
99 self.instanced_ecls = {} 104 self.instanced_ecls = {}
100 self.instanced_anms = {} 105 self.instanced_anms = {}
101 self.instanced_stages = {} 106 self.instanced_stages = {}
111 path = os.path.join(self.game_dir, path) 116 path = os.path.join(self.game_dir, path)
112 yield glob(path) 117 yield glob(path)
113 paths = list(chain(*_expand_paths())) 118 paths = list(chain(*_expand_paths()))
114 path = paths[0] 119 path = paths[0]
115 if os.path.splitext(path)[1] == '.exe': 120 if os.path.splitext(path)[1] == '.exe':
116 self.exe = path 121 self.exe_files.extend(paths)
117 else: 122 else:
118 archive_description = ArchiveDescription.get_from_path(path) 123 archive_description = ArchiveDescription.get_from_path(path)
119 for name in archive_description.file_list: 124 for name in archive_description.file_list:
120 self.known_files[name] = archive_description 125 self.known_files[name] = archive_description
121 126
167 return self.instanced_shts[name] 172 return self.instanced_shts[name]
168 173
169 174
170 def get_eosd_characters(self): 175 def get_eosd_characters(self):
171 #TODO: Move to pytouhou.games.eosd? 176 #TODO: Move to pytouhou.games.eosd?
172 path = self.exe 177 for path in self.exe_files:
173 with open(path, 'rb') as file: 178 try:
174 characters = EoSDSHT.read(file) #TODO: modular 179 with open(path, 'rb') as file:
175 return characters 180 characters = EoSDSHT.read(file)
181 return characters
182 except InvalidExeException:
183 pass
184 logger.error("Required game exe not found!")
176 185
177 186
178 def get_anm_wrapper(self, names, offsets=None): 187 def get_anm_wrapper(self, names, offsets=None):
179 """Create an AnmWrapper for ANM files “names”. 188 """Create an AnmWrapper for ANM files “names”.
180 189