Skip to content

Commit

Permalink
Only run Savegame upgrade when its necessary #2086
Browse files Browse the repository at this point in the history
  • Loading branch information
Kilian Köppchen committed Feb 15, 2015
1 parent a09750f commit fd972a7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions horizons/util/savegameupgrader.py
Expand Up @@ -403,15 +403,12 @@ def _upgrade(self):
metadata = SavegameManager.get_metadata(self.original_path)
rev = metadata['savegamerev']

if not SavegameUpgrader.can_upgrade(rev):
raise SavegameTooOld(revision=rev)
else: # upgrade
if rev < VERSION.SAVEGAMEREVISION :
if not SavegameUpgrader.can_upgrade(rev):
raise SavegameTooOld(revision=rev)

self.log.warning('Discovered old savegame file, auto-upgrading: %s -> %s' % \
(rev, VERSION.SAVEGAMEREVISION))
self.using_temp = True
handle, self.final_path = tempfile.mkstemp(prefix='uh-savegame.' + os.path.basename(os.path.splitext(self.original_path)[0]) + '.', suffix='.sqlite')
os.close(handle)
shutil.copyfile(self.original_path, self.final_path)
db = DbReader(self.final_path)
db('BEGIN TRANSACTION')

Expand Down Expand Up @@ -482,6 +479,10 @@ def can_upgrade(cls, from_savegame_version):
def get_path(self):
"""Return the path to the up-to-date version of the saved game."""
if self.final_path is None:
self.using_temp = True
handle, self.final_path = tempfile.mkstemp(prefix='uh-savegame.' + os.path.basename(os.path.splitext(self.original_path)[0]) + '.', suffix='.sqlite')
os.close(handle)
shutil.copyfile(self.original_path, self.final_path)
self._upgrade()
return self.final_path

Expand Down

0 comments on commit fd972a7

Please sign in to comment.