-
Notifications
You must be signed in to change notification settings - Fork 15
/
prepare.py
121 lines (105 loc) · 3.9 KB
/
prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"""
Utility module to prepare the data for the parser.
"""
import logging
import subprocess
import winreg
from pathlib import Path
# Titan Quest Anniversary Edition registry key:
LOOKUP_KEY = (r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
r'\Steam App 475150')
# Extract commands to run:
COMMANDS = [
['Toolset/Templates.arc', 'data/database'],
['Text/Text_CH.arc', 'data/resources/zh'],
['Text/Text_CZ.arc', 'data/resources/cs'],
['Text/Text_DE.arc', 'data/resources/de'],
['Text/Text_EN.arc', 'data/resources/en'],
['Text/Text_ES.arc', 'data/resources/es'],
['Text/Text_FR.arc', 'data/resources/fr'],
['Text/Text_IT.arc', 'data/resources/it'],
['Text/Text_JA.arc', 'data/resources/ja'],
['Text/Text_KO.arc', 'data/resources/ko'],
['Text/Text_PL.arc', 'data/resources/pl'],
['Text/Text_RU.arc', 'data/resources/ru'],
['Text/Text_UK.arc', 'data/resources/uk'],
['Resources/Quests.arc', 'data/quests'],
['Resources/XPack/Quests.arc', 'data/quests'],
['Resources/XPack2/Quests.arc', 'data/quests'],
['Resources/XPack3/Quests.arc', 'data/quests'],
['Resources/XPack4/Quests.arc', 'data/quests'],
['Resources/Items.arc', 'data/textures/Items'],
['Resources/XPack/Items.arc', 'data/textures/XPack/Items'],
['Resources/XPack2/Items.arc', 'data/textures/XPack2/Items'],
['Resources/XPack3/Items.arc', 'data/textures/XPack3/Items'],
['Resources/XPack4/Item.arc', 'data/textures/XPack4/Item'],
]
# Required directories for this parser:
DIRECTORIES = [
'data/database',
'data/quests',
'data/resources/cs',
'data/resources/de',
'data/resources/en',
'data/resources/es',
'data/resources/fr',
'data/resources/it',
'data/resources/ja',
'data/resources/ko',
'data/resources/pl',
'data/resources/ru',
'data/resources/uk',
'data/resources/zh',
'data/textures/xpack4/Item',
'data/textures/xpack3/Items',
'data/textures/XPack2/Items',
'data/textures/XPack/Items',
'data/textures/Items',
]
def tqdb_prepare():
# Open the TQAE key and grab the install location:
try:
tqae_key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE, LOOKUP_KEY, 0, winreg.KEY_READ)
except FileNotFoundError:
import platform
bitness = platform.architecture()[0]
if bitness == '32bit':
other_view_flag = winreg.KEY_WOW64_64KEY
elif bitness == '64bit':
other_view_flag = winreg.KEY_WOW64_32KEY
else:
raise RuntimeError("Platform architecture not recognized: " +
bitness)
try:
tqae_key = winreg.OpenKey(
winreg.HKEY_LOCAL_MACHINE, LOOKUP_KEY,
access=winreg.KEY_READ | other_view_flag)
except WindowsError as err:
raise RuntimeError('Could not find installation directory for '
'Titan Quest.') from err
try:
install = winreg.QueryValueEx(tqae_key, 'InstallLocation')[0]
except WindowsError as err:
raise RuntimeError('Could not find installation directory for Titan '
'Quest.') from err
logging.info("Found TQ installation directory: " + install)
# Create the required directories if necessary
for d in DIRECTORIES:
Path(d).mkdir(parents=True, exist_ok=True)
# Run the extraction commands:
tool = Path(install, 'ArchiveTool.exe')
for c in COMMANDS:
input_file = Path(install, c[0])
subprocess.run([
# ArchiveTool.exe in the TQ Install directory
str(tool),
# Resource ARC file in the TQ Install directory
str(input_file),
# Extract flag for the ArchiveTool executable
'-extract',
# Output directory (local data/ dir)
str(Path(c[1]).absolute()),
])
if __name__ == '__main__':
tqdb_prepare()