Exemple #1
0
void TextureManager::LoadAllTGA(File *pDirectory, bool bRecursive)
{
	if (pDirectory && pDirectory->IsDirectory())
	{
		File *pFile = 0;
		for (unsigned int i = 0; i < pDirectory->GetNumChildren(); ++i)
		{
			pFile = pDirectory->GetChild(i);
			if (pFile)
			{
				if (pFile->IsDirectory() && bRecursive)
				{
					//recursive is set to true, so load this directory as well
					LoadAllTGA(pFile, bRecursive);
				}
				else if (!pFile->IsDirectory())
				{	//if its not a directory, check to see if the extension is TGA.  If so, load the texture!
					if ((strcmp(pFile->GetExtension().c_str(), "tga") == 0) || (strcmp(pFile->GetExtension().c_str(), "TGA") == 0))
					{
						LoadTexture(pFile->GetName().c_str());
					}
				}
			}
		}
	}	
}
bool Animation::Save(Serializer& dest) const
{
    // Write ID, name and length
    dest.WriteFileID("UANI");
    dest.WriteString(animationName_);
    dest.WriteFloat(length_);

    // Write tracks
    dest.WriteUInt(tracks_.Size());
    for (HashMap<StringHash, AnimationTrack>::ConstIterator i = tracks_.Begin(); i != tracks_.End(); ++i)
    {
        const AnimationTrack& track = i->second_;
        dest.WriteString(track.name_);
        dest.WriteUByte(track.channelMask_);
        dest.WriteUInt(track.keyFrames_.Size());

        // Write keyframes of the track
        for (unsigned j = 0; j < track.keyFrames_.Size(); ++j)
        {
            const AnimationKeyFrame& keyFrame = track.keyFrames_[j];
            dest.WriteFloat(keyFrame.time_);
            if (track.channelMask_ & CHANNEL_POSITION)
                dest.WriteVector3(keyFrame.position_);
            if (track.channelMask_ & CHANNEL_ROTATION)
                dest.WriteQuaternion(keyFrame.rotation_);
            if (track.channelMask_ & CHANNEL_SCALE)
                dest.WriteVector3(keyFrame.scale_);
        }
    }

    // If triggers have been defined, write an XML file for them
    if (!triggers_.Empty() || HasMetadata())
    {
        File* destFile = dynamic_cast<File*>(&dest);
        if (destFile)
        {
            String xmlName = ReplaceExtension(destFile->GetName(), ".xml");

            SharedPtr<XMLFile> xml(new XMLFile(context_));
            XMLElement rootElem = xml->CreateRoot("animation");

            for (unsigned i = 0; i < triggers_.Size(); ++i)
            {
                XMLElement triggerElem = rootElem.CreateChild("trigger");
                triggerElem.SetFloat("time", triggers_[i].time_);
                triggerElem.SetVariant(triggers_[i].data_);
            }

            SaveMetadataToXML(rootElem);

            File xmlFile(context_, xmlName, FILE_WRITE);
            xml->Save(xmlFile);
        }
        else
            ATOMIC_LOGWARNING("Can not save animation trigger data when not saving into a file");
    }

    return true;
}
Exemple #3
0
bool Shader::ProcessSource(String& code, Deserializer& source)
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    
    // If the source if a non-packaged file, store the timestamp
    File* file = dynamic_cast<File*>(&source);
    if (file && !file->IsPackaged())
    {
        FileSystem* fileSystem = GetSubsystem<FileSystem>();
        String fullName = cache->GetResourceFileName(file->GetName());
        unsigned fileTimeStamp = fileSystem->GetLastModifiedTime(fullName);
        if (fileTimeStamp > timeStamp_)
            timeStamp_ = fileTimeStamp;
    }
    
    // Store resource dependencies for includes so that we know to reload if any of them changes
    if (source.GetName() != GetName())
        cache->StoreResourceDependency(this, source.GetName());
    
    while (!source.IsEof())
    {
        String line = source.ReadLine();
        
        if (line.StartsWith("#include"))
        {
            String includeFileName = GetPath(source.GetName()) + line.Substring(9).Replaced("\"", "").Trimmed();
            
            SharedPtr<File> includeFile = cache->GetFile(includeFileName);
            if (!includeFile)
                return false;
            
            // Add the include file into the current code recursively
            if (!ProcessSource(code, *includeFile))
                return false;
        }
        else
        {
            code += line;
            code += "\n";
        }
    }

    // Finally insert an empty line to mark the space between files
    code += "\n";
    
    return true;
}
Exemple #4
0
string User::GetJsonByUserContentList(std::list<UserContent*> list, bool full)
{
	string json;
	for (std::list<UserContent*>::iterator it=list.begin(); it != list.end(); ++it)
	{
		json += "{";
		json += "\"identifier\" : " + std::to_string((*it)->identifier)  + ",";
		json += "\"type\" : " + std::to_string((*it)->type) + ",";

		if(full)
		{
			File* file = new File();
			file->Load((*it)->identifier);

			json += "\"name\" : \"" + file->GetName() + "\",";
			json += "\"extension\" : \"" + file->GetExtension() + "\",";
			json += "\"sizeMB\" : " + std::to_string(file->GetSize()) + ",";
			json += "\"owner\" : " + file->GetOwner() + ",";
			json += "\"tags\" : " + file->GetTagsStr() + ",";
			if(file->IsDeleted())
				json += "\"delete\" : true,";
			else
				json += "\"delete\" : false,";
			json += "\"lastModifiedBy\" : \"" + file->GetLastModifiedBy() + "\", ";
			json += "\"lastModifiedOn\" : \"" + to_string(file->GetLastModifiedOn())+ "\",";
			json += "\"lastVersion\" : " + std::to_string(file->GetLastVersion()) + ",";
			json += "\"versions\" :" + file->GetVersionsStr() + ",";

			delete file;
		}

		json += "\"content\" : [";
		if((*it)->type == 2)
			json += GetJsonByUserContentList((*it)->content, full);
		json += "]";
		json += "},";
	}
	return json.substr(0, json.length() - 1);
}
Exemple #5
0
string User::GetJsonBySharedFilesList(bool full)
{
	string json;
	for (std::list<int>::iterator it=sharedFiles.begin(); it != sharedFiles.end(); ++it)
	{
		if(full)
		{
			File* file = new File();
			file->Load(*it);

			json += "{";
			json += "\"identifier\" : " + std::to_string(file->GetIdentifier())  + ",";
			json += "\"type\" : " + std::to_string(file->GetType()) + ",";
			json += "\"name\" : \"" + file->GetName() + "\",";
			json += "\"extension\" : \"" + file->GetExtension() + "\",";
			json += "\"sizeMB\" : " + std::to_string(file->GetSize()) + ",";
			json += "\"owner\" : " + file->GetOwner() + ",";
			json += "\"tags\" : " + file->GetTagsStr() + ",";
			if(file->IsDeleted())
				json += "\"delete\" : true,";
			else
				json += "\"delete\" : false,";
			json += "\"lastModifiedOn\" : \"" + to_string(file->GetLastModifiedOn()) + "\",";
			json += "\"lastModifiedBy\" : \"" + file->GetLastModifiedBy() + "\",";
			json += "\"lastVersion\" : " + std::to_string(file->GetLastVersion()) + ",";
			json += "\"versions\" : " + file->GetVersionsStr();

			delete file;

			json += "},";

		}
		else
			json += std::to_string(*it) + ",";
	}
	return json.substr(0, json.length() - 1);
}
Exemple #6
0
bool Model::Save(Serializer& dest) const
{
    // Write ID
    if (!dest.WriteFileID("UMD2"))
        return false;

    // Write vertex buffers
    dest.WriteUInt(vertexBuffers_.Size());
    for (unsigned i = 0; i < vertexBuffers_.Size(); ++i)
    {
        VertexBuffer* buffer = vertexBuffers_[i];
        dest.WriteUInt(buffer->GetVertexCount());
        const PODVector<VertexElement>& elements = buffer->GetElements();
        dest.WriteUInt(elements.Size());
        for (unsigned j = 0; j < elements.Size(); ++j)
        {
            unsigned elementDesc = ((unsigned)elements[j].type_) |
                (((unsigned)elements[j].semantic_) << 8) |
                (((unsigned)elements[j].index_) << 16);
            dest.WriteUInt(elementDesc);
        }
        dest.WriteUInt(morphRangeStarts_[i]);
        dest.WriteUInt(morphRangeCounts_[i]);
        dest.Write(buffer->GetShadowData(), buffer->GetVertexCount() * buffer->GetVertexSize());
    }
    // Write index buffers
    dest.WriteUInt(indexBuffers_.Size());
    for (unsigned i = 0; i < indexBuffers_.Size(); ++i)
    {
        IndexBuffer* buffer = indexBuffers_[i];
        dest.WriteUInt(buffer->GetIndexCount());
        dest.WriteUInt(buffer->GetIndexSize());
        dest.Write(buffer->GetShadowData(), buffer->GetIndexCount() * buffer->GetIndexSize());
    }
    // Write geometries
    dest.WriteUInt(geometries_.Size());
    for (unsigned i = 0; i < geometries_.Size(); ++i)
    {
        // Write bone mappings
        dest.WriteUInt(geometryBoneMappings_[i].Size());
        for (unsigned j = 0; j < geometryBoneMappings_[i].Size(); ++j)
            dest.WriteUInt(geometryBoneMappings_[i][j]);

        // Write the LOD levels
        dest.WriteUInt(geometries_[i].Size());
        for (unsigned j = 0; j < geometries_[i].Size(); ++j)
        {
            Geometry* geometry = geometries_[i][j];
            dest.WriteFloat(geometry->GetLodDistance());
            dest.WriteUInt(geometry->GetPrimitiveType());
            dest.WriteUInt(LookupVertexBuffer(geometry->GetVertexBuffer(0), vertexBuffers_));
            dest.WriteUInt(LookupIndexBuffer(geometry->GetIndexBuffer(), indexBuffers_));
            dest.WriteUInt(geometry->GetIndexStart());
            dest.WriteUInt(geometry->GetIndexCount());
        }
    }

    // Write morphs
    dest.WriteUInt(morphs_.Size());
    for (unsigned i = 0; i < morphs_.Size(); ++i)
    {
        dest.WriteString(morphs_[i].name_);
        dest.WriteUInt(morphs_[i].buffers_.Size());

        // Write morph vertex buffers
        for (HashMap<unsigned, VertexBufferMorph>::ConstIterator j = morphs_[i].buffers_.Begin();
             j != morphs_[i].buffers_.End(); ++j)
        {
            dest.WriteUInt(j->first_);
            dest.WriteUInt(j->second_.elementMask_);
            dest.WriteUInt(j->second_.vertexCount_);

            // Base size: size of each vertex index
            unsigned vertexSize = sizeof(unsigned);
            // Add size of individual elements
            if (j->second_.elementMask_ & MASK_POSITION)
                vertexSize += sizeof(Vector3);
            if (j->second_.elementMask_ & MASK_NORMAL)
                vertexSize += sizeof(Vector3);
            if (j->second_.elementMask_ & MASK_TANGENT)
                vertexSize += sizeof(Vector3);

            dest.Write(j->second_.morphData_.Get(), vertexSize * j->second_.vertexCount_);
        }
    }

    // Write skeleton
    skeleton_.Save(dest);

    // Write bounding box
    dest.WriteBoundingBox(boundingBox_);

    // Write geometry centers
    for (unsigned i = 0; i < geometryCenters_.Size(); ++i)
        dest.WriteVector3(geometryCenters_[i]);

    // Write metadata
    if (HasMetadata())
    {
        File* destFile = dynamic_cast<File*>(&dest);
        if (destFile)
        {
            String xmlName = ReplaceExtension(destFile->GetName(), ".xml");

            SharedPtr<XMLFile> xml(new XMLFile(context_));
            XMLElement rootElem = xml->CreateRoot("model");
            SaveMetadataToXML(rootElem);

            File xmlFile(context_, xmlName, FILE_WRITE);
            xml->Save(xmlFile);
        }
        else
            URHO3D_LOGWARNING("Can not save model metadata when not saving into a file");
    }

    return true;
}
void test_object_fetch(void)
{
    ocout << otext("\n>>>>> TEST OBJECT FETCHING \n\n");

    Statement st(con);
    st.Execute(otext("select val from test_object for update"));

    Resultset rs = st.GetResultset();
    while (rs++)
    {
        Object obj = rs.Get<Object>(1);

        ocout << otext(".... val_int      : ") << obj.Get<int>(otext("VAL_INT")) << oendl;
        ocout << otext(".... val_dbl      : ") << obj.Get<double>(otext("VAL_DBL")) << oendl;
        ocout << otext(".... val_flt      : ") << obj.Get<float>(otext("VAL_FLT")) << oendl;
        ocout << otext(".... val_str      : ") << obj.Get<ostring>(otext("VAL_STR")) << oendl;
        ocout << otext(".... val_date     : ") << obj.Get<Date>(otext("VAL_DATE")) << oendl;

        Clob clob = obj.Get<Clob>(otext("VAL_LOB"));
        ocout << otext(".... val_lob      : ") << clob.Read(SizeBuffer) << oendl;

        File file = obj.Get<File>(otext("VAL_FILE"));
        ocout << otext(".... val_file     : ") << file.GetDirectory() << otext("/") << file.GetName() << oendl;

        Raw raw = obj.Get<Raw>(otext("VAL_RAW"));
        raw.push_back(0);
        ocout << otext(".... val_raw      : ") << reinterpret_cast<char *>(raw.data()) << oendl;

        Object obj2 = obj.Get<Object>(otext("VAL_OBJ"));
        ocout << otext(".... val_obj.code : ") << obj2.Get<int>(otext("ID")) << oendl;
        ocout << otext(".... val_obj.name : ") << obj2.Get<ostring>(otext("NAME")) << oendl;
    }

    con.Commit();

    ocout << otext("\n>>>>> TEST OBJECT FETCHING  AS STRING \n\n");

    st.Execute(otext("select val from test_object"));

    rs = st.GetResultset();
    while (rs++)
    {
        ocout << rs.Get<Object>(1) << oendl;
    }
}
void test_returning_array(void)
{
    ocout << otext("\n>>>>> TEST ARRAY BINDING WITH RETURNING CLAUSE \n\n");

    std::vector<int>     tab_int;
    std::vector<double>  tab_dbl;
    std::vector<float>   tab_flt;
    std::vector<ostring> tab_str;
    std::vector<Date>    tab_date;
    std::vector<Clob>    tab_lob;
    std::vector<File>    tab_file;


    for (int i = 0; i < ElemCount; i++)
    {
        tab_int.push_back(i + 1);
        tab_dbl.push_back(3.14*static_cast<double>(i + 1));
        tab_flt.push_back(3.14f*static_cast<float>(i + 1));

        ostring str;
        str += otext("Name");
        str += ((i + 1) + '0');
        tab_str.push_back(str);

        tab_date.push_back(Date::SysDate());

        Clob clob(con);
        clob.Write(otext("Lob value ") + str);
        tab_lob.push_back(clob);

        ostring fileName;
        fileName += otext("File");
        fileName += ((i + 1) + '0');
        File file(con, otext("Mydir"), fileName);
        tab_file.push_back(file);
    }

    Statement st(con);

    st.Prepare(otext("insert into test_array ")
        otext("( ")
        otext("   val_int,  val_dbl, val_flt, val_str, val_date, ")
        otext("   val_lob, val_file ")
        otext(") ")
        otext("values ")
        otext("( ")
        otext("   :val_int, :val_dbl, :val_flt, :val_str, :val_date, ")
        otext("   :val_lob, :val_file ")
        otext(") ")
        otext("returning")
        otext("  val_int,  val_dbl, val_flt, val_str, val_date, ")
        otext("   val_lob, val_file ")
        otext("into  ")
        otext("  :out_int, :out_dbl, :out_flt,  :out_str, :out_date, ")
        otext("   :out_lob, :out_file "));

    st.SetBindArraySize(ElemCount);

    /* bind vectors */
    st.Bind(otext(":val_int"), tab_int, BindInfo::In);
    st.Bind(otext(":val_dbl"), tab_dbl, BindInfo::In);
    st.Bind(otext(":val_flt"), tab_flt, BindInfo::In);
    st.Bind(otext(":val_date"), tab_date, BindInfo::In);
    st.Bind(otext(":val_lob"), tab_lob, BindInfo::In);
    st.Bind(otext(":val_file"), tab_file, BindInfo::In);
    st.Bind(otext(":val_str"), tab_str, 30, BindInfo::In);

    /* register output */
    st.Register<int    >(otext(":out_int"));
    st.Register<double >(otext(":out_dbl"));
    st.Register<float  >(otext(":out_flt"));
    st.Register<Date   >(otext(":out_date"));
    st.Register<Clob   >(otext(":out_lob"));
    st.Register<File   >(otext(":out_file"));
    st.Register<ostring>(otext(":out_str"), 30);

    st.ExecutePrepared();
    ocout << oendl << st.GetAffectedRows() << otext(" row(s) inserted") << oendl;

    int rowIndex = 0;

    Resultset rs = st.GetResultset();
    while (!rs.IsNull())
    {
        while (rs++)
        {
            ocout << otext("Row #") << ++rowIndex << otext("---------------") << oendl;

            ocout << otext(".... val_int    : ") << rs.Get<int>(otext(":OUT_INT")) << oendl;
            ocout << otext(".... val_dbl    : ") << rs.Get<double>(otext(":OUT_DBL")) << oendl;
            ocout << otext(".... val_flt    : ") << rs.Get<float>(otext(":OUT_FLT")) << oendl;
            ocout << otext(".... val_str    : ") << rs.Get<ostring>(otext(":OUT_STR")) << oendl;
            ocout << otext(".... val_date   : ") << rs.Get<Date>(otext(":OUT_DATE")) << oendl;

            Clob clob = rs.Get<Clob>(otext(":OUT_LOB"));
            ocout << otext(".... val_lob    : ") << clob.Read(SizeBuffer) << oendl;

            File file = rs.Get<File>(otext(":OUT_FILE"));
            ocout << otext(".... val_file   : ") << file.GetDirectory() << otext("/") << file.GetName() << oendl;
        }

        rs = st.GetNextResultset();
    }
}
Exemple #9
0
   File*
   Logger::_GetCurrentLogFile(LogType lt)
   {
      String fileName = GetCurrentLogFileName(lt);
      m_bSepSvcLogs = IniFileSettings::Instance()->GetSepSvcLogs();

      bool writeUnicode = false;

      File *file = 0;
      switch (lt)
      {
      case Normal:
         file = &_normalLogFile;
         writeUnicode = false;
         break;
      case Error:
         file = &_errorLogFile;
         writeUnicode = false;
         break;
      case AWStats:
         file = &_awstatsLogFile;
         writeUnicode = false;
         break;
      case Backup:
         file = &_backupLogFile;
         writeUnicode = true;
         break;
      case Events:
         file = &_eventsLogFile;
         writeUnicode = true;
         break;
      case IMAP:
         if (m_bSepSvcLogs) 
            file = &_IMAPLogFile;
         else
            file = &_normalLogFile;
         writeUnicode = false;
         break;
      case POP3:
         if (m_bSepSvcLogs) 
            file = &_POP3LogFile;
         else
            file = &_normalLogFile;
         writeUnicode = false;
         break;
      case SMTP:
         if (m_bSepSvcLogs) 
            file = &_SMTPLogFile;
         else
            file = &_normalLogFile;
         writeUnicode = false;
         break;
      }

      bool fileExists = FileUtilities::Exists(fileName);

      if (file->IsOpen())
      {
         if (file->GetName() != fileName)
            file->Close();
         else if (!fileExists)
            file->Close();
      }
      
      if (!file->IsOpen())
      {
         file->Open(fileName, File::OTAppend);

         if (!fileExists && writeUnicode)
         {
            file->WriteBOF();
         }
      }

      return file;
   }
Exemple #10
0
bool Font::SaveXML(Serializer& dest, int pointSize, bool usedGlyphs)
{
    const FontFace* fontFace = GetFace(pointSize);
    if (!fontFace)
        return false;

    PROFILE(FontSaveXML);

    SharedPtr<FontFace> packedFontFace;
    if (usedGlyphs)
    {
        // Save used glyphs only, try to pack them first
        packedFontFace = Pack(fontFace);
        if (packedFontFace)
            fontFace = packedFontFace;
        else
            return false;
    }

    SharedPtr<XMLFile> xml(new XMLFile(context_));
    XMLElement rootElem = xml->CreateRoot("font");

    // Information
    XMLElement childElem = rootElem.CreateChild("info");
    String fileName = GetFileName(GetName());
    childElem.SetAttribute("face", fileName);
    childElem.SetAttribute("size", String(pointSize));

    // Common
    childElem = rootElem.CreateChild("common");
    childElem.SetInt("lineHeight", fontFace->rowHeight_);
    unsigned pages = fontFace->textures_.Size();
    childElem.SetInt("pages", pages);

    // Construct the path to store the texture
    String pathName;
    File* file = dynamic_cast<File*>(&dest);
    if (file)
        // If serialize to file, use the file's path
        pathName = GetPath(file->GetName());
    else
        // Otherwise, use the font resource's path
        pathName = "Data/" + GetPath(GetName());

    // Pages
    childElem = rootElem.CreateChild("pages");
    for (unsigned i = 0; i < pages; ++i)
    {
        XMLElement pageElem = childElem.CreateChild("page");
        pageElem.SetInt("id", i);
        String texFileName = fileName + "_" + String(i) + ".png";
        pageElem.SetAttribute("file", texFileName);

        // Save the font face texture to image file
        SaveFaceTexture(fontFace->textures_[i], pathName + texFileName);
    }

    // Chars and kernings
    XMLElement charsElem = rootElem.CreateChild("chars");
    unsigned numGlyphs = fontFace->glyphs_.Size();
    charsElem.SetInt("count", numGlyphs);
    XMLElement kerningsElem;
    bool hasKerning = fontFace->hasKerning_;
    if (hasKerning)
        kerningsElem = rootElem.CreateChild("kernings");
    for (HashMap<unsigned, unsigned>::ConstIterator i = fontFace->glyphMapping_.Begin(); i != fontFace->glyphMapping_.End(); ++i)
    {
        // Char
        XMLElement charElem = charsElem.CreateChild("char");
        charElem.SetInt("id", i->first_);
        FontGlyph glyph = fontFace->glyphs_[i->second_];
        charElem.SetInt("x", glyph.x_);
        charElem.SetInt("y", glyph.y_);
        charElem.SetInt("width", glyph.width_);
        charElem.SetInt("height", glyph.height_);
        charElem.SetInt("xoffset", glyph.offsetX_);
        charElem.SetInt("yoffset", glyph.offsetY_);
        charElem.SetInt("xadvance", glyph.advanceX_);
        charElem.SetInt("page", glyph.page_);

        // Kerning
        if (hasKerning)
        {
            for (HashMap<unsigned, unsigned>::ConstIterator j = glyph.kerning_.Begin(); j != glyph.kerning_.End(); ++j)
            {
                // To conserve space, only write when amount is non zero
                if (j->second_ == 0)
                    continue;

                XMLElement kerningElem = kerningsElem.CreateChild("kerning");
                kerningElem.SetInt("first", i->first_);
                kerningElem.SetInt("second", j->first_);
                kerningElem.SetInt("amount", j->second_);
            }
        }
    }

    return xml->Save(dest);
}