-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_local_upk_files.py
133 lines (112 loc) · 5.9 KB
/
prepare_local_upk_files.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
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# Copyright © 2016 ButenkoMS. All rights reserved. Contacts: <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from upk_helping_tools.upk_utils_api import *
from help_tools import IsOK_ContextHolder, is_ok, is_ok_reader, ResultType, CriteriaType
import shutil
"""
Module Docstring
Docstrings: http://www.python.org/dev/peps/pep-0257/
"""
__author__ = "ButenkoMS <[email protected]>"
__copyright__ = "Copyright © 2016 ButenkoMS. All rights reserved. Contacts: <[email protected]>"
__credits__ = ["ButenkoMS <[email protected]>", ]
__license__ = "Apache License, Version 2.0"
__version__ = "0.0.1"
__maintainer__ = "ButenkoMS <[email protected]>"
__email__ = "[email protected]"
__status__ = "Prototype"
# __status__ = "Development"
# __status__ = "Production"
def main():
dir_table = {
'upk utils dir': r'C:\Tools\UPKUtils',
'xcom original upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole',
# 'xcom original upk dir': r'C:\Games\Steam\steamapps\common\XCom-Enemy-Unknown\XEW\Long War Files',
'xcom unpacked upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole_Unpacked',
# 'xcom unpacked upk dir': r'C:\Development\XCOM Modding\Work\OriginalCookedPCConsole_Unpacked',
'xcom deserialized upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole_Deserialized',
'xcom XEW dir': r'C:\Games\Steam\steamapps\common\XCom-Enemy-Unknown\XEW\XComGame\CookedPCConsole'
}
dir_table = {
'upk utils dir': r'C:\Tools\UPKUtils',
'xcom original upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole',
'xcom unpacked upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole_Unpacked',
'xcom deserialized upk dir': r'C:\Development\XCOM Modding\Work\CookedPCConsole_Deserialized',
'xcom XEW dir': r'C:\Games\Steam\steamapps\common\XCom-Enemy-Unknown\XEW\XComGame\CookedPCConsole'
}
files_table = {
'deserialize this file': r"C:\Development\XCOM Modding\Work\CookedPCConsole\XComGame.upk"
}
options_table = {
'u': 0,
'ud': 1,
'ds': 2,
'c': 3,
}
context = IsOK_ContextHolder(global_block_results_criteria=ResultType(CriteriaType.optional, set()))
with is_ok(context, 'ask user'):
if context:
context.push_result(True, int(options_table[input('Enter option (\'c\' = "copy files from XEW folder"; '
'\'u\' = "unpack"; '
'\'ud\' = "unpack + deserialize"; '
'\'ds\' = "deserialize single file"): ')]))
with is_ok(context, 'unpack'):
if context:
if context.read_block_result_link('ask user').result in {0, 1}:
unpack_upk_files(dir_table['upk utils dir'],
dir_table['xcom original upk dir'],
dir_table['xcom unpacked upk dir'],
True,
True)
context.push_result(True)
with is_ok(context, 'deserialize'):
if context:
if context.read_block_result_link('ask user').result in {1}:
deserialize_upk_files(dir_table['upk utils dir'],
dir_table['xcom unpacked upk dir'],
dir_table['xcom deserialized upk dir'])
context.push_result(True)
with is_ok(context, 'deserialize single file'):
if context:
if context.read_block_result_link('ask user').result in {2}:
deserialize_this_file = input('Enter upk file name or leave blank for default: ')
if deserialize_this_file == '':
deserialize_this_file = files_table['deserialize this file']
deserialize_result = deserialize_single_upk_file(dir_table['upk utils dir'],
deserialize_this_file,
dir_table['xcom deserialized upk dir'])
print('DESERIALIZE RESULT: {}'.format(deserialize_result))
context.push_result(True, deserialize_result)
context.push_result(True)
with is_ok(context, 'copy files from XEW'):
if context:
if context.read_block_result_link('ask user').result in {3}:
set_of_ext = {'.upk', '.u'}
file_list_result = filtered_file_list(dir_table['xcom XEW dir'], FilteringType.including, set_of_ext)
for file_name in file_list_result[2]:
if 'voice' not in file_name.lower():
source_full_file_name = os.path.join(file_list_result[0], file_name)
destination_full_file_name = os.path.join(dir_table['xcom original upk dir'], file_name)
shutil.copyfile(source_full_file_name, destination_full_file_name)
print('COPIED "{}" TO "{}"'.format(source_full_file_name, destination_full_file_name))
context.push_result(True)
with is_ok_reader(context):
print()
if context:
print('DONE. SUCCESSFUL.')
else:
print('DONE. ERRORS LOG: \n{}'.format(context.get_bad_blocks_str()))
if __name__ == "__main__":
main()