forked from Tignus/AstroSaveConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAstroSaveConverter.py
180 lines (138 loc) · 4.92 KB
/
AstroSaveConverter.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import argparse
import os
import sys
from cogs.AstroLogging import AstroLogging
from cogs.AstroSaveContainer import AstroSaveContainer
"""
D
I
Arguments:
Returns:
Returns
Exception:
None
"""
def check_container_path(path):
"""
Defines the container to use
If the path variable is empty, find every *container* file in the
current directory and make the user chose one
Arguments:
path -- current known path for the container
Returns:
Returns "path" if it was non-empty
Else returns the chosen container
Exception:
Raise FileNotFoundError if no container is found
"""
list_containers = []
if path == '' or path == None:
for file in os.listdir():
if file.rfind("container") != -1:
list_containers.append(file)
if len(list_containers) == 0:
raise FileNotFoundError
AstroLogging.logPrint('\nContainers found:')
for i, container in enumerate(list_containers):
AstroLogging.logPrint(f'\t {str(i+1)}) {container}')
min_container_number = 1
max_container_number = len(list_containers)
path_index = 0
while path_index == 0:
AstroLogging.logPrint(
'\nWhich container would you like to convert ?')
path_index = input()
try:
path_index = int(path_index)
if (path_index < min_container_number or path_index > max_container_number):
raise ValueError
except ValueError:
path_index = 0
AstroLogging.logPrint(
f'Please use only values between {min_container_number} and {max_container_number}')
path = list_containers[path_index-1]
return path
def choose_save_to_export(container):
"""
Let the user choose the save(s) to export from the container
The user can choose one or several saves to export.
Multi-save is supported (separated by commas)
Ex: 1,2,4
Arguments:
container -- Container from which to export the saves
Returns:
Returns the list of the saves number to extract
Exception:
None
"""
save_numbers_list = []
min_save_number = 1
max_save_number = len(container.save_list)
while save_numbers_list == []:
AstroLogging.logPrint(
'\nWhich saves would you like to convert ?')
AstroLogging.logPrint(
'(Multi-convert is supported. Ex: "1,2,4")')
save_numbers = input()
try:
for number in save_numbers.split(','):
number = int(number)
if (number < min_save_number or number > max_save_number):
raise ValueError
save_numbers_list.append(number)
except ValueError:
save_numbers_list = []
AstroLogging.logPrint(
f'Please use only values between {min_save_number} and {max_save_number}')
return save_numbers_list
def manage_rename(container):
"""
Manage wether some saves have to be renamed or not
Arguments:
container -- Container from which to rename the saves
Returns:
Nothing
Exception:
None
"""
is_rename = None
while is_rename != 'y' and is_rename != 'n':
AstroLogging.logPrint('\nWould you like to rename a save ? (y/n)')
is_rename = input().lower()
if is_rename == 'y':
for number in save_numbers_list:
container.save_list[number - 1].rename()
if __name__ == "__main__":
try:
os.system(
"title AstroSaveConverter - Migrate your Astroneer save from Microsoft to Steam")
except:
pass
try:
parser = argparse.ArgumentParser()
parser.add_argument(
"-f", "--fileContainer", help="File container to parse", required=False)
args = parser.parse_args()
path = os.getcwd()
# TODO verifier si le dossier courant est un sous-dossier de %appadata% et warning
# TODO quelquepart: si qqun rentre "connard" dans un prompt, insulter copieusement EmptyProfile
AstroLogging.setup_logging(path)
try:
fileContainer = check_container_path(args.fileContainer)
except FileNotFoundError as e:
AstroLogging.logPrint('\nNo container found, press a key to exit')
input()
sys.exit(-1)
container = AstroSaveContainer(fileContainer)
AstroLogging.logPrint('Container file loaded successfully !\n')
container.print_container()
save_numbers_list = choose_save_to_export(container)
manage_rename(container)
AstroLogging.logPrint(f'\nExtracting saves {str(save_numbers_list)}')
container.xbox_to_steam(save_numbers_list)
AstroLogging.logPrint(f'\nTask completed, press any key to exit')
input()
except Exception as ex:
AstroLogging.logPrint(ex)
AstroLogging.logPrint('', 'exception')
sys.exit()