diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 7206262..b0bfdfe 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp @@ -4,10 +4,10 @@ * and open the template in the editor. */ -/* +/* * File: ScoresDisplay.cpp * Author: poul - * + * * Created on 7. februar 2016, 17:34 */ @@ -151,7 +151,7 @@ void ScoresDisplay::Draw(SDL_Renderer* target) { NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2,ysize-60,pageXofY.c_str()); } -void ScoresDisplay::ProcessInput(const SDL_Event& event, bool &processed) { +void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) { if ( event.type == SDL_KEYDOWN ) { if ( (event.key.keysym.sym == SDLK_RIGHT)) { page++; @@ -178,7 +178,7 @@ void ScoresDisplay::ProcessInput(const SDL_Event& event, bool &processed) { void ScoresDisplay::Update() { int mousex, mousey; SDL_GetMouseState(&mousex,&mousey); - + // If the mouse button is released, make bMouseUp equal true if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { bMouseUp=true; diff --git a/source/code/main.cpp b/source/code/main.cpp index 2331c51..4765c06 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -994,35 +994,35 @@ bool OpenDialogbox(int x, int y, std::string& name) { } -void RunGameState(sago::GameStateInterface &state ) { +void RunGameState(sago::GameStateInterface& state ) { int mousex,mousey; bool done = false; //We are done! while (!done && !Config::getInstance()->isShuttingDown()) { state.Draw(screen); - + SDL_Delay(1); SDL_Event event; SDL_GetMouseState(&mousex,&mousey); bool mustWriteScreenshot = false; - + while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) { Config::getInstance()->setShuttingDown(5); done = true; } - + if ( event.key.keysym.sym == SDLK_F9 ) { mustWriteScreenshot = true; } - + bool processed = false; state.ProcessInput(event, processed); - + } - + state.Update(); - + mouse.Draw(screen, SDL_GetTicks(), mousex, mousey); SDL_RenderPresent(screen); if (mustWriteScreenshot) { @@ -1503,7 +1503,7 @@ int PuzzleLevelSelect(int Type) { if (Type == 1) { string scoreString = SPrintStringF(_("Best score: %i"), GetStageScores(selected)) ; string timeString = SPrintStringF(_("Time used: %s"),"-- : --"); - + if (GetStageTime(selected)>0) { timeString = SPrintStringF(_("Time used: %s"), string(itoa(GetStageTime(selected)/1000/60)+" : "+itoa2((GetStageTime(selected)/1000)%60)).c_str() ); } @@ -1636,7 +1636,6 @@ static void StartTwoPlayerVs() { //Warning: the arguments to main must be "int argc, char* argv[]" NO CONST! or SDL_main will fail to find it int main(int argc, char* argv[]) { try { - OsCreateFolders(); //Init the file system abstraction layer PHYSFS_init(argv[0]); vector search_paths; @@ -1657,10 +1656,10 @@ int main(int argc, char* argv[]) { ("verbose-basic", "Enables basic verbose messages") ("print-search-path", "Prints the search path and quits") ("bind-text-domain", boost::program_options::value(), SPrintStringF("Overwrites the bind text domain used for finding translations. " - "Default: \"%s\"", LOCALEDIR).c_str()) + "Default: \"%s\"", LOCALEDIR).c_str()) ("homepath", boost::program_options::value(), SPrintStringF("Set the home folder where settings are saved. The directory must exsist." - " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str()) - + " Default: \"%s\"", getPathToSaveFiles().c_str()).c_str()) + ; boost::program_options::variables_map vm; try { @@ -1683,7 +1682,7 @@ int main(int argc, char* argv[]) { } if (vm.count("help")) { cout << SPrintStringF("Block Attack - Rise of the blocks %s\n" - "%s\n", VERSION_NUMBER, "www.blockattack.net"); + "%s\n", VERSION_NUMBER, "www.blockattack.net"); cout << desc << endl; return 1; } @@ -1703,6 +1702,8 @@ int main(int argc, char* argv[]) { cout << savepath << endl; return 0; } + //Os create folders must be after the paramters because they can change the home folder + OsCreateFolders(); SoundEnabled = true; MusicEnabled = true; diff --git a/source/code/os.cpp b/source/code/os.cpp index 2bcc0dc..adbcf63 100644 --- a/source/code/os.cpp +++ b/source/code/os.cpp @@ -90,7 +90,7 @@ string getMyDocumentsPath() { #endif -static std::string overrideSavePath = ""; +static std::string overrideSavePath = ""; /** * Returns the path to where all settings must be saved. @@ -147,30 +147,26 @@ std::string getPuzzleSetSavePath() { return ret; } -void OsCreateFolders() { - //We first create the folder there we will save (only on UNIX systems) - //we call the external command "mkdir"... the user might have renamed this, but we hope he hasn't - +static void OsCreateFolderInSaveGames(const string& path) { + string cmd = "mkdir -p "+getPathToSaveFiles()+"/"+path; #if defined(__unix__) - //Compiler warns about unused result. The users envisonment should normally give the user all the information he needs - if (system("mkdir -p ~/.gamesaves/blockattack/screenshots")) { - cerr << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl; - } - if (system("mkdir -p ~/.gamesaves/blockattack/replays")) { - cerr << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl; - } - if (system("mkdir -p ~/.gamesaves/blockattack/puzzles")) { - cerr << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl; + int retcode = system(cmd.c_str()); + if (retcode != 0) { + cerr << "Failed to create: " << getPathToSaveFiles()+"/"+path << endl; } #elif defined(_WIN32) //Now for Windows NT/2k/xp/2k3 etc. string tempA = getMyDocumentsPath()+"\\My Games"; CreateDirectory(tempA.c_str(),nullptr); - tempA = getMyDocumentsPath()+"\\My Games\\blockattack"; - CreateDirectory(tempA.c_str(),nullptr); - tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays"; - CreateDirectory(tempA.c_str(),nullptr); - tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots"; + tempA += "/"+path; CreateDirectory(tempA.c_str(),nullptr); #endif +} + +void OsCreateFolders() { + //We first create the folder there we will save (only on UNIX systems) + //we call the external command "mkdir"... the user might have renamed this, but we hope he hasn't + OsCreateFolderInSaveGames("screenshots"); + OsCreateFolderInSaveGames("replays"); + OsCreateFolderInSaveGames("puzzles"); } \ No newline at end of file