From 4f1175bfbaf5c52bba4ce372385e98e39cabc3f3 Mon Sep 17 00:00:00 2001 From: drojf Date: Fri, 20 Nov 2020 16:52:36 +1100 Subject: [PATCH] Make ui backup more transactional and raise an error if ui backup fails - Need UI backup so on future installs can determine which modded ui file to use - Make sure when performing backup with forcedExtract option, it backs-up to the forceExtract directory, rather than the game directory - See https://github.com/07th-mod/matsuribayashi/issues/32 --- higurashiInstaller.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/higurashiInstaller.py b/higurashiInstaller.py index 09f9afd6..fddda1aa 100644 --- a/higurashiInstaller.py +++ b/higurashiInstaller.py @@ -108,14 +108,27 @@ def __init__(self, fullInstallConfiguration, extractDirectlyToGameDirectory, mod def backupUI(self): """ Backs up the `sharedassets0.assets` file + Try to do this in a transactional way so you can't get a half-copied .backup file. + This is important since the .backup file is needed to determine which ui file to use on future updates + + The file is not moved directly in case the installer is halted before the new UI file can be placed, resulting + in an install completely missing a sharedassets0.assets UI file. """ try: uiPath = path.join(self.dataDirectory, "sharedassets0.assets") - backupPath = path.join(self.dataDirectory, "sharedassets0.assets.backup") + + # partialManualInstall is not really supported on MacOS, so just assume output folder is HigurashiEpX_Data + if self.forcedExtractDirectory is not None: + backupPath = path.join(self.forcedExtractDirectory, self.info.subModConfig.dataName, "sharedassets0.assets.backup") + else: + backupPath = path.join(self.dataDirectory, "sharedassets0.assets.backup") + if path.exists(uiPath) and not path.exists(backupPath): - shutil.copy(uiPath, backupPath) + shutil.copy(uiPath, backupPath + '.temp') + os.rename(backupPath + '.temp', backupPath) except Exception as e: - print('Warning: Failed to backup sharedassets0.assets file: {}'.format(e)) + print('Error: Failed to backup sharedassets0.assets file: {} (need backup for future installs!)'.format(e)) + raise e def cleanOld(self): """ @@ -313,6 +326,7 @@ def main(fullInstallConfiguration): modOptionParser = installConfiguration.ModOptionParser(fullInstallConfiguration) + # The Partial Manual Install option is mainly for Windows, so please don't assume it works properly on Linux/MacOS if modOptionParser.partialManualInstall: extractDir = fullInstallConfiguration.subModConfig.modName + " " + fullInstallConfiguration.subModConfig.subModName + " Extracted" installer = Installer(fullInstallConfiguration, extractDirectlyToGameDirectory=False, modOptionParser=modOptionParser, forcedExtractDirectory=extractDir)