예제 #1
0
/**
 * Load a text file to an FString.
 * Supports all combination of ANSI/Unicode files and platforms.
 * @param Result string representation of the loaded file
 * @param Filename name of the file to load
 * @param VerifyFlags flags controlling the hash verification behavior ( see EHashOptions )
 */
bool FFileHelper::LoadFileToString( FString& Result, const TCHAR* Filename, uint32 VerifyFlags )
{
	FArchive* Reader = IFileManager::Get().CreateFileReader( Filename );
	if( !Reader )
	{
		return 0;
	}
	
	int32 Size = Reader->TotalSize();
	uint8* Ch = (uint8*)FMemory::Malloc(Size);
	Reader->Serialize( Ch, Size );
	bool Success = Reader->Close();
	delete Reader;
	BufferToString( Result, Ch, Size );

	// handle SHA verify of the file
	if( (VerifyFlags & EHashOptions::EnableVerify) && ( (VerifyFlags & EHashOptions::ErrorMissingHash) || FSHA1::GetFileSHAHash(Filename, NULL) ) )
	{
		// kick off SHA verify task. this frees the buffer on close
		FBufferReaderWithSHA Ar( Ch, Size, true, Filename, false, true );
	}
	else
	{
		// free manually since not running SHA task
		FMemory::Free(Ch);
	}

	return Success;
}
예제 #2
0
파일: Variant.cpp 프로젝트: PeteX/Urho3D
String Variant::ToString() const
{
    switch (type_)
    {
    case VAR_INT:
        return String(value_.int_);

    case VAR_BOOL:
        return String(value_.bool_);

    case VAR_FLOAT:
        return String(value_.float_);

    case VAR_VECTOR2:
        return (reinterpret_cast<const Vector2*>(&value_))->ToString();

    case VAR_VECTOR3:
        return (reinterpret_cast<const Vector3*>(&value_))->ToString();

    case VAR_VECTOR4:
        return (reinterpret_cast<const Vector4*>(&value_))->ToString();

    case VAR_QUATERNION:
        return (reinterpret_cast<const Quaternion*>(&value_))->ToString();

    case VAR_COLOR:
        return (reinterpret_cast<const Color*>(&value_))->ToString();

    case VAR_STRING:
        return *(reinterpret_cast<const String*>(&value_));

    case VAR_BUFFER:
        {
            const PODVector<unsigned char>& buffer = *(reinterpret_cast<const PODVector<unsigned char>*>(&value_));
            String ret;
            BufferToString(ret, buffer.Begin().ptr_, buffer.Size());
            return ret;
        }

    case VAR_PTR:
        // Pointer serialization not supported (convert to null)
        return String(0);

    case VAR_INTRECT:
        return (reinterpret_cast<const IntRect*>(&value_))->ToString();

    case VAR_INTVECTOR2:
        return (reinterpret_cast<const IntVector2*>(&value_))->ToString();

    default:
        // VAR_RESOURCEREF, VAR_RESOURCEREFLIST, VAR_VARIANTVECTOR, VAR_VARIANTMAP
        // Reference string serialization requires typehash-to-name mapping from the context. Can not support here
        // Also variant map or vector string serialization is not supported. XML or binary save should be used instead
        return String::EMPTY;
    }
}
예제 #3
0
bool XMLElement::SetBuffer(const ea::string& name, const void* data, unsigned size)
{
    ea::string dataStr;
    BufferToString(dataStr, data, size);
    return SetAttribute(name, dataStr);
}
예제 #4
0
파일: JSONValue.cpp 프로젝트: Boshin/Urho3D
void JSONValue::AddBuffer(const void* data, unsigned size)
{
    String dataStr;
    BufferToString(dataStr, data, size);
    AddString(dataStr);
}
예제 #5
0
파일: JSONValue.cpp 프로젝트: Boshin/Urho3D
void JSONValue::SetBuffer(const String& name, const void* data, unsigned size)
{
    String dataStr;
    BufferToString(dataStr, data, size);
    SetString(name, dataStr);
}