============== idSessionLocal::HandleSaveGameMenuCommands ============== */
| 336 | ============== |
| 337 | */ |
| 338 | bool idSessionLocal::HandleSaveGameMenuCommand( idCmdArgs &args, int &icmd ) { |
| 339 | |
| 340 | const char *cmd = args.Argv(icmd-1); |
| 341 | |
| 342 | if ( !idStr::Icmp( cmd, "loadGame" ) ) { |
| 343 | int choice = guiActive->State().GetInt("loadgame_sel_0"); |
| 344 | if ( choice >= 0 && choice < loadGameList.Num() ) { |
| 345 | sessLocal.LoadGame( loadGameList[choice] ); |
| 346 | } |
| 347 | return true; |
| 348 | } |
| 349 | |
| 350 | if ( !idStr::Icmp( cmd, "saveGame" ) ) { |
| 351 | const char *saveGameName = guiActive->State().GetString("saveGameName"); |
| 352 | if ( saveGameName && saveGameName[0] ) { |
| 353 | |
| 354 | // First see if the file already exists unless they pass '1' to authorize the overwrite |
| 355 | if ( icmd == args.Argc() || atoi(args.Argv( icmd++ )) == 0 ) { |
| 356 | idStr saveFileName = saveGameName; |
| 357 | sessLocal.ScrubSaveGameFileName( saveFileName ); |
| 358 | saveFileName = "savegames/" + saveFileName; |
| 359 | saveFileName.SetFileExtension(".save"); |
| 360 | |
| 361 | idStr game = cvarSystem->GetCVarString( "fs_game" ); |
| 362 | idFile *file; |
| 363 | if(game.Length()) { |
| 364 | file = fileSystem->OpenFileRead( saveFileName, true, game ); |
| 365 | } else { |
| 366 | file = fileSystem->OpenFileRead( saveFileName ); |
| 367 | } |
| 368 | |
| 369 | if ( file != NULL ) { |
| 370 | fileSystem->CloseFile( file ); |
| 371 | |
| 372 | // The file exists, see if it's an autosave |
| 373 | saveFileName.SetFileExtension(".txt"); |
| 374 | idLexer src(LEXFL_NOERRORS|LEXFL_NOSTRINGCONCAT); |
| 375 | if ( src.LoadFile( saveFileName ) ) { |
| 376 | idToken tok; |
| 377 | src.ReadToken( &tok ); // Name |
| 378 | src.ReadToken( &tok ); // Map |
| 379 | src.ReadToken( &tok ); // Screenshot |
| 380 | if ( !tok.IsEmpty() ) { |
| 381 | // NOTE: base/ gui doesn't handle that one |
| 382 | guiActive->HandleNamedEvent( "autosaveOverwriteError" ); |
| 383 | return true; |
| 384 | } |
| 385 | } |
| 386 | guiActive->HandleNamedEvent( "saveGameOverwrite" ); |
| 387 | return true; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | sessLocal.SaveGame( saveGameName ); |
| 392 | SetSaveGameGuiVars( ); |
| 393 | // DG: select item 0 => select savegame just created (should be on top as it's newest) |
| 394 | guiActive->SetStateInt( "loadgame_sel_0", 0 ); |
| 395 | guiActive->StateChanged( com_frameTime ); |
nothing calls this directly
no test coverage detected