-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcli_interactive.py
236 lines (187 loc) · 8.73 KB
/
cli_interactive.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
from __future__ import unicode_literals
try:
from typing import List, Optional, Dict, Set, Any, Callable
except:
pass # Just needed for pycharm comments
import os
import sys
# Embedded python doesn't have current directory as path
if os.getcwd() not in sys.path:
print("Startup: Adding {} to path".format(os.getcwd()))
sys.path.append(os.getcwd())
# Python 2/3 input() function fix
try: input = raw_input
except NameError: pass
from installConfiguration import SubModConfig, FullInstallConfiguration
import main as gui_main
import common
import logger
import gameScanner
import uminekoInstaller
import uminekoNScripterInstaller
import higurashiInstaller
from httpGUI import getDownloadPreview
def userAskYesNo(headerText, descriptionText=None):
# type: (str, str) -> bool
while True:
print("\n---- {} ----".format(headerText))
if descriptionText is not None:
print(descriptionText)
response = input("(Please type 'y' or 'n', then hit enter)\n>>")
if len(response) > 0:
if response[0] in 'yY':
return True
elif response[0] in 'nN':
return False
print("Invalid response, please type 'y' or 'n' ")
def userPickFromList(choices, overallDescription, customFormatter=None):
# type: (List[Any], str, Callable[[Any], str]) -> (Any, int)
if customFormatter is None:
customFormatter = lambda x: x
# If only one choice, just return that choice
if len(choices) == 1:
return choices[0], 0
while True:
print("\n---- {} ----".format(overallDescription))
i = 1
for choice in choices:
print("{}) {}".format(i, customFormatter(choice)))
i += 1
# Collect response from the user. If it's invalid, loop again.
try:
choice_index = int(input("(Type the number of your choice, then hit enter)\n>>")) - 1
return choices[choice_index], choice_index
except:
print("Invalid response, please try again.")
continue
# This code is an excerpt from InstallerGUI.try_start_install(...)
def tryGetFullInstallConfig(subMod, installPath):
# type: (SubModConfig, str) -> List[FullInstallConfiguration]
fullInstallConfigs = None
if os.path.isdir(installPath):
fullInstallConfigs, _ = gameScanner.scanForFullInstallConfigs([subMod], possiblePaths=[installPath])
# If normal scan fails, then scan the path using the more in-depth 'scanUserSelectedPath(...)' function
if not fullInstallConfigs:
fullInstallConfigs, errorMessage = gameScanner.scanUserSelectedPath([subMod], installPath)
print(errorMessage)
return fullInstallConfigs
def askUserOptions(subModToInstall):
# type: (SubModConfig) -> None
# Separate the radio and checkbox options
radioOptions = {} # a dict of str -> [ModOption], grouped by mod option type. Order of list should be the same as in the JSON.
checkBoxOptions = [] # a plain list of ModOption objects which are of checkbox type
for option in subModToInstall.modOptions:
if not option.isRadio:
checkBoxOptions.append(option)
else:
if option.group not in radioOptions:
radioOptions[option.group] = []
radioOptions[option.group].append(option)
# Ask the user about each check box option
for option in checkBoxOptions:
option.value = userAskYesNo("Would you like to enable option [{}]?".format(option.name),
"Description: [{}]".format(option.description))
# Ask the user about each group of radio options
def customFormatter(option):
return "[{}]:\n{}\n".format(option.name, option.description)
for (optionGroupName, optionList) in radioOptions.items():
chosenRadioOption, _ = userPickFromList(optionList, "Please choose [{}]".format(optionGroupName),
customFormatter=customFormatter)
chosenRadioOption.value = True
def askUserInstallPathGetFullInstallConfig():
# type: () -> FullInstallConfiguration
manualPathMarker = "Choose Path Manually"
fullInstallConfigs, partiallyUninstalledPaths = gameScanner.scanForFullInstallConfigs([subModToInstall])
if partiallyUninstalledPaths:
print("-----------------------------------------------------------------")
print("WARNING: The following games were uninstalled via Steam, but the mod files still remain on disk:")
for path in partiallyUninstalledPaths:
print(" - {}".format(path))
print("Please manually delete these folders to free disk space and avoid problems with the installer.")
print("-----------------------------------------------------------------")
userAskYesNo("Have you read the above message?")
_, installConfigIndex = userPickFromList([x.installPath for x in fullInstallConfigs] + [manualPathMarker],
"Please choose the game path to install to")
if installConfigIndex < len(fullInstallConfigs):
return fullInstallConfigs[installConfigIndex]
else:
# Ask the user where they want to install the game
while True:
installPath = input(
"\n---- Please copy and paste the game path below ----\nIt should contain one of {}\nDO NOT include the quotation characters [\"] or ['] in your path!\nExample: C:\\Program Files\\Steam\\steamapps\\common\\Umineko (for Umineko Question Arcs)\n>>".format(
subModToInstall.identifiers)
)
print("Validating [{}]".format(installPath))
fullInstallConfigList = tryGetFullInstallConfig(subModToInstall, installPath)
if fullInstallConfigList:
return fullInstallConfigList[0] # type: FullInstallConfiguration
else:
print("---- Invalid game path, please try again ----")
def warnIfSavesIncompatible(fullInstallConfig):
downloadItemsPreview, totalDownloadSize, numUpdatesRequired, fullUpdateRequired, partialReinstallDetected, scriptNeedsUpdate = getDownloadPreview(
fullInstallConfig)
if not scriptNeedsUpdate:
return
print("""---------------------------------------------------
WARNING: Game saves will probably NOT be compatible after this update (global save data should be OK though).
If you try to load old saves with the mod, they may skip you forward or backward in the game!
- If you're in the middle of a chapter, we suggest you finish up the current chapter first.
Then, after installing the mod, use the chapter select menu, and DO NOT load any old saves.
- If you haven't made any saves yet, you can ignore this message.
> Continue install anyway?""")
userAskYesNo("Have you read the above message?")
if __name__ == "__main__":
gui_main.installerCommonStartupTasks()
common.Globals.scanForExecutables()
modList = gui_main.getModList()
subModList = gui_main.getSubModConfigList(modList) #type: List[SubModConfig]
# Get a list of unique game names
uniqueGameNames = []
seenGameNames = set()
for subMod in subModList:
if subMod.modName not in seenGameNames:
seenGameNames.add(subMod.modName)
uniqueGameNames.append(subMod.modName)
# Ask the user which game they want to install
gameName, _ = userPickFromList(uniqueGameNames, "Please choose the mod you want to install")
# Get a list of variants with that name
modVariants = [subMod for subMod in subModList if subMod.modName == gameName] #type: List[SubModConfig]
# Ask the user which submod they want to install
subModToInstall, _ = userPickFromList(modVariants, "Please choose which variant to install") #type: SubModConfig
fullInstallConfig = askUserInstallPathGetFullInstallConfig()
# Warn the user if installation may cause saves to become incompatible
warnIfSavesIncompatible(fullInstallConfig)
# Ask the user what options they want to install
# Note: this function directly modifies the submod's options
askUserOptions(subModToInstall)
# Summarize install choices (print submod and path)
print("\n--------- INSTALL CONFIRMATION ---------")
print("This will PERMANENTLY modify files in the game folder:")
print(fullInstallConfig.installPath)
print("Please take a backup of this folder if you have custom scripts, sprites, voices etc. or wish to revert to unmodded later.")
print("------------------------------------------")
print("You have chosen to install [{}], variant [{}]".format(subModToInstall.modName, subModToInstall.subModName))
print("The mod will install to [{}]".format(fullInstallConfig.installPath))
lastGroup = None
for option in subModToInstall.modOptions:
if option.group != lastGroup:
lastGroup = option.group
print("\n {}:".format(option.group))
print(" {:>24}: {}".format(option.name, option.value))
# Do one final confirmation before starting the install
if not userAskYesNo("Start the install with these settings?"):
input("Install Stopped! Press ENTER to quit")
raise SystemExit(-1)
# Begin the install
installFunction = {
"higurashi": higurashiInstaller.main,
"umineko": uminekoInstaller.mainUmineko,
"umineko_nscripter": uminekoNScripterInstaller.main
}.get(subModToInstall.family, None)
if installFunction:
installFunction(fullInstallConfig)
else:
print(
"Submod family is not recognised, the script may be out of date."
"Please ask us to update it."
)