From 298c1e905c0c3d04acdb1dd0c5e6bedce77dec3c Mon Sep 17 00:00:00 2001 From: j-p-e-g Date: Mon, 14 Sep 2009 23:15:56 +0000 Subject: Fix 2841668: Crawl segfaulting when attempting to use mpr() within the DollEditRegion. Also, if the target file (dolls.txt) within settings/ is writing protected create the file locally instead. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@10678 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/tilereg.cc | 36 ++++++++++++++++++++++++++---------- crawl-ref/source/tilesdl.cc | 4 ++-- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index 3c8136bc11..d73085cd0f 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -44,6 +44,7 @@ REVISION("$Rev$"); #include "tilemcache.h" #include "tiledef-gui.h" +#include #include coord_def Region::NO_CURSOR(-1, -1); @@ -314,11 +315,18 @@ static bool _save_doll_data(int mode, int num, const dolls_data* dolls) { // Save mode, num, and all dolls into dolls.txt. std::string dollsTxtString = datafile_path("dolls.txt", false, true); - const char *dollsTxt = (dollsTxtString.c_str()[0] == 0) ? - "dolls.txt" : dollsTxtString.c_str(); + + struct stat stFileInfo; + stat(dollsTxtString.c_str(), &stFileInfo); + + // Write into the current directory instead if we didn't find the file + // or don't have write permissions. + const char *dollsTxt = (dollsTxtString.c_str()[0] == 0 + || !(stFileInfo.st_mode & S_IWUSR)) ? "dolls.txt" + : dollsTxtString.c_str(); FILE *fp = NULL; - if ( (fp = fopen(dollsTxt, "w+")) != NULL ) + if ((fp = fopen(dollsTxt, "w+")) != NULL) { fprintf(fp, "MODE=%s\n", (mode == TILEP_MODE_EQUIP) ? "EQUIP" : @@ -342,11 +350,8 @@ static bool _save_doll_data(int mode, int num, const dolls_data* dolls) return (true); } - else - { - mprf(MSGCH_ERROR, "Could not write into file '%s'.", dollsTxt); - return (false); - } + + return (false); } // Loads player doll definitions from (by default) dolls.txt. @@ -358,8 +363,16 @@ static bool _load_doll_data(const char *fn, dolls_data *dolls, int max, FILE *fp = NULL; std::string dollsTxtString = datafile_path(fn, false, true); - const char *dollsTxt = (dollsTxtString.c_str()[0] == 0) ? - "dolls.txt" : dollsTxtString.c_str(); + + struct stat stFileInfo; + stat(dollsTxtString.c_str(), &stFileInfo); + + // Try to read from the current directory instead if we didn't find the + // file or don't have reading permissions. + const char *dollsTxt = (dollsTxtString.c_str()[0] == 0 + || !(stFileInfo.st_mode & S_IRUSR)) ? "dolls.txt" + : dollsTxtString.c_str(); + if ( (fp = fopen(dollsTxt, "r")) == NULL ) { @@ -419,11 +432,14 @@ static bool _load_doll_data(const char *fn, dolls_data *dolls, int max, break; } } +#if 0 + // Probably segfaults within the tile edit menu. if (*cur >= count) { mprf(MSGCH_WARN, "Doll %d could not be found in '%s'.", *cur, dollsTxt); } +#endif } else // Load up to max dolls from file. { diff --git a/crawl-ref/source/tilesdl.cc b/crawl-ref/source/tilesdl.cc index 2c9f70df7d..95970da583 100644 --- a/crawl-ref/source/tilesdl.cc +++ b/crawl-ref/source/tilesdl.cc @@ -1332,10 +1332,10 @@ void TilesFramework::update_minimap(int gx, int gy, map_feature f) const int grid = mgrd[gx][gy]; if (mons_friendly_real(&menv[grid])) f = MF_MONS_FRIENDLY; - else if (mons_neutral(&menv[grid])) - f = MF_MONS_NEUTRAL; else if (mons_class_flag(menv[grid].type, M_NO_EXP_GAIN)) f = MF_MONS_NO_EXP; + else if (mons_neutral(&menv[grid])) + f = MF_MONS_NEUTRAL; } else if (f == MF_FLOOR || f == MF_MAP_FLOOR || f == MF_WATER) { -- cgit v1.2.3-54-g00ecf