From 4e8fdc105c59d0989e0b0edae9faadb414c01870 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 2 Aug 2010 03:15:11 +0000 Subject: [PATCH] - attmpt to auto-create the screens folder at startup to avoid crashes when folder is missing and users try to take a screenshot. --- source/glest_game/game/game.cpp | 23 +++++++++++++---------- source/glest_game/game/game_constants.h | 2 ++ source/glest_game/global/config.cpp | 2 ++ source/glest_game/main/main.cpp | 5 +++++ 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 18b10d63..4273cab5 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -937,16 +937,19 @@ void Game::keyDown(char key){ showFullConsole= true; } else if(key == configKeys.getCharKey("Screenshot")) { - for(int i=0; i<100; ++i){ - string path= "screens/screen" + intToStr(i) + ".tga"; - - FILE *f= fopen(path.c_str(), "rb"); - if(f==NULL){ - Renderer::getInstance().saveScreen(path); - break; - } - else{ - fclose(f); + string path = GameConstants::folder_path_screenshots; + if(isdir(path.c_str()) == true) { + for(int i=0; i<100; ++i){ + path = GameConstants::folder_path_screenshots; + path += "screen" + intToStr(i) + ".tga"; + FILE *f= fopen(path.c_str(), "rb"); + if(f==NULL) { + Renderer::getInstance().saveScreen(path); + break; + } + else { + fclose(f); + } } } } diff --git a/source/glest_game/game/game_constants.h b/source/glest_game/game/game_constants.h index 7b58e989..e3de74eb 100644 --- a/source/glest_game/game/game_constants.h +++ b/source/glest_game/game/game_constants.h @@ -64,6 +64,8 @@ public: static const char *folder_path_tutorials; static const char *NETWORK_SLOT_UNCONNECTED_SLOTNAME; + + static const char *folder_path_screenshots; }; enum PathType { diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 1776814c..ef893417 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -38,6 +38,8 @@ const char *GameConstants::folder_path_tutorials = "tutorials"; const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???"; +const char *GameConstants::folder_path_screenshots = "screens/"; + // ===================================================== // class Config // ===================================================== diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 94b65d25..fa241052 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -663,6 +663,11 @@ int glestMain(int argc, char** argv){ gameInitialized = true; + string screenShotsPath = GameConstants::folder_path_screenshots; + if(isdir(screenShotsPath.c_str()) == false) { + createDirectoryPaths(screenShotsPath); + } + if(config.getBool("AllowGameDataSynchCheck","false") == true) { vector techDataPaths = config.getPathListForType(ptTechs); preCacheThread.reset(new FileCRCPreCacheThread());