Skip to content

Commit

Permalink
Fix #2086. This changes the current behaviour.
Browse files Browse the repository at this point in the history
Only games are loaded which have an higher revision
than the related value stored in the constants. Old behaviour
was to load everything and hope it works.
  • Loading branch information
Kilian Köppchen committed Feb 10, 2015
1 parent 8c483bf commit a4f8d48
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
14 changes: 14 additions & 0 deletions doc/CHANGELOG.md
@@ -1,6 +1,20 @@
CHANGELOG Unknown Horizons
==========================

| Release | Current savegame revision |
|---|---|
| 2014.1 | 74 |
| 2013.3 | 73 |
| 2013.2 | 71 |
| 2013.1 | 70 |
| 2012.1a | 56 |
| 2012.1 | 56 |
| 2011.3 | 43 |
| 2011.2 | 15 |
| 2011.1a | 12 |
| 2011.1 | 12 |
| 2010.1 | 8 |

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2014-12-31: Milestone 2014.1
Expand Down
1 change: 1 addition & 0 deletions horizons/constants.py
Expand Up @@ -73,6 +73,7 @@ def _get_git_version():

## +=1 this if you changed the savegame "api"
SAVEGAMEREVISION = 74
SAVEGAME_LEAST_UPGRADABLE_REVISION = 48

@staticmethod
def string():
Expand Down
3 changes: 2 additions & 1 deletion horizons/main.py
Expand Up @@ -373,12 +373,13 @@ def start_singleplayer(options):

from horizons.scenario import InvalidScenarioFileFormat # would create import loop at top
from horizons.util.savegameaccessor import MapFileNotFound
from horizons.util.savegameupgrader import SavegameTooOld
try:
_modules.session.load(options)
_modules.gui.close_all()
except InvalidScenarioFileFormat:
raise
except MapFileNotFound, Exception:
except (MapFileNotFound, SavegameTooOld, Exception):
_modules.gui.close_all()
# don't catch errors when we should fail fast (used by tests)
if os.environ.get('FAIL_FAST', False):
Expand Down
25 changes: 15 additions & 10 deletions horizons/util/savegameupgrader.py
Expand Up @@ -37,6 +37,13 @@
from horizons.util.shapes import Rect
from horizons.util.yamlcache import YamlCache

class SavegameTooOld(Exception):
def __init__(self, msg=None, revision=None):
if msg is None:
msg = "The savegame is too old!"
if revision is not None:
msg += " Revision: " + str(revision)
super(SavegameTooOld, self).__init__(msg)

class SavegameUpgrader(object):
"""The class that prepares saved games to be loaded by the current version."""
Expand Down Expand Up @@ -395,10 +402,9 @@ def _upgrade(self):
from horizons.savegamemanager import SavegameManager
metadata = SavegameManager.get_metadata(self.original_path)
rev = metadata['savegamerev']
if rev == 0: # not a regular savegame, usually a map
self.final_path = self.original_path
elif rev == VERSION.SAVEGAMEREVISION: # the current version
self.final_path = self.original_path

if not SavegameUpgrader.can_upgrade(rev):
raise SavegameTooOld(revision=rev)
else: # upgrade
self.log.warning('Discovered old savegame file, auto-upgrading: %s -> %s' % \
(rev, VERSION.SAVEGAMEREVISION))
Expand Down Expand Up @@ -467,12 +473,11 @@ def _upgrade(self):

@classmethod
def can_upgrade(cls, from_savegame_version):
"""Calculates whether a savegame can be upgraded from the current version"""
for i in xrange(from_savegame_version+1, VERSION.SAVEGAMEREVISION+1, 1):
if not hasattr(cls, "_upgrade_to_rev" + str(i)):
return False
return True

"""Checks whether a savegame can be upgraded from the current version"""
if from_savegame_version >= VERSION.SAVEGAME_LEAST_UPGRADABLE_REVISION:
return True
else:
return False

def get_path(self):
"""Return the path to the up-to-date version of the saved game."""
Expand Down

0 comments on commit a4f8d48

Please sign in to comment.