-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathuminekoInstaller.py
238 lines (195 loc) · 10.1 KB
/
uminekoInstaller.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
237
238
from __future__ import unicode_literals
import commandLineParser
import common
import os, shutil, subprocess, hashlib
import fileVersionManagement
import gameScanner
import installConfiguration
import logger
import steamGridExtractor
try:
from typing import List
except:
pass
def backupOrRemoveFiles(folderToBackup):
"""
Backs up files for both question and answer arcs
If a backup already exists, the file is instead removed
:param folderToBackup: Folder to scan for files. Backups will be placed in the same folder, with extension '.backup'
:return:
"""
pathsToBackup = ['Umineko5to8.exe', 'Umineko5to8', 'Umineko5to8.app',
'Umineko1to4.exe', 'Umineko1to4', 'Umineko1to4.app',
'0.utf', '0.u']
for pathToBackup in pathsToBackup:
fullFilePath = os.path.join(folderToBackup, pathToBackup)
backupPath = fullFilePath + '.backup'
# Backup the file/folders if they exist
if os.path.exists(fullFilePath):
try:
print("backupOrRemoveFiles: Backing up {} to {}".format(fullFilePath, backupPath))
if os.path.isfile(fullFilePath):
shutil.copy(fullFilePath, backupPath)
else:
shutil.copytree(fullFilePath, backupPath)
except Exception as e:
print("backupOrRemoveFiles: Failed to backup {}: {}".format(fullFilePath, e))
def deleteExtractablesFromFolder(folderContainingItems, extractableItemList):
#type: (str, List[common.DownloaderAndExtractor.ExtractableItem]) -> None
for extractableItem in extractableItemList:
extractableItemPath = os.path.join(folderContainingItems, extractableItem.filename)
dateModifiedPath = "{}.dateModified".format(extractableItemPath)
if os.path.exists(extractableItemPath):
print("Removing: [{}]".format(extractableItemPath))
os.remove(extractableItemPath)
if os.path.exists(dateModifiedPath):
print("Removing dateModified file: [{}]".format(dateModifiedPath))
os.remove(dateModifiedPath)
#do install given a installer config object
def mainUmineko(conf):
# type: (installConfiguration.FullInstallConfiguration) -> None
logger.getGlobalLogger().trySetSecondaryLoggingPath(
os.path.join(conf.installPath, common.Globals.LOG_BASENAME)
)
isQuestionArcs = 'question' in conf.subModConfig.modName.lower()
print("CONFIGURATION:")
print("Install path", conf.installPath)
print("Mod Option", conf.subModConfig.modName)
print("Sub Option", conf.subModConfig.subModName)
print("Is Question Arcs", isQuestionArcs)
print("Is Windows", common.Globals.IS_WINDOWS)
print("Is Linux", common.Globals.IS_LINUX)
print("Is Mac", common.Globals.IS_MAC)
####################################### VALIDATE AND PREPARE FOLDERS ###############################################
# do a quick verification that the directory is correct before starting installer
if not os.path.isfile(os.path.join(conf.installPath, "arc.nsa")):
raise Exception("ERROR - wrong game path. Installation Stopped.\n"
"There is no 'arc.nsa' in the game folder. Are you sure the correct game folder was selected?")
for filename in os.listdir(conf.installPath):
# Stop the user installing the mod on pirated versions of the game.
# Use SHA256 hash of the lowercase filename to avoid listing the website names in our source code.
if hashlib.sha256(filename.lower().encode('utf-8')).hexdigest() in [
'2c02ec6f6de9281a68975257a477e8f994affe4eeaaf18b0b56b4047885461e0',
'4fae41c555fe50034065e59ce33a643c1d93ee846221ecc5756f00e039035076',
]:
raise Exception("\nInstall Failed - The {} mod is not compatible with the pirated version of the game\n"
"(Detected file [{}]) Please install the latest Steam or Mangagamer release."
.format(conf.subModConfig.modName, filename))
# Stop the user installing the mod on the old/original Japanese game.
# This probably means the user placed a fake identifier (eg the game exe) in the old game's folder.
if filename == 'snow.dll':
raise Exception("\nInstall Failed - The {} mod is not compatible with the old/original Japanese game.\n"
"(Detected [{}]) Please install the latest Steam or Mangagamer release."
.format(conf.subModConfig.modName, filename))
if common.Globals.IS_LINUX:
gameIsLinuxIdentifierPath = os.path.join(conf.installPath, "lib64/libfreetype.so.6")
print("Checking for Proton install by checking if identifier {} is missing".format(gameIsLinuxIdentifierPath))
if not os.path.exists(gameIsLinuxIdentifierPath):
if common.Globals.FORCE_ASSET_OS_STRING is None:
raise Exception(common.Globals.PROTON_ERROR_MESSAGE +
"\nIf you are absolutely sure you're not using Proton, create a dummy file at [{}] to bypass this error.".format(gameIsLinuxIdentifierPath))
else:
print(common.Globals.PROTON_WITH_ASSETS_OVERRIDE_MESSAGE)
# Create aliases for the temp directories, and ensure they exist beforehand
downloadTempDir = conf.subModConfig.modName + " Downloads"
if os.path.isdir(downloadTempDir):
print("Information: Temp directories already exist - continued or overwritten install")
common.makeDirsExistOK(downloadTempDir)
######################################## Query and Download Files ##################################################
fileVersionManager = fileVersionManagement.VersionManager(
fullInstallConfiguration=conf,
modFileList=conf.buildFileListSorted(),
localVersionFolder=conf.installPath)
optionParser = installConfiguration.ModOptionParser(conf)
skipDownload = optionParser.downloadManually
filesRequiringUpdate = fileVersionManager.getFilesRequiringUpdate()
print("Perform Full Install: {}".format(fileVersionManager.fullUpdateRequired()))
conf.subModConfig.printEnabledOptions()
downloaderAndExtractor = common.DownloaderAndExtractor(filesRequiringUpdate, downloadTempDir, conf.installPath, downloadProgressAmount=45, extractionProgressAmount=45, skipDownload=skipDownload)
downloaderAndExtractor.buildDownloadAndExtractionList()
for opt in optionParser.downloadAndExtractOptionsByPriority:
downloaderAndExtractor.addItemManually(
url=opt.url,
extractionDir=os.path.join(conf.installPath, opt.relativeExtractionPath),
)
downloaderAndExtractor.printPreview()
downloaderAndExtractor.download()
# Treat the install as "started" once the "download" stage is complete
fileVersionManager.saveVersionInstallStarted()
###################### Backup/clear the .exe and script files, and old graphics ####################################
backupOrRemoveFiles(conf.installPath)
if fileVersionManager.fullUpdateRequired():
# Remove old graphics from a previous installation, as they can conflict with the voice-only patch
graphicsPathsToDelete = [os.path.join(conf.installPath, x) for x in ['big', 'bmp', 'en']]
for folderPath in graphicsPathsToDelete:
if os.path.exists(folderPath):
print("Deleting {}".format(folderPath))
try:
shutil.rmtree(folderPath)
except:
print("WARNING: failed to remove folder {}".format(folderPath))
######################################## Extract Archives ##########################################################
def remapPaths(originalFolder, originalFilename):
fileNameNoExt, extension = os.path.splitext(originalFilename)
if '.utf' in extension:
return originalFolder, (fileNameNoExt + '.u')
else:
return originalFolder, originalFilename
# If any mod options request deletion of a folder, do it before the extraction
common.applyDeletions(conf.installPath, optionParser)
downloaderAndExtractor.extract(remapPaths)
############################################# FIX .ARC FILE NAMING #################################################
# Steam release has arc files labeled arc.nsa, arc1.nsa, arc2.nsa, arc3.nsa.
# Mangagamer release has only one arc file labeled arc.nsa
# Generate dummy arc1-arc3 nsa files if they don't already exist, so the game can find the arc4.nsa that we provide
for i in range(1,4):
nsaPath = os.path.join(conf.installPath, 'arc{}.nsa'.format(i))
if not os.path.exists(nsaPath):
print(".nsa archive check: Generating dummy [{}] as it does not already exist (Mangagamer)".format(nsaPath))
with open(nsaPath, 'wb') as dummyNSAFile:
dummyNSAFile.write(bytes([0, 0, 0, 0, 0, 6]))
else:
print(".nsa archive check: [{}] already exists (Steam)".format(nsaPath))
#################################### MAKE EXECUTABLE, WRITE HELPER SCRIPTS #########################################
gameBaseName = "Umineko5to8"
if isQuestionArcs:
gameBaseName = "Umineko1to4"
if common.Globals.IS_MAC:
print("Un-quarantining game executable")
subprocess.call(["xattr", "-d", "com.apple.quarantine", os.path.join(conf.installPath, gameBaseName + ".app")])
print("Creating debug mode batch files")
# write batch file to let users launch game in debug mode
with open(os.path.join(conf.installPath, gameBaseName + "_DebugMode.bat"), 'w') as f:
f.writelines([gameBaseName + ".exe --debug\n", "pause"])
#make the following files executable, if they exist
makeExecutableList = [
os.path.join(conf.installPath, "Umineko1to4"),
os.path.join(conf.installPath, "Umineko1to4.app/Contents/MacOS/umineko4"),
os.path.join(conf.installPath, "Umineko5to8"),
os.path.join(conf.installPath, "Umineko5to8.app/Contents/MacOS/umineko8")
]
print("Making executables ... executable")
for exePath in makeExecutableList:
if os.path.exists(exePath):
common.makeExecutable(exePath)
# Patched game uses mysav folder, which Steam can't see so can't get incompatible saves by accident.
# Add batch file which reverses this behaviour by making a linked folder from (saves->mysav)
print("Creating EnableSteamSync.bat")
with open(os.path.join(conf.installPath, "EnableSteamSync.bat"), 'w') as f:
f.write("""
if exist saves (
ren saves backup-saves
mklink /J saves mysav
) else (
mklink /J saves mysav
)
pause
""")
# For now, don't copy save data
if optionParser.installSteamGrid:
steamGridExtractor.extractSteamGrid(downloadTempDir)
fileVersionManager.saveVersionInstallFinished()
if not optionParser.keepDownloads and not skipDownload:
print("Removing temporary downloads:")
deleteExtractablesFromFolder(downloadTempDir, downloaderAndExtractor.extractList)
commandLineParser.printSeventhModStatusUpdate(100, "Umineko install script completed!")