From fd55bc22733510b7e608bd2bd5854efb366f4e97 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Fri, 10 Dec 2010 00:04:08 +0000 Subject: [PATCH] Avoid crash if history.dat file can not be written; also added 2nd location to test for (where the config.xml etc files are stored) to test, which makes history usable in standard windows installation (where . is not writable). Fixes bug 3128511. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6938 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/race/history.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/race/history.cpp b/src/race/history.cpp index 7a238e6fe..f246cdb23 100644 --- a/src/race/history.cpp +++ b/src/race/history.cpp @@ -21,6 +21,7 @@ #include +#include "io/file_manager.hpp" #include "modes/world.hpp" #include "karts/kart.hpp" #include "race/race_manager.hpp" @@ -150,6 +151,24 @@ void History::updateReplay(float dt) void History::Save() { FILE *fd = fopen("history.dat","w"); + if(fd) + printf("History saved in ./history.dat.\n"); + else + { + std::string fn = file_manager->getConfigDir()+"/history.dat"; + fd = fopen(fn.c_str(), "w"); + if(fd) + printf("History saved in '%s'.\n",fn.c_str()); + + } + if(!fd) + { + printf("Can't open history.dat file for writing - can't save history.\n"); + printf("Make sure history.dat in the current directory or the config\n"); + printf("directory is writable.\n"); + return; + } + World *world = World::getWorld(); int num_karts = world->getNumKarts(); #ifdef VERSION @@ -207,8 +226,18 @@ void History::Load() { char s[1024], s1[1024]; int n; + FILE *fd = fopen("history.dat","r"); - if (fd == NULL) + if(fd) + printf("Reading ./history.dat\n"); + else + { + std::string fn = file_manager->getConfigDir()+"/history.dat"; + fd = fopen(fn.c_str(), "r"); + if(fd) + printf("Reading '%s'.\n", fn.c_str()); + } + if(!fd) { fprintf(stderr, "ERROR: could not open history.dat\n"); exit(-2);