From: <bur...@us...> - 2010-05-21 09:47:40
|
Revision: 6899 http://freecol.svn.sourceforge.net/freecol/?rev=6899&view=rev Author: burschik Date: 2010-05-21 09:47:33 +0000 (Fri, 21 May 2010) Log Message: ----------- Delete autosave patch by Christian Quast. Modified Paths: -------------- freecol/trunk/data/classic/specification.xml freecol/trunk/data/freecol/specification.xml freecol/trunk/data/testing/specification.xml freecol/trunk/src/net/sf/freecol/FreeCol.java freecol/trunk/src/net/sf/freecol/client/ClientOptions.java freecol/trunk/src/net/sf/freecol/client/control/ConnectController.java freecol/trunk/src/net/sf/freecol/client/control/InGameController.java freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages_de.properties freecol/trunk/src/net/sf/freecol/server/FreeColServer.java Modified: freecol/trunk/data/classic/specification.xml =================================================================== --- freecol/trunk/data/classic/specification.xml 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/data/classic/specification.xml 2010-05-21 09:47:33 UTC (rev 6899) @@ -2013,6 +2013,8 @@ <integerOption id="model.option.autosavePeriod" defaultValue="0" minimumValue="0" maximumValue="100"/> <!-- Option for setting the number of autosaves to keep. If set to 0, all autosaves are kept. --> <integerOption id="model.option.autosaveGenerations" defaultValue="10" minimumValue="0" maximumValue="100"/> + <!-- Option to delete old save games when a new game is started --> + <booleanOption id="model.option.autosaveDelete" defaultValue="false"/> </optionGroup> <optionGroup id="clientOptions.warehouse" > <!-- The Stock the custom house should keep when selling goods. --> Modified: freecol/trunk/data/freecol/specification.xml =================================================================== --- freecol/trunk/data/freecol/specification.xml 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/data/freecol/specification.xml 2010-05-21 09:47:33 UTC (rev 6899) @@ -1847,6 +1847,8 @@ <integerOption id="model.option.autosavePeriod" defaultValue="0" minimumValue="0" maximumValue="100"/> <!-- Option for setting the number of autosaves to keep. If set to 0, all autosaves are kept. --> <integerOption id="model.option.autosaveGenerations" defaultValue="10" minimumValue="0" maximumValue="100"/> + <!-- Option to delete old save games when a new game is started --> + <booleanOption id="model.option.autosaveDelete" defaultValue="false"/> </optionGroup> <optionGroup id="clientOptions.warehouse" > <!-- The Stock the custom house should keep when selling goods. --> Modified: freecol/trunk/data/testing/specification.xml =================================================================== --- freecol/trunk/data/testing/specification.xml 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/data/testing/specification.xml 2010-05-21 09:47:33 UTC (rev 6899) @@ -2159,6 +2159,8 @@ <integerOption id="model.option.autosavePeriod" defaultValue="0" minimumValue="0" maximumValue="100"/> <!-- Option for setting the number of autosaves to keep. If set to 0, all autosaves are kept. --> <integerOption id="model.option.autosaveGenerations" defaultValue="10" minimumValue="0" maximumValue="100"/> + <!-- Option to delete old save games when a new game is started --> + <booleanOption id="model.option.autosaveDelete" defaultValue="false"/> </optionGroup> <optionGroup id="clientOptions.warehouse" > <!-- The Stock the custom house should keep when selling goods. --> Modified: freecol/trunk/src/net/sf/freecol/FreeCol.java =================================================================== --- freecol/trunk/src/net/sf/freecol/FreeCol.java 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/FreeCol.java 2010-05-21 09:47:33 UTC (rev 6899) @@ -137,6 +137,13 @@ private static File mainUserDirectory = null; private static File saveDirectory; + /** Directory containing automatically created save games. + * At program start, the path of this directory is based on the path + * where to store regular save games. If the value of saveGame is + * changed by the user during the game, then the value of + * autoSaveDirectory will not be effected. + */ + private static File autoSaveDirectory; private static File tcUserDirectory; @@ -566,6 +573,19 @@ } else { saveDirectory.mkdir(); } + + autoSaveDirectory = new File(saveDirectory, "autosave"); + if (autoSaveDirectory.exists()) { + if (autoSaveDirectory.isFile()) { + System.out.println("Could not create freecol/save/autosave under " + + System.getProperty("user.home") + " because there " + + "already exists a regular file with the same name."); + return null; + } + } else { + autoSaveDirectory.mkdir(); + } + tcUserDirectory = new File(mainUserDirectory, tc); if (tcUserDirectory.exists()) { if (tcUserDirectory.isFile()) { @@ -646,7 +666,7 @@ * @return The directory. */ public static File getAutosaveDirectory() { - return saveDirectory; + return autoSaveDirectory; } public static InputStream getSpecificationInputStream() throws IOException { Modified: freecol/trunk/src/net/sf/freecol/client/ClientOptions.java =================================================================== --- freecol/trunk/src/net/sf/freecol/client/ClientOptions.java 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/client/ClientOptions.java 2010-05-21 09:47:33 UTC (rev 6899) @@ -256,8 +256,16 @@ * autosaves are kept. */ public static final String AUTOSAVE_GENERATIONS = "model.option.autosaveGenerations"; - + + + /** + * Option for deleting autosaves when a new game is started. If set to + * true, old autosaves will be deleted if a new game is started. + */ + public static final String AUTOSAVE_DELETE = "model.option.autosaveDelete"; + + /** * Option for setting wether or not the fog of war should be displayed. */ public static final String DISPLAY_FOG_OF_WAR = "model.option.displayFogOfWar"; Modified: freecol/trunk/src/net/sf/freecol/client/control/ConnectController.java =================================================================== --- freecol/trunk/src/net/sf/freecol/client/control/ConnectController.java 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/client/control/ConnectController.java 2010-05-21 09:47:33 UTC (rev 6899) @@ -158,6 +158,9 @@ try { FreeColServer freeColServer = new FreeColServer(false, true, port, null, nationOptions, level); + if (freeColClient.getClientOptions().getBoolean(ClientOptions.AUTOSAVE_DELETE)) { + freeColServer.removeAutosaves(Messages.message("clientOptions.savegames.autosave.fileprefix")); + } FreeCol.getSpecification().applyDifficultyLevel(level); freeColClient.setFreeColServer(freeColServer); } catch (NoRouteToServerException e) { Modified: freecol/trunk/src/net/sf/freecol/client/control/InGameController.java =================================================================== --- freecol/trunk/src/net/sf/freecol/client/control/InGameController.java 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/client/control/InGameController.java 2010-05-21 09:47:33 UTC (rev 6899) @@ -354,8 +354,13 @@ int turnNumber = game.getTurn().getNumber(); if (savegamePeriod <= 1 || (savegamePeriod != 0 && turnNumber % savegamePeriod == 0)) { + String playernation= ""; + if (player != null) { + playernation = player.getName() + "_" + + Messages.message(player.getNation().getNameKey()) + "_"; + } String filename = Messages.message("clientOptions.savegames.autosave.fileprefix") - + '-' + getSaveGameString(game.getTurn()) + ".fsg"; + + '-' + playernation + getSaveGameString(game.getTurn()) + ".fsg"; File saveGameFile = new File(FreeCol.getAutosaveDirectory(), filename); saveGame(saveGameFile); Modified: freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties =================================================================== --- freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages.properties 2010-05-21 09:47:33 UTC (rev 6899) @@ -655,6 +655,8 @@ clientOptions.savegames.autosavePeriod.shortDescription=The period for saving the game automatically and using 0 for disabling this feature. clientOptions.savegames.autosaveGenerations.name=Keep x autosave files: clientOptions.savegames.autosaveGenerations.shortDescription=The number of autosave files to keep. Set to 0 in order to keep all autosave files. +clientOptions.savegames.autosaveDelete.name=Delete autosaves files: +clientOptions.savegames.autosaveDelete.shortDescription=Delete old autosave files when a new game is started. clientOptions.warehouse.name=Warehouse Settings clientOptions.warehouse.shortDescription=Change default settings for warehouses and custom houses. clientOptions.warehouse.customStock.name=Default Custom House Stock Modified: freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages_de.properties =================================================================== --- freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages_de.properties 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/client/gui/i18n/FreeColMessages_de.properties 2010-05-21 09:47:33 UTC (rev 6899) @@ -578,6 +578,8 @@ clientOptions.savegames.autosavePeriod.shortDescription=Legt die Anzahl der Runden fest die zwischen dem automatischen Speichern liegt. 0 deaktiviert die Funktion. clientOptions.savegames.autosaveGenerations.name=X automatisch gesicherte Spielstände behalten clientOptions.savegames.autosaveGenerations.shortDescription=Legt die Anzahl der zu behaltenden automatisch gesicherten Spielstände fest. 0 löscht keine Spielstände. +clientOptions.savegames.autosaveDelete.name=Automatisch gesicherte Spielstände löschen +clientOptions.savegames.autosaveDelete.shortDescription=Automatisch gesicherte Spielstände löschen wenn ein neues Spiel gestarted wird. clientOptions.warehouse.name=Lager-/Zollhäuser clientOptions.warehouse.shortDescription=Ändern der Standardeinstellungen für Lager- und Zollhäuser. clientOptions.warehouse.customStock.name=Standard-Zollhausbestand Modified: freecol/trunk/src/net/sf/freecol/server/FreeColServer.java =================================================================== --- freecol/trunk/src/net/sf/freecol/server/FreeColServer.java 2010-05-21 09:46:52 UTC (rev 6898) +++ freecol/trunk/src/net/sf/freecol/server/FreeColServer.java 2010-05-21 09:47:33 UTC (rev 6899) @@ -777,6 +777,19 @@ throw new FreeColException("incompatibleVersions"); } } + + /** + * Removes automatically created save games. + * Call this function to delete the automatically created save games from + * a previous game. + */ + public static void removeAutosaves(final String prefix) { + for (File autosaveFile : FreeCol.getAutosaveDirectory().listFiles()) { + if (autosaveFile.getName().startsWith(prefix)) { + autosaveFile.delete(); + } + } + } /** * Sets the mode of the game: singleplayer/multiplayer. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |