Skip to content

Commit 6cb910a

Browse files
committed
Fix language patch - always install base scripts before language patch installed
- See #233
1 parent ab25b97 commit 6cb910a

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

fileVersionManagement.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def userDidPartialReinstall(self, gameInstallTimeProbePath):
8989
return os.path.getctime(gameInstallTimeProbePath) > os.path.getmtime(self.localVersionFilePath)
9090

9191
def __init__(self, fullInstallConfiguration, modFileList, localVersionFolder, datadir=None, _testRemoteSubModVersion=None, verbosePrinting=True):
92-
#type: (installConfiguration.FullInstallConfiguration, List[installConfiguration.ModFile], str, str, Optional[SubModVersionInfo], bool) -> None
93-
subMod = fullInstallConfiguration.subModConfig
92+
#type: (installConfiguration.FullInstallConfiguration, List[installConfiguration.ModFile], str, str, Optional[SubModVersionInfo], bool, Optional[list[str]]) -> None
93+
subMod = fullInstallConfiguration.subModConfig # type: installConfiguration.SubModConfig
9494
self.verbosePrinting = verbosePrinting
9595
self.targetID = subMod.modName + '/' + subMod.subModName
9696
self.unfilteredModFileList = modFileList
@@ -132,8 +132,14 @@ def __init__(self, fullInstallConfiguration, modFileList, localVersionFolder, da
132132
for file in self.unfilteredModFileList:
133133
self.updatesRequiredDict[file.id] = (True, "Failed to retrieve remote version information")
134134
else:
135+
forceUpdateList = []
136+
137+
# Always install script when language patch is enabled
138+
if subMod.family == "higurashi" and modOptionParser.languagePatchIsEnabled:
139+
forceUpdateList.append(ForceUpdate('script', 'Language patch option forces script re-install'))
140+
135141
# Mark files which need update
136-
self.updatesRequiredDict = getFilesNeedingUpdate(self.unfilteredModFileList, self.localVersionInfo, self.remoteVersionInfo, repairMode=modOptionParser.repairMode)
142+
self.updatesRequiredDict = getFilesNeedingUpdate(self.unfilteredModFileList, self.localVersionInfo, self.remoteVersionInfo, repairMode=modOptionParser.repairMode, forceUpdateList=forceUpdateList)
137143

138144
if verbosePrinting:
139145
print("\nInstaller Update Information:")
@@ -266,10 +272,15 @@ def getRemoteVersion(remoteTargetID):
266272

267273
return SubModVersionInfo(remoteVersionObject)
268274

275+
class ForceUpdate:
276+
def __init__(self, name, reason):
277+
#type: (str, str) -> None
278+
self.name = name
279+
self.reason = reason
269280

270281
# given a mod
271-
def getFilesNeedingUpdate(modFileList, localVersionInfo, remoteVersionInfo, repairMode):
272-
#type: (List[installConfiguration.ModFile], SubModVersionInfo, SubModVersionInfo, bool) -> Dict[str, Tuple[bool, str]]
282+
def getFilesNeedingUpdate(modFileList, localVersionInfo, remoteVersionInfo, repairMode, forceUpdateList=None):
283+
#type: (List[installConfiguration.ModFile], SubModVersionInfo, SubModVersionInfo, bool, Optional[list[ForceUpdate]]) -> Dict[str, Tuple[bool, str]]
273284
"""
274285
275286
:param modFileList:
@@ -301,6 +312,13 @@ def getFilesNeedingUpdate(modFileList, localVersionInfo, remoteVersionInfo, repa
301312
result = updatesRequiredDict.get(file.id)
302313
needUpdate, updateReason = (True, "Missing version info") if result is None else result
303314

315+
# Check for files forced to update via forceUpdateList parameter
316+
if not needUpdate and forceUpdateList is not None:
317+
for forceUpdate in forceUpdateList:
318+
if file.name == forceUpdate.name:
319+
needUpdate = True
320+
updateReason = forceUpdate.reason
321+
304322
if not needUpdate and repairMode and file.installOnRepair:
305323
needUpdate = True
306324
updateReason = "Re-installing as Repair Mode Enabled"

higurashiInstaller.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ def __init__(self, fullInstallConfiguration, extractDirectlyToGameDirectory, mod
124124
:param str directory: The directory of the game
125125
:param dict info: The info dictionary from server JSON file for the requested target
126126
"""
127+
self.optionParser = modOptionParser
127128
self.forcedExtractDirectory = forcedExtractDirectory
128129
self.info = fullInstallConfiguration
129130
self.directory = fullInstallConfiguration.installPath
130131
self.dataDirectory = self.getDataDirectory(self.directory)
131132
self.clearScripts = False # If true, will clear CompiledUpdateScripts before extraction stage
132-
self.languagePatchIsEnabled = False # True if at least one language patch will be installed
133133
self.skipDownload = skipDownload
134134
self.isWine = fullInstallConfiguration.isWine
135135

@@ -175,16 +175,11 @@ def __init__(self, fullInstallConfiguration, extractDirectlyToGameDirectory, mod
175175

176176
self.downloaderAndExtractor.buildDownloadAndExtractionList()
177177

178-
self.optionParser = modOptionParser
179-
180178
for opt in self.optionParser.downloadAndExtractOptionsByPriority:
181179
self.downloaderAndExtractor.addItemManually(
182180
url=opt.url,
183181
extractionDir=os.path.join(self.extractDir, opt.relativeExtractionPath),
184182
)
185-
if opt.group == 'Alternate Languages':
186-
self.clearScripts = True
187-
self.languagePatchIsEnabled = True
188183

189184
self.downloaderAndExtractor.printPreview()
190185

@@ -227,7 +222,7 @@ def clearScriptsAndCompiledScripts(self):
227222
for globPattern in ["CompiledUpdateScripts/*.mg", "Update/*.txt"]:
228223
compiledScriptsPattern = path.join(self.assetsDir, globPattern)
229224

230-
print("Attempting to clear compiled scripts")
225+
print("Attempting to clear compiled scripts in [{}]".format(compiledScriptsPattern))
231226
try:
232227
for mg in glob.glob(compiledScriptsPattern):
233228
forceRemove(mg)
@@ -376,12 +371,23 @@ def applyLanguagePatchFixesIfNecessary(self):
376371
folderToApply = self.getDataDirectory(self.forcedExtractDirectory)
377372

378373
# Don't need to apply any special UI if no language patch
379-
if not self.languagePatchIsEnabled:
374+
if not self.optionParser.languagePatchIsEnabled:
380375
return
381376

377+
print("applyLanguagePatchFixesIfNecessary(): Language Patch Enabled - Executing Extra Language Patch Fixes...")
378+
382379
# For now, assume language patches don't provide CompiledUpdateScripts folder, so clear any existing compiled
383380
# scripts which may come with the main patch
384-
self.clearScriptsAndCompiledScripts()
381+
# NOTE: previously, scripts were cleared here via self.clearScriptsAndCompiledScripts(), but this caused issues.
382+
# It is now changed to:
383+
#
384+
# 1. Before this function is called, scripts are cleared (as part of normal mod script installation)
385+
# 2. Then, base scripts are then installed (will always happen even if already on latest script ver.)
386+
# 3. Then the language patch scripts are installed
387+
#
388+
# This is done because as all language patches omit some files (at least init.txt, but often other scripts),
389+
# so language patches must be installed "ontop" of existing scripts. Clearing scripts at any other time will result
390+
# in missing scripts.
385391

386392
invalidUIFileList = listInvalidUIFiles(folderToApply)
387393

installConfiguration.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def __init__(self, fullInstallConfiguration):
275275
self.repairMode = False
276276
self.downloadManually = False
277277
self.forceInstallFromScratch = False
278+
self.languagePatchIsEnabled = False
278279

279280
# Sort according to priority - higher priority items will be extracted later, overwriting lower priority items.
280281
for modOption in self.config.subModConfig.modOptions:
@@ -307,6 +308,10 @@ def __init__(self, fullInstallConfiguration):
307308
# Make sure download and extraction options are sorted
308309
self.downloadAndExtractOptionsByPriority.sort(key=lambda opt: opt.priority)
309310

311+
# Check if any language patch options are enabled
312+
for opt in self.downloadAndExtractOptionsByPriority:
313+
if opt.group == 'Alternate Languages':
314+
self.languagePatchIsEnabled = True
310315

311316
class SubModConfig:
312317
# directly represents a single submod from the json file

0 commit comments

Comments
 (0)