Skip to content

Commit

Permalink
Make ui backup more transactional and raise an error if ui backup fails
Browse files Browse the repository at this point in the history
- 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 07th-mod/matsuribayashi#32
  • Loading branch information
drojf committed Nov 20, 2020
1 parent 8c4e6d4 commit 4f1175b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions higurashiInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4f1175b

Please sign in to comment.