Exemple #1
0
fileDescriptor tfs_openFile(char *name) {
	int file_block_num, check, numFree, dir_block_num, return_fd;
	char dir[strlen(name) + 1];
   	char *lastSlash;
	Inode inode;
	SuperBlock superblock;
    
    if(tfs_name_check(name) < 0) {
        return BAD_FILENAME;
    }

	if (readBlock(disk_num, 0, &superblock) < 0) {
		return READ_ERROR;
	}

	file_block_num = Dir_File_Exists(name, disk_num);

	if (file_block_num == DIR_DNE) {
		return DIR_DNE;
	}


	if (file_block_num == FILE_DNE) {
		if ((check = sb_numFreeBlocks(&superblock, disk_num, &numFree)) < 0) { // 
			return check;
		}

		if (numFree == 0) {
			return NO_FREE_BLOCKS;
		}

		strcpy(dir, name);
		lastSlash = strrchr(name, '/'); 
		dir[lastSlash - name + 1] = 0; // stores the path of the directory without the file at the end
		in_init(&inode, lastSlash + 1, dir_block_num = Dir_Exists(disk_num, dir));

		if ((file_block_num = sb_getFreeBlock(&superblock, disk_num)) < 0) {
			return file_block_num;
		}

		if (writeBlock(disk_num, file_block_num, &inode) < 0) {
			sb_makeFreeBlock(&superblock, disk_num, file_block_num); 
			return WRITE_ERROR;
		}

		if ((check = Dir_AddFileToDir(disk_num, file_block_num, dir_block_num)) < 0) {
			return check;
		}
	}

	if ((check = OFTable_Add(&oftable, file_block_num, &return_fd)) < 0) {
		return check;
	}

	return return_fd;
}
void cResource_Manager :: Init_User_Directory( void )
{
	// Create user directory
	if( !Dir_Exists( user_data_dir ) )
	{
		// first run if not available
		Create_Directory( user_data_dir );
	}
	// Create savegame directory
	if( !Dir_Exists( user_data_dir + USER_SAVEGAME_DIR ) )
	{
		Create_Directory( user_data_dir + USER_SAVEGAME_DIR );
	}
	// Create screenshot directory
	if( !Dir_Exists( user_data_dir + USER_SCREENSHOT_DIR ) )
	{
		Create_Directory( user_data_dir + USER_SCREENSHOT_DIR );
	}
	// Create level directory
	if( !Dir_Exists( user_data_dir + USER_LEVEL_DIR ) )
	{
		Create_Directory( user_data_dir + USER_LEVEL_DIR );
	}
	// Create world directory
	if( !Dir_Exists( user_data_dir + USER_WORLD_DIR ) )
	{
		Create_Directory( user_data_dir + USER_WORLD_DIR );
	}
	// Create cache directory
	if( !Dir_Exists( user_data_dir + USER_IMGCACHE_DIR ) )
	{
		Create_Directory( user_data_dir + USER_IMGCACHE_DIR );
	}
}
Exemple #3
0
void cOverworld :: Save( void )
{
	pAudio->Play_Sound( "editor/save.ogg" );

	std::string save_dir = pResource_Manager->user_data_dir + USER_WORLD_DIR + "/" + m_description->m_path;
	// Create directory if new world
	if( !Dir_Exists( save_dir ) )
	{
		Create_Directory( save_dir );
	}

	std::string filename = save_dir + "/world.xml";

// fixme : Check if there is a more portable way f.e. with imbue()
#ifdef _WIN32
	ofstream file( utf8_to_ucs2( filename ).c_str(), ios::out | ios::trunc );
#else
	ofstream file( filename.c_str(), ios::out | ios::trunc );
#endif


	if( !file )
	{
		printf( "Error : Couldn't open world file for saving. Is the file read-only ?" );
		pHud_Debug->Set_Text( _("Couldn't save world ") + filename, speedfactor_fps * 5.0f );
		return;
	}

	CEGUI::XMLSerializer stream( file );


	// begin
	stream.openTag( "overworld" );

	// begin
	stream.openTag( "information" );
		// game version
		Write_Property( stream, "game_version", int_to_string(SMC_VERSION_MAJOR) + "." + int_to_string(SMC_VERSION_MINOR) + "." + int_to_string(SMC_VERSION_PATCH) );
		// engine version
		Write_Property( stream, "engine_version", world_engine_version );
		// time ( seconds since 1970 )
		Write_Property( stream, "save_time", static_cast<Uint64>( time( NULL ) ) );
	// end information
	stream.closeTag();

	// begin
	stream.openTag( "settings" );
		// music
		Write_Property( stream, "music", m_musicfile );
	// end settings
	stream.closeTag();

	// begin
	stream.openTag( "background" );
		// color
		Write_Property( stream, "color_red", static_cast<int>(m_background_color.red) );
		Write_Property( stream, "color_green", static_cast<int>(m_background_color.green) );
		Write_Property( stream, "color_blue", static_cast<int>(m_background_color.blue) );
	// end background
	stream.closeTag();

	// begin
	stream.openTag( "player" );
		// start waypoint
		Write_Property( stream, "waypoint", m_player_start_waypoint );
		// moving state
		Write_Property( stream, "moving_state", static_cast<int>(m_player_moving_state) );
	// end player
	stream.closeTag();

	// objects
	for( cSprite_List::iterator itr = m_sprite_manager->objects.begin(); itr != m_sprite_manager->objects.end(); ++itr )
	{
		cSprite *obj = (*itr);

		// skip spawned and destroyed objects
		if( obj->m_spawned || obj->m_auto_destroy )
		{
			continue;
		}

		// save to file stream
		obj->Save_To_XML( stream );
	}

	// end overworld
	stream.closeTag();

	file.close();

	// save layer
	m_layer->Save( save_dir + "/layer.xml" );
	// save description
	m_description->Save();

	// show info
	pHud_Debug->Set_Text( _("World ") + m_description->m_name + _(" saved") );
}