本文整理汇总了C++中FileStream::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::GetSize方法的具体用法?C++ FileStream::GetSize怎么用?C++ FileStream::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::GetSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: net_send_file
int DERPEditor::net_send_file(lua_State *L)
{
if (lua_gettop(L) == 1)
{
const char* path = lua_tostring(L, 1);
FileStream s;
if (!s.OpenReadBinary(path))
{
char msg[4096];
//Format(msg, "Could not open file to send (send_file): '%s'", path);
lua_pushstring(L, msg);
lua_error(L);
return 0;
}
unsigned fsize = s.GetSize();
char* data = new char[fsize];
s.Read(data, fsize);
unsigned long hash = Hash(data, fsize);
s.Close();
Packet* packet = LuaApp::GetInstance()->m_net->CreateEmptyPacket("res", 1 /* datacache */);
// hash, filename, datalen, data
packet->PushInt(hash);
const char* filename = PathFileName(path);
packet->PushString(filename, strlen(filename)+1);
packet->PushInt(fsize);
packet->PushString(data, fsize);
Util::Array<Network::Client*>& Clients = LuaApp::GetInstance()->m_net->GetClients();
Util::Array<Network::Client*>::iterator iter = Clients.begin();
while (iter != Clients.end())
{
printf("Sending to client %d.\n", (*iter)->Ident);
(*iter)->SendPacket(packet);
iter++;
}
delete packet;
delete data;
char ret[256];
//Format(ret, "%X_%s", hash, filename);
lua_pushstring(L, ret);
return 1;
}
else
{
lua_pushstring(L, "Invalid arguments passed to send_file function!");
lua_error(L);
}
return 0;
}
示例2: CacheResource
/// @copydoc ResourceHandler::CacheResource()
bool ShaderResourceHandler::CacheResource(
ObjectPreprocessor* pObjectPreprocessor,
Resource* pResource,
const String& rSourceFilePath )
{
HELIUM_ASSERT( pObjectPreprocessor );
HELIUM_ASSERT( pResource );
const Shader* pShader = Reflect::AssertCast< const Shader >( pResource );
GameObjectPath shaderPath = pShader->GetPath();
HELIUM_TRACE( TraceLevels::Info, TXT( "ShaderResourceHandler: Caching \"%s\".\n" ), *shaderPath.ToString() );
DefaultAllocator allocator;
FileStream* pSourceFileStream = FileStream::OpenFileStream( rSourceFilePath, FileStream::MODE_READ );
if( !pSourceFileStream )
{
HELIUM_TRACE(
TraceLevels::Error,
TXT( "ShaderResourceHandler: Source file for shader resource \"%s\" failed to open properly.\n" ),
*shaderPath.ToString() );
return false;
}
// Load the entire shader resource into memory.
int64_t size64 = pSourceFileStream->GetSize();
HELIUM_ASSERT( size64 != -1 );
HELIUM_ASSERT( static_cast< uint64_t >( size64 ) <= static_cast< size_t >( -1 ) );
if( size64 > static_cast< uint64_t >( static_cast< size_t >( -1 ) ) )
{
HELIUM_TRACE(
TraceLevels::Error,
( TXT( "ShaderResourceHandler: Source file for shader resource \"%s\" is too large to fit into " )
TXT( "memory for preprocessing.\n" ) ),
*shaderPath.ToString() );
delete pSourceFileStream;
return false;
}
size_t size = static_cast< size_t >( size64 );
void* pShaderData = allocator.Allocate( size );
HELIUM_ASSERT( pShaderData );
if( !pShaderData )
{
HELIUM_TRACE(
TraceLevels::Error,
( TXT( "ShaderResourceHandler: Failed to allocate %" ) TPRIuSZ TXT( " bytes for loading the source " )
TXT( "data of \"%s\" for preprocessing.\n" ) ),
size,
*shaderPath.ToString() );
delete pSourceFileStream;
return false;
}
BufferedStream( pSourceFileStream ).Read( pShaderData, 1, size );
delete pSourceFileStream;
// Parse all preprocessor toggle and selection tokens from the shader source.
Shader::PersistentResourceData resourceData;
const char* pLineEnd = static_cast< const char* >( pShaderData );
const char* pShaderEnd = pLineEnd + size;
do
{
const char* pLineStart = pLineEnd;
while( pLineEnd < pShaderEnd )
{
char character = *pLineEnd;
if( character == '\n' || character == '\r' )
{
break;
}
++pLineEnd;
}
ParseLine( shaderPath, resourceData, pLineStart, pLineEnd );
while( pLineEnd < pShaderEnd )
{
char character = *pLineEnd;
if( character != '\n' && character != '\r' )
{
break;
}
++pLineEnd;
}
} while( pLineEnd < pShaderEnd );
//.........这里部分代码省略.........
示例3: CacheResource
/// @copydoc ResourceHandler::CacheResource()
bool FontResourceHandler::CacheResource(
ObjectPreprocessor* pObjectPreprocessor,
Resource* pResource,
const String& rSourceFilePath )
{
HELIUM_ASSERT( pObjectPreprocessor );
HELIUM_ASSERT( pResource );
Font* pFont = Reflect::AssertCast< Font >( pResource );
// Load the font into memory ourselves in order to make sure we properly support Unicode file names.
FileStream* pFileStream = File::Open( rSourceFilePath, FileStream::MODE_READ );
if( !pFileStream )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Source file for font resource \"%s\" failed to open properly.\n" ),
*rSourceFilePath );
return false;
}
uint64_t fileSize64 = static_cast< uint64_t >( pFileStream->GetSize() );
if( fileSize64 > SIZE_MAX )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Font file \"%s\" exceeds the maximum addressable size of data in memory for " )
TXT( "this platform and will not be cached.\n" ) ),
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t fileSize = static_cast< size_t >( fileSize64 );
uint8_t* pFileData = new uint8_t [ fileSize ];
if( !pFileData )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Failed to allocate %" ) TPRIuSZ TXT( " bytes for resource data for font " )
TXT( "\"%s\".\n" ) ),
fileSize,
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t bytesRead = pFileStream->Read( pFileData, 1, fileSize );
delete pFileStream;
if( bytesRead != fileSize )
{
HELIUM_TRACE(
TRACE_WARNING,
( TXT( "FontResourceHandler: Attempted to read %" ) TPRIuSZ TXT( " bytes from font resource file \"%s\", " )
TXT( "but only %" ) TPRIuSZ TXT( " bytes were read successfully.\n" ) ),
fileSize,
*rSourceFilePath,
bytesRead );
}
// Create the font face.
FT_Library pLibrary = GetStaticLibrary();
HELIUM_ASSERT( pLibrary );
FT_Face pFace = NULL;
FT_Error error = FT_New_Memory_Face( pLibrary, pFileData, static_cast< FT_Long >( bytesRead ), 0, &pFace );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to create font face from resource file \"%s\".\n" ),
*rSourceFilePath );
delete [] pFileData;
return false;
}
// Set the appropriate font size.
int32_t pointSize = Font::Float32ToFixed26x6( pFont->GetPointSize() );
uint32_t dpi = pFont->GetDpi();
error = FT_Set_Char_Size( pFace, pointSize, pointSize, dpi, dpi );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to set size of font resource \"%s\".\n" ),
*rSourceFilePath );
FT_Done_Face( pFace );
delete [] pFileData;
//.........这里部分代码省略.........
示例4: includePath
/// Open a shader include file.
///
/// @param[in] includeType Location of the include file.
/// @param[in] pFileName Name of the include file.
/// @param[in] pParentData Pointer to the container that includes the include file.
/// @param[out] ppData Pointer to the returned buffer that contains the include directives. This pointer
/// remains valid until Close() is called.
/// @param[out] pBytes Number of bytes returned in ppData.
///
/// @return S_OK if the include file was loaded successfully, an error code if not.
///
/// @see Close()
HRESULT D3DIncludeHandler::Open(
D3D10_INCLUDE_TYPE /*includeType*/,
LPCSTR pFileName,
LPCVOID /*pParentData*/,
LPCVOID* ppData,
UINT* pBytes )
{
HELIUM_ASSERT( pFileName );
HELIUM_ASSERT( ppData );
HELIUM_ASSERT( pBytes );
// Build the path to the file to include.
String fileName;
StringConverter< char, tchar_t >::Convert( fileName, pFileName );
Path includePath( m_shaderDirectory + fileName.GetData() );
// Attempt to open and read the contents of the include file.
FileStream* pIncludeFileStream = File::Open( includePath.c_str(), FileStream::MODE_READ );
if( !pIncludeFileStream )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "D3DIncludeHandler::Open(): Failed to open include file \"%s\" for reading.\n" ),
*includePath );
return E_FAIL;
}
int64_t fileSizeActual = pIncludeFileStream->GetSize();
HELIUM_ASSERT( fileSizeActual >= 0 );
if( fileSizeActual > UINT32_MAX )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "D3DIncludeHandler::Open(): Include file \"%s\" is larger than 4 GB and cannot be read.\n" ) ),
*includePath );
delete pIncludeFileStream;
return E_FAIL;
}
uint32_t fileSize = static_cast< uint32_t >( fileSizeActual );
DefaultAllocator allocator;
void* pBuffer = allocator.Allocate( fileSize );
if( !pBuffer )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "D3DIncludeHandler::Open(): Failed to allocate %" ) TPRIu32 TXT( " bytes for loading include " )
TXT( "file \"%s\".\n" ) ),
fileSize,
*includePath );
delete pIncludeFileStream;
return E_FAIL;
}
size_t bytesRead = pIncludeFileStream->Read( pBuffer, 1, fileSize );
if( bytesRead != fileSize )
{
HELIUM_TRACE(
TRACE_WARNING,
( TXT( "D3DIncludeHandler::Open(): Include file \"%s\" claimed to be %" ) TPRIu32 TXT( " bytes, but " )
TXT( "only %" ) TPRIuSZ TXT( " bytes could be read.\n" ) ),
*includePath,
fileSize,
bytesRead );
fileSize = static_cast< uint32_t >( bytesRead );
}
delete pIncludeFileStream;
*ppData = pBuffer;
*pBytes = fileSize;
return S_OK;
}