Example #1
0
void GameFileArray::init(const char *extStr)
{
	//------------- Read Hall of Fame ------------//

	if( !has_read_hall_of_fame )		// only read once, GameFileArray::init() is called every time the load/save game menu is brought up.
	{
		read_hall_of_fame();
		has_read_hall_of_fame = 1;
	}

	//-- Load all headers of all saved game files in current directory --//

	load_all_game_header(extStr);
}
Example #2
0
//------ Begin of function GameFileArray::init ------//
//
// <char *>path - path of the save game, without '/' at the end
// <char *>extStr - extension of the save game
//
void GameFileArray::init(const char *path, const char *extStr)
{
	//------------- Read Hall of Fame ------------//

	if( !has_read_hall_of_fame )		// only read once, GameFileArray::init() is called every time the load/save game menu is brought up.
	{
		read_hall_of_fame();
		has_read_hall_of_fame = 1;
	}

	//-- Load all headers of all saved game files in current directory --//

	strcpy( save_default_dir, path );
	// REMOVE '/' at the end if any, 
	m.rtrim( save_default_dir);		// trim space at the end first
	int dirLen = strlen(save_default_dir);
	if( dirLen > 1 && save_default_dir[dirLen-1] == '/' )
		save_default_dir[dirLen-1] = '\0';

	strcpy( save_default_ext, extStr);

	load_all_game_header(save_default_dir, save_default_ext);
}
Example #3
0
//-------- Begin of function GameFileArray::save_new_game -----//
//
// Save current game to a new saved game file immediately without
// prompting menu.
//
// Called by GameFileArray::process_action() and error handler.
//
// <char*> fileName - file name of the saved game
//
// return 1 - success
//        0 - cancel
//       -1 - fail
//
// ###### begin Gilbert 20/1 ########//
int GameFileArray::save_new_game(const char* fileName)
{
	GameFile  gameFile;
	GameFile* gameFilePtr;
	int       addFlag=1;
	int       gameFileRecno;

	memset( &gameFile, 0, sizeof(GameFile) );

	if( fileName )		// has a filename before extension
	{
		load_all_game_header( save_default_dir, save_default_ext );

		// ### begin Gilbert 26/5 #####//
		// fileName = player_profile.save_game_path(fileName);
		// ### end Gilbert 26/5 #####//

		if( save_default_dir[0] != '\0' )
		{
			strcpy( gameFile.file_name, save_default_dir );
			strcat( gameFile.file_name, "/" );
			strcat( gameFile.file_name, fileName );
		}
		else
		{
			strcpy( gameFile.file_name, fileName );
		}

		// if fileName without extension append

		if( !strchr(fileName, '.' ) )
		{
			strcat(gameFile.file_name, strchr( save_default_ext, '.') );		// remove '*' of "*.SAV"
		}

		//----- check for overwriting an existing file ----//

		for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ )
		{
			gameFilePtr = game_file_array[gameFileRecno];

			// ###### begin Gilbert 31/10 ######//
			if( strcasecmp(gameFilePtr->file_name, gameFile.file_name)==0 )      // if this file name already exist
			// ###### end Gilbert 31/10 ######//
			{
				addFlag=0;
				break;
			}
		}
		// strcpy( gameFile.file_name, fileName );		// now use gameFile.file_name instead
   }
	else
   {
		load_all_game_header( save_default_dir, save_default_ext );

		// find the extension begin with '.'
		err_when( !strchr(save_default_ext, '.') );
      gameFile.set_file_name(save_default_dir, strchr(save_default_ext, '.') );        // give it a new game_file_name based on current group name
   }

	// --------- ask description -------//

	if( !gameFile.ask_desc() )
		return 0;

	//----------- save game now ------------//

	if( gameFile.save_game(save_default_dir, NULL, NULL) )		// use gameFile.file_name
	{
		strcpy( last_file_name, gameFile.file_name );

		if( addFlag )
		{
         linkin(&gameFile);

			quick_sort( sort_game_file_function );
      }
		else
      {
			// #### begin Gilbert 31/10 ######//
         update(&gameFile, gameFileRecno);
			// #### end Gilbert 31/10 ######//
      }

		return 1;
   }

	return -1;

	// ###### end Gilbert 20/1 ########//
}
Example #4
0
// ------- begin of function GameFileArray::reload -------//
//
// load hall of fame and load_all_game_header from default directory
//
void GameFileArray::reload()
{
	load_all_game_header(save_default_dir, save_default_ext);
}