Пример #1
0
//------------------------------------------------------------------------------------
OFS::ofs64 ExtractThread::generateList(OFS::FileList& list)
{
    unsigned int list_max = list.size();
    OFS::ofs64 file_size = 0;
    
    std::string tmpSaveCurrentDir;
    OFS::FileList subList;

    for(unsigned int i = 0;i < list_max;i++)
    {
        list[i].name = currentDir + list[i].name;
        file_size += list[i].file_size;

        if(list[i].flags & OFS::OFS_DIR)
        {
            tmpSaveCurrentDir = currentDir;
            currentDir = list[i].name + "/";

            subList = ofsFile->listFiles(currentDir.c_str());

            file_size += generateList(subList);

            for(unsigned int z = 0;z < subList.size();z++)
                list.push_back(subList[z]);

            currentDir = tmpSaveCurrentDir;
        }
    }

    return file_size;
}
Пример #2
0
//-----------------------------------------------------------------------------
void Ogitors::COFSSceneSerializer::_upgradeOgsceneFileFrom3To4(TiXmlNode* ogsceneRootNode)
{
    TiXmlElement* element = ogsceneRootNode->FirstChildElement();   

    OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();
    OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr();

    OFS::FileList list;
    mFile->listFilesRecursive("/", list);

    Ogre::StringVector terFiles;

    for( unsigned int i = 0;i < list.size(); i++ )
    {
        if(list[i].flags && OFS::OFS_FILE)
        {
            if(list[i].name.substr(list[i].name.size() - 4, 4) == ".ogt")
            {
                terFiles.push_back( list[i].name );
            }
        }
    }

    if( terFiles.size() > 0 )
    {
        Ogre::SceneManager *pUpgSM = Ogre::Root::getSingletonPtr()->createSceneManager("OctreeSceneManager", "UpgradeSCM");

        for( unsigned int i = 0;i < terFiles.size(); i++ )
        {
            Ogre::String filenameorig = terFiles[i];
            Ogre::String filenamebackup = filenameorig + ".backup";

            mFile->renameFile( filenameorig.c_str(), filenamebackup.c_str() );

            OFS::OFSHANDLE *filebackup = new OFS::OFSHANDLE();
            OFS::OFSHANDLE *fileorig = new OFS::OFSHANDLE();

            mFile->createFile(*fileorig, filenameorig.c_str());
            mFile->openFile(*filebackup, filenamebackup.c_str(), OFS::OFS_READ);

            {
                OgreTerrainConverter conv;

                Ogre::DataStreamPtr stream_in = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mFile, filebackup));
                Ogre::DataStreamPtr stream_out = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mFile, fileorig));
                Ogre::DataStreamPtr compressStream(OGRE_NEW Ogre::DeflateStream(filenameorig, stream_in));
                Ogre::StreamSerialiser ser_in(compressStream);
                Ogre::StreamSerialiser ser_out(stream_out);

                conv.Upgrade( ser_in, ser_out );
            }
        }

        Ogre::Root::getSingletonPtr()->destroySceneManager(pUpgSM);
    }
}
Пример #3
0
//----------------------------------------------------------------------------------------
void OfsTreeWidget::fillTree(QTreeWidgetItem *pItem, std::string path)
{
    OFS::FileList list = mFile->listFiles(path.c_str(), OFS::OFS_DIR);

    std::sort(list.begin(), list.end(), OFS::FileEntry::Compare);

    for(unsigned int i = 0;i < list.size();i++)
    {
        Ogre::String name = list[i].name;

        QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
        item->setIcon(0, mOgitorMainWindow->mIconProvider.icon(QFileIconProvider::Folder));
        item->setTextColor(0, Qt::blue);

        std::string fullpath = path + name + "/";
        item->setWhatsThis(0, QString(fullpath.c_str()));

        if(mCapabilities & CAP_SHOW_COLORS)
        {
            bool isReadOnly = (list[i].flags & OFS::OFS_READONLY) > 0;
            bool isHidden = (list[i].flags & OFS::OFS_HIDDEN) > 0;

            QColor textColor = Qt::black;

            if(isReadOnly && isHidden)
                textColor = QColor(255, 210, 210);
            else if(isReadOnly)
                textColor = QColor(255, 0, 0);
            else if(isHidden)
                textColor = QColor(210, 210, 210);

             if(list[i].flags & OFS::OFS_LINK)
                 textColor.setBlue(255); 

            item->setTextColor(0, textColor);
        }

        pItem->addChild(item);

        mItemMap.insert(NameTreeWidgetMap::value_type(fullpath, item));


        fillTree(item, fullpath);
    }

    if(path != "/" && list.size() == 0)
    {
        QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(".")));
        item->setTextColor(0, Qt::black);
        item->setWhatsThis(0, QString(path.c_str()));
        pItem->addChild(item);
    }
}
Пример #4
0
void ModularZoneFactory::loadZoneTemplates(void)
{
    mZoneTemplates.clear();
    if(OgitorsRoot::getSingletonPtr()->IsSceneLoaded())
    {
        //scene is loaded, we can get the project directories

        //parse all the .zone files from the project directory
        //if I had a custom zone resmanager I could get them this way
        //pList = Ogre::ResourceGroupManager::getSingleton().findResourceNames(PROJECT_RESOURCE_GROUP,"*.zone",false);
        //maybe TODO: create .zone resourcemanager

        //Because my.zone files are not a resource I have to manaully get them:
        OFS::OfsPtr& ofsFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();

        OFS::FileList list;

        ofsFile->listFilesRecursive("/", list);

        //get rid of everthing except .zone files
        list.erase(std::remove_if(list.begin(),list.end(),not_a_zonefile),list.end());

        int key = 0;
        OFS::FileList::iterator zonefile;
        for(zonefile = list.begin();zonefile!=list.end();++zonefile)
        {
            //load the .zone XML file and get the zone info
            //.
            ZoneInfo zone = this->_loadZoneDescription((*zonefile).name);
            if(!zone.mName.empty())
            {
                //make sure dependencies are available
                bool resources = false;
                //mesh:
                resources = Ogre::ResourceGroupManager::getSingletonPtr()->resourceExistsInAnyGroup(zone.mMesh);
                if(resources)
                {
                    //add to map
                    mZoneTemplates.insert(ZoneInfoMap::value_type(key,zone));
                    ++key;
                }
            }
        }
    }
}
//----------------------------------------------------------------------------
void extractOFS(Ogre::String path)
{
    unsigned int MAX_BUFFER_SIZE = 16 * 1024 * 1024;

    char *tmp_buffer = new char[MAX_BUFFER_SIZE];

    OFS::OfsPtr& ofsFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();

    OFS::FileList list;

    ofsFile->listFilesRecursive("/", list);

    std::sort(list.begin(), list.end(), OFS::FileEntry::Compare);

    std::ofstream out_handle;
    OFS::OFSHANDLE in_handle;

    for(unsigned int i = 0; i < list.size(); i++)
    {
        std::string file_path = path + list[i].name;

        if(list[i].flags & OFS::OFS_DIR)
        {
            OgitorsSystem::getSingletonPtr()->MakeDirectory(file_path);
        }
        else
        {
            std::string file_ofs_path = list[i].name;

            out_handle.open(file_path.c_str(), std::ofstream::out | std::ofstream::binary);

            if(out_handle.is_open())
            {
                try
                {
                    OFS::OfsResult ret = ofsFile->openFile(in_handle, file_ofs_path.c_str());
                    if(ret != OFS::OFS_OK)
                    {
                        out_handle.close();
                        continue;
                    }

                    unsigned int total = list[i].file_size;

                    while(total > 0)
                    {
                        if(total < MAX_BUFFER_SIZE)
                        {
                            ofsFile->read(in_handle, tmp_buffer, total);
                            out_handle.write(tmp_buffer, total);
                            total = 0;
                        }
                        else
                        {
                            ofsFile->read(in_handle, tmp_buffer, MAX_BUFFER_SIZE);
                            out_handle.write(tmp_buffer, MAX_BUFFER_SIZE);
                            total -= MAX_BUFFER_SIZE;
                        }
                    }
                }
                catch(OFS::Exception&)
                {
                }

                out_handle.close();
                ofsFile->closeFile(in_handle);
            }
        }
    }

    delete [] tmp_buffer;
}
Пример #6
0
int COFSSceneSerializer::Import(Ogre::String importfile)
{
    OgitorsRoot *ogRoot = OgitorsRoot::getSingletonPtr();
    OgitorsSystem *mSystem = OgitorsSystem::getSingletonPtr();
    OFS::OfsPtr& mFile = OgitorsRoot::getSingletonPtr()->GetProjectFile();

    if(importfile == "")
    {
        UTFStringVector extlist;
        extlist.push_back(OTR("Ogitor File System File"));
        extlist.push_back("*.ofs");
        extlist.push_back(OTR("Ogitor Scene File"));
        extlist.push_back("*" + Globals::OGSCENE_FORMAT_EXTENSION);

        importfile = mSystem->GetSetting("system", "oldOpenPath", "");
        importfile = mSystem->DisplayOpenDialog(OTR("Open"), extlist, importfile);
        if(importfile == "") 
            return SCF_CANCEL;

        mSystem->SetSetting("system", "oldOpenPath", importfile);
    }

    importfile = OgitorsUtils::QualifyPath(importfile);

    Ogre::String filePath = OgitorsUtils::ExtractFilePath(importfile);
    Ogre::String fileName = OgitorsUtils::ExtractFileName(importfile);

    bool testpassed = false;
    try
    {
        std::ofstream test((filePath + "test.dat").c_str());
        if(test.is_open())
            testpassed = true;
        test.close();
        mSystem->DeleteFile(filePath + "test.dat");
    }
    catch(...)
    {
        testpassed = false;
    }

    if(!testpassed)
    {
        mSystem->DisplayMessageDialog("The path is read-only. Ogitor can not work with read-only project paths!", DLGTYPE_OK);
        return SCF_CANCEL;
    }

    Ogre::UTFString loadmsg = "";

    int typepos = importfile.find_last_of(".");
    if(typepos != -1 && (importfile.substr(typepos, 4) != ".ofs"))
        importfile = filePath;
    

    OFS::OfsResult oRet;
    if((oRet = mFile.mount(importfile.c_str(), OFS::OFS_MOUNT_OPEN | OFS::OFS_MOUNT_RECOVER)) != OFS::OFS_OK)
    {
        if(oRet == OFS::OFS_PREVIOUS_VERSION)
        {
            mSystem->DisplayMessageDialog("The OFS file is a previous version, please use qtOFS to upgrade it to new file version.", DLGTYPE_OK);
        }

        loadmsg = mSystem->Translate("Please load a Scene File...");
        mSystem->UpdateLoadProgress(-1, loadmsg);
        return SCF_ERRPARSE;
    }

    OFS::FileSystemStats fsStats;

    mFile->getFileSystemStats(fsStats);

    PROJECTOPTIONS *pOpt = ogRoot->GetProjectOptions();
    pOpt->CreatedIn = "";

    pOpt->ProjectDir = filePath;
    typepos = fileName.find_last_of(".");
    if(typepos != -1)
        fileName.erase(typepos, fileName.length() - typepos);
    pOpt->ProjectName = fileName;

    fileName += Globals::OGSCENE_FORMAT_EXTENSION;

    OFS::ofs64 file_size = 0;

    if(mFile->getFileSize(fileName.c_str(), file_size) != OFS::OFS_OK)
	{		
        // OGSCENE file name needs to match OFS container file name. If the later was renamed, we 
        // need to automatically adapt the OGSCENE file name now.
        OFS::FileList files = mFile->listFiles("/", OFS::OFS_FILE);
        unsigned int ogsceneFileExtensionLength = strlen(Globals::OGSCENE_FORMAT_EXTENSION.c_str());

		for(OFS::FileList::iterator iter = files.begin(); iter != files.end(); iter++)
		{
			// Filter out too short names
            if(iter->name.size() <= ogsceneFileExtensionLength) 
                continue;

			if(stricmp(iter->name.c_str() + (iter->name.size() - (ogsceneFileExtensionLength)), Globals::OGSCENE_FORMAT_EXTENSION.c_str()) == 0)
			{
				mFile->renameFile(iter->name.c_str(), fileName.c_str());
				break;
			}
		}

		if(mFile->getFileSize(fileName.c_str(), file_size) != OFS::OFS_OK)
			return SCF_ERRFILE;
	}

    char *file_data = new char[(unsigned int)file_size + 1];

    OFS::OFSHANDLE projHandle;

    if(mFile->openFile(projHandle, fileName.c_str(), OFS::OFS_READ) != OFS::OFS_OK)
    {
        delete [] file_data;
        return SCF_ERRFILE;
    }

    mFile->read(projHandle, file_data, file_size);
    mFile->closeFile(projHandle);

    TiXmlDocument docImport;

    if(!docImport.LoadFromMemory(file_data, file_size))
    {
        delete [] file_data;
        return SCF_ERRFILE;
    }

    delete [] file_data;

    loadmsg = mSystem->Translate("Parsing Scene File");
    mSystem->UpdateLoadProgress(1, loadmsg);

    TiXmlNode* ogitorSceneNode = 0;
    TiXmlNode* projectNode;
    TiXmlElement* element = 0;
    bool upgradeExecuted = false;
    ogitorSceneNode = docImport.FirstChild("OGITORSCENE");

    if(!ogitorSceneNode)
        return SCF_ERRPARSE;

    element = ogitorSceneNode->ToElement();

    // Old OGSCENE version check and attempt to fix/update
    int version = Ogre::StringConverter::parseInt(ValidAttr(element->Attribute("version"), "0"));    
    if(Ogre::StringConverter::toString(version) < Globals::OGSCENE_FORMAT_VERSION)
    {
        mSystem->DisplayMessageDialog(mSystem->Translate("Old OGSCENE file version detected. Ogitor will now attempt to upgrade the format and will also create a backup version of your OFS file."), DLGTYPE_OK);

        loadmsg = mSystem->Translate("Upgrading OGSCENE file.");
        mSystem->UpdateLoadProgress(10, loadmsg);

        if(version == 0)
        {
            mSystem->DisplayMessageDialog(mSystem->Translate("OGSCENE files contains no version number set and therefore cannot be loaded."), DLGTYPE_OK);
            return SCF_ERRPARSE;
        }
        else if(version == 1)
        {
            mSystem->DisplayMessageDialog(mSystem->Translate("OGSCENE files with version 1 cannot be upgraded automatically. Please contact the Ogitor team for further details."), DLGTYPE_OK);
            return SCF_ERRPARSE;
        }

        if(version > 1)
        {
            if((mFile->getFileSystemType() == OFS::OFS_PACKED) && (!mSystem->CopyFile(importfile, importfile + ".backup")))
                mSystem->DisplayMessageDialog(mSystem->Translate("Error while trying to create backup file."), DLGTYPE_OK);
        }
        switch(version)
        {
         case 2:
            _upgradeOgsceneFileFrom2To3(ogitorSceneNode);
            _upgradeOgsceneFileFrom3To4(ogitorSceneNode);
            break;
         case 3:
            _upgradeOgsceneFileFrom3To4(ogitorSceneNode);
            break;
        }

        upgradeExecuted = true;
    }  

    projectNode = ogitorSceneNode->FirstChild("PROJECT");

    if(projectNode)
    {
        loadmsg = mSystem->Translate("Parsing project options");
        mSystem->UpdateLoadProgress(5, loadmsg);
        ogRoot->LoadProjectOptions(projectNode->ToElement());
        ogRoot->PrepareProjectResources();
    }

    element = ogitorSceneNode->FirstChildElement();

    loadmsg = mSystem->Translate("Creating scene objects");
    mSystem->UpdateLoadProgress(10, loadmsg);

    unsigned int obj_count = 0;
    Ogre::String objecttype;
    OgitorsPropertyValueMap params;
    OgitorsPropertyValue tmpPropVal;
    Ogre::String objAttValue;
    Ogre::String elementName;
    TiXmlElement* properties = 0;
    Ogre::String attID;
    Ogre::String attValue;
    CBaseEditor* result = 0;
    TiXmlElement* customprop = 0;
    Ogre::StringVector invalidEditorTypes;

    do
    {
        // Make sure its NON-ZERO
        if(pOpt->ObjectCount)
        {
            ++obj_count;
            mSystem->UpdateLoadProgress(10 + ((obj_count * 70) / pOpt->ObjectCount), loadmsg);
        }

        params.clear();       

        objAttValue = ValidAttr(element->Attribute("object_id"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_UNSIGNED_INT;
            tmpPropVal.val = Ogre::Any(Ogre::StringConverter::parseUnsignedInt(objAttValue));
            params.insert(OgitorsPropertyValueMap::value_type("object_id", tmpPropVal));
        }

        objAttValue = ValidAttr(element->Attribute("parentnode"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("parentnode", tmpPropVal));
        }

        objAttValue = ValidAttr(element->Attribute("name"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("name", tmpPropVal));
        }
        else
            continue;

        objAttValue = ValidAttr(element->Attribute("typename"), "");
        if(objAttValue != "")
        {
            tmpPropVal.propType = PROP_STRING;
            tmpPropVal.val = Ogre::Any(objAttValue);
            params.insert(OgitorsPropertyValueMap::value_type("typename", tmpPropVal));
        }
        else
            continue;

        properties = element->FirstChildElement();
        if(properties)
        {            
            do
            {
                elementName = properties->Value();
                if(elementName != "PROPERTY")
                    continue;

                attID = ValidAttr(properties->Attribute("id"), "");
                int attType = Ogre::StringConverter::parseInt(ValidAttr(properties->Attribute("type"), ""));
                attValue = ValidAttr(properties->Attribute("value"), "");

                params.insert(OgitorsPropertyValueMap::value_type(attID, OgitorsPropertyValue::createFromString((OgitorsPropertyType)attType, attValue)));
            } while(properties = properties->NextSiblingElement());
        }

        objecttype = Ogre::any_cast<Ogre::String>(params["typename"].val);
        result = ogRoot->CreateEditorObject(0, objecttype, params, false, false);
        if(result)
        {
            customprop = element->FirstChildElement("CUSTOMPROPERTIES");
            if(customprop) 
            {
                OgitorsUtils::ReadCustomPropertySet(customprop, result->getCustomProperties());
            }
        }
        else
            invalidEditorTypes.push_back(objecttype);

    } while(element = element->NextSiblingElement());

    // Print out invalid/unsupported editor types (= types where no factory could be found)
    if(invalidEditorTypes.size() > 0)
    {
        std::sort(invalidEditorTypes.begin(), invalidEditorTypes.end());
        invalidEditorTypes.erase(std::unique(invalidEditorTypes.begin(), invalidEditorTypes.end()), invalidEditorTypes.end());
        Ogre::String invalidTypesResultString;
        for(unsigned int i = 0; i < invalidEditorTypes.size(); i++)
        {
            invalidTypesResultString += invalidEditorTypes.at(i) + "\n";
        }
        mSystem->DisplayMessageDialog(mSystem->Translate("Could not create objects of types:\n" + invalidTypesResultString), DLGTYPE_OK);
    }

    //// Save directly after upgrade
    //if(upgradeExecuted)
    //    Export(false, importfile);

    ogRoot->AfterLoadScene();

    return SCF_OK;
}
Пример #7
0
//------------------------------------------------------------------------------------
void ExtractThread::extractFiles(QString path, const OFS::FileList& list)
{
    std::ofstream out_handle;
    OFS::OFSHANDLE in_handle;

    unsigned int output_amount = 0;

    mutex.lock();
    currentPos = 0.0f; 
    msgProgress = "";
    mutex.unlock();

    for(unsigned int i = 0;i < list.size();i++)
    {
        if(list[i].flags & OFS::OFS_DIR)
        {
            QString dir_path = path + QString("/") + QString(list[i].name.c_str());
            QDir directory(dir_path);
            directory.mkpath(dir_path);
        }
        else
        {
            std::string file_path = path.toStdString() + std::string("/") + list[i].name;
            std::string file_ofs_path = list[i].name;

            QFileInfo info(QString(file_path.c_str()));
            QDir directory(info.absolutePath());
            directory.mkpath(info.absolutePath());

            mutex.lock();
            msgProgress = file_ofs_path.c_str();
            mutex.unlock();

            out_handle.open(file_path.c_str(), std::ofstream::out | std::ofstream::binary);

            if(out_handle.is_open())
            {
                try
                {
                    OFS::OfsResult ret = ofsFile->openFile(in_handle, file_ofs_path.c_str());
                    if(ret != OFS::OFS_OK)
                    {
                        out_handle.close();
                        continue;
                    }

                    unsigned int total = list[i].file_size;

                    while(total > 0)
                    {
                        if(total < MAX_BUFFER_SIZE)
                        {
                            ofsFile->read(in_handle, tmp_buffer, total);
                            out_handle.write(tmp_buffer, total);
                            output_amount += total;
                            total = 0;
                        }
                        else
                        {
                            ofsFile->read(in_handle, tmp_buffer, MAX_BUFFER_SIZE);
                            out_handle.write(tmp_buffer, MAX_BUFFER_SIZE);
                            total -= MAX_BUFFER_SIZE;
                            output_amount += MAX_BUFFER_SIZE;
                        }

                        if(mTotalFileSize > 0)
                        {
                            mutex.lock();
                            currentPos = (float)output_amount / (float)mTotalFileSize; 
                            mutex.unlock();
                        }
                    }
                }
                catch(OFS::Exception& e)
                {
                    QMessageBox::information(QApplication::activeWindow(),"Ofs Exception:", tr("Error Extracting File : ") + QString(file_ofs_path.c_str()) + QString("\n") + QString(e.getDescription().c_str()), QMessageBox::Ok);
                }

                out_handle.close();
                ofsFile->closeFile(in_handle);
            }
        }
    }

    mutex.lock();
    currentPos = 1.0f;
    msgProgress = tr("Finished Extracting");
    mutex.unlock();
}
Пример #8
0
//------------------------------------------------------------------------------------
void MainWindow::showFiles()
{
    while(mFileListWidget->rowCount() > 0)
        mFileListWidget->removeRow(0);
    
    mCurrentFiles.clear();

    QIcon folderIcon = mIconProvider.icon(QFileIconProvider::Folder);
    
    if(mOfsFile.valid())
    {
        OFS::FileList dirs = mOfsFile->listFiles(mCurrentDir.c_str(), OFS::OFS_DIR);
        OFS::FileList files = mOfsFile->listFiles(mCurrentDir.c_str(), OFS::OFS_FILE);

        std::sort(dirs.begin(), dirs.end(), OFS::FileEntry::Compare);
        std::sort(files.begin(), files.end(), OFS::FileEntry::Compare);

        int current_row = 0;
        if(mCurrentDir.size() > 1)
        {
            mFileListWidget->insertRow(current_row);
            mFileListWidget->setRowHeight(current_row, mRowHeight);
            QTableWidgetItem *witem = new QTableWidgetItem(folderIcon, QString(".."));
            mFileListWidget->setItem(0, 0, witem);

            witem = new QTableWidgetItem("");
            mFileListWidget->setItem(current_row, 1, witem);

            witem = new QTableWidgetItem(tr("Directory"));
            mFileListWidget->setItem(current_row, 2, witem);

            witem = new QTableWidgetItem("");
            mFileListWidget->setItem(current_row, 3, witem);

            witem = new QTableWidgetItem("");
            mFileListWidget->setItem(current_row, 4, witem);

            current_row++;

            OFS::FileEntry updata;
            updata.flags = OFS::OFS_DIR;
            updata.name = "..";
            updata.file_size = 0;

            mCurrentFiles.push_back(updata);
        }

        mDirUpButton->setEnabled(mCurrentDir.size() > 1);

        for(unsigned int i = 0;i < dirs.size();i++)
        {
            mFileListWidget->insertRow(current_row);
            mFileListWidget->setRowHeight(current_row, mRowHeight);

            bool isReadOnly = (dirs[i].flags & OFS::OFS_READONLY) > 0;
            bool isHidden = (dirs[i].flags & OFS::OFS_HIDDEN) > 0;

            if(isHidden && (actViewShowHidden->isChecked() == false))
                continue;

            QColor textColor = Qt::black;

            if(isReadOnly && isHidden)
                textColor = QColor(255, 210, 210);
            else if(isReadOnly)
                textColor = QColor(255, 0, 0);
            else if(isHidden)
                textColor = QColor(210, 210, 210);

            QTableWidgetItem *witem = new QTableWidgetItem(folderIcon, QString(dirs[i].name.c_str()));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 0, witem);

            witem = new QTableWidgetItem("");
            mFileListWidget->setItem(current_row, 1, witem);

            witem = new QTableWidgetItem(tr("Directory"));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 2, witem);

            witem = new QTableWidgetItem(QDateTime::fromTime_t(dirs[i].create_time).toString());
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 3, witem);

            witem = new QTableWidgetItem(QString("{ ") + QString(dirs[i].uuid.toString().c_str()) + QString(" }"));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 4, witem);

            current_row++;

            mCurrentFiles.push_back(dirs[i]);
        }

        for(unsigned int i = 0;i < files.size();i++)
        {
            mFileListWidget->insertRow(current_row);
            mFileListWidget->setRowHeight(current_row, mRowHeight);

            std::string ext_name = files[i].name;

            bool isReadOnly = (files[i].flags & OFS::OFS_READONLY) > 0;
            bool isHidden = (files[i].flags & OFS::OFS_HIDDEN) > 0;

            if(isHidden && (actViewShowHidden->isChecked() == false))
                continue;

            QColor textColor = Qt::black;

            if(isReadOnly && isHidden)
                textColor = QColor(255, 210, 210);
            else if(isReadOnly)
                textColor = QColor(255, 0, 0);
            else if(isHidden)
                textColor = QColor(210, 210, 210);

            QIcon icon = mUnknownFileIcon;
            int ext_pos = ext_name.find_last_of(".");

            if(ext_pos > 0)
            {
                ext_name.erase(0, ext_pos);
                FileIconMap::iterator it = mFileIconMap.find(ext_name);
                if(it == mFileIconMap.end())
                {
                    std::string filename = "./qtOfs_icontest";
                    filename += ext_name;

                    std::fstream stream;
                    stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc);
                    stream.close();

                    QFileInfo info(QString(filename.c_str()));
                    icon = mIconProvider.icon(info);
                    if(icon.isNull())
                        icon = mUnknownFileIcon;
                    
                    mFileIconMap.insert(FileIconMap::value_type(ext_name, icon));

                    QFile::remove(QString(filename.c_str()));
                }
                else
                    icon = it->second;
            }

            QTableWidgetItem *witem = new QTableWidgetItem(icon, QString(files[i].name.c_str()));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 0, witem);

            unsigned int file_size = files[i].file_size;
            
            QString size_str = QString("%1").arg(file_size);

            int len = size_str.length();
            int runs = (len - 1) / 3;

            for(int j = 0;j < runs;j++)
            {
                size_str.insert(len - (3 * j) - 3, '.');
            }

            witem = new QTableWidgetItem(size_str + QString(" "));
            witem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 1, witem);

            witem = new QTableWidgetItem(tr("File"));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 2, witem);

            witem = new QTableWidgetItem(QDateTime::fromTime_t(files[i].create_time).toString());
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 3, witem);

            witem = new QTableWidgetItem(QString("{ ") + QString(files[i].uuid.toString().c_str()) + QString(" }"));
            witem->setTextColor(textColor);
            mFileListWidget->setItem(current_row, 4, witem);

            ++current_row;

            mCurrentFiles.push_back(files[i]);
        }

        if(mCurrentDir.size() > 1)
            --current_row;

        mTotalEntriesLabel->setText(tr("Total Entries : ") + QString("%1").arg(current_row));
        mDirectoryDisplay->setText(QString(mCurrentDir.c_str()));
    }
}
Пример #9
0
//-----------------------------------------------------------------------------------------
bool CTerrainGroupEditor::load(bool async)
{
    if(mLoaded->get())
        return true;

    if(!getParent()->load())
        return false;

    Ogre::ResourceGroupManager *mngr = Ogre::ResourceGroupManager::getSingletonPtr();
    Ogre::String terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory;
    terrainDir = mOgitorsRoot->GetProjectFile()->getFileSystemName() + "::/" + terrainDir + "/";

    mngr->addResourceLocation(terrainDir + "textures/normalheight", "Ofs", "TerrainGroupNormalHeight");
    mngr->initialiseResourceGroup("TerrainGroupNormalHeight");

    mngr->addResourceLocation(terrainDir + "textures/diffusespecular", "Ofs", "TerrainGroupDiffuseSpecular");
    mngr->initialiseResourceGroup("TerrainGroupDiffuseSpecular");

    mngr->addResourceLocation(terrainDir + "plants", "Ofs", "TerrainGroupPlants");
    mngr->initialiseResourceGroup("TerrainGroupPlants");

    OgitorsRoot::getSingletonPtr()->PrepareTerrainResources();
    OgitorsRoot::getSingletonPtr()->ReloadUserResources();

    mDecalFrustum = OGRE_NEW Ogre::Frustum();
    mDecalNode = getSceneManager()->getRootSceneNode()->createChildSceneNode("OgitorTerrainDecalNode");
    mDecalNode->setPosition(99999, -99999, 99999);
    mDecalNode->attachObject(mDecalFrustum);
    mDecalFrustum->setProjectionType(Ogre::PT_ORTHOGRAPHIC);
    mDecalNode->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X));
    mDecalFrustum->setFOVy(Ogre::Degree(45));
    mDecalFrustum->setNearClipDistance(10);
    mDecalFrustum->setOrthoWindow(10, 10);
    mDecalFrustum->setVisible(false);
    mDecalTexture = Ogre::TextureManager::getSingletonPtr()->createManual("OgitorDecalTexture", "TerrainResources", 
        Ogre::TEX_TYPE_2D, 256, 256, 1, 1, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY, this);

    mBrushData = OGRE_ALLOC_T(float, BRUSH_DATA_SIZE * BRUSH_DATA_SIZE, Ogre::MEMCATEGORY_GEOMETRY);

    mTerrainGlobalOptions->setMaxPixelError(mMaxPixelError->get());
    mTerrainGlobalOptions->setCompositeMapSize(mCompositeMapTextureSize->get());
    mTerrainGlobalOptions->setCompositeMapDistance(mCompositeMapDistance->get());
    mTerrainGlobalOptions->setLightMapSize(mLightMapTextureSize->get());
    mTerrainGlobalOptions->setLayerBlendMapSize(mBlendMapTextureSize->get());
    mTerrainGlobalOptions->setUseVertexCompressionWhenAvailable(false);
    mTerrainGlobalOptions->setSkirtSize(mSkirtSize->get());
    mTerrainGlobalOptions->setUseRayBoxDistanceCalculation(mUseRayBoxDistanceCalculation->get());

    if(mMaterialGeneratorType->get() == 1)
    {
        Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorC(this, mDecalFrustum));
        mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr);
        mMaxLayersAllowed = 10;
    }
    else
    {
        Ogre::TerrainMaterialGeneratorPtr matGenPtr(OGRE_NEW Ogre::TerrainMaterialGeneratorB(this, mDecalFrustum));
        mTerrainGlobalOptions->setDefaultMaterialGenerator(matGenPtr);
        mMaxLayersAllowed = 6;
    }

    CSceneManagerEditor *mSceneMgr = static_cast<CSceneManagerEditor*>(mOgitorsRoot->GetSceneManagerEditor());

    if(mSceneMgr->getShadowsEnabled())
    {
        if(mMaterialGeneratorType->get() == 1)
        {
            Ogre::TerrainMaterialGeneratorC::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorC::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile());
            matProfile->setReceiveDynamicShadowsEnabled(true);
            matProfile->setReceiveDynamicShadowsLowLod(false);
            matProfile->setReceiveDynamicShadowsDepth(true);
            matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get()));
        }
        else
        {
            Ogre::TerrainMaterialGeneratorB::SM2Profile* matProfile = static_cast<Ogre::TerrainMaterialGeneratorB::SM2Profile*>(mTerrainGlobalOptions->getDefaultMaterialGenerator()->getActiveProfile());
            matProfile->setReceiveDynamicShadowsEnabled(true);
            matProfile->setReceiveDynamicShadowsLowLod(false);
            matProfile->setReceiveDynamicShadowsDepth(true);
            matProfile->setReceiveDynamicShadowsPSSM(static_cast<Ogre::PSSMShadowCameraSetup*>(mSceneMgr->getPSSMSetup().get()));
        }
    }

    CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::enabled", CTerrainGroupEditor, onShadowsChange, mShadowsConnection[0]);
    CONNECT_PROPERTY_MEMFN(mSceneMgr, "shadows::technique", CTerrainGroupEditor, onShadowsTechniqueChange, mShadowsConnection[1]);

    mHandle = OGRE_NEW Ogre::TerrainGroup(mOgitorsRoot->GetSceneManager(), Ogre::Terrain::ALIGN_X_Z, mMapSize->get(), mWorldSize->get());
    mHandle->setOrigin(Ogre::Vector3::ZERO);
    mHandle->setResourceGroup("TerrainResources");
    mHandle->setFilenameConvention(mPageNamePrefix->get(), "ogt");
    StaticGroupPtr = mHandle;

    mPGHandle = new PagedGeometry(mOgitorsRoot->GetViewport()->getCameraEditor()->getCamera(), mPGPageSize->get());
    mPGHandle->addDetailLevel<GrassPage>(mPGDetailDistance->get());

    //Create a GrassLoader object
    mGrassLoaderHandle = new GrassLoader(mPGHandle);
    mGrassLoaderHandle->setVisibilityFlags(1 << mLayer->get());

    //Assign the "grassLoader" to be used to load geometry for the PagedGrass instance
    mPGHandle->setPageLoader(mGrassLoaderHandle);

    //Supply a height function to GrassLoader so it can calculate grass Y values
    mGrassLoaderHandle->setHeightFunction(OgitorTerrainGroupHeightFunction);

    Ogre::Vector3 vDir;
    Ogre::ColourValue cDiffuse;
    Ogre::SceneManager::MovableObjectIterator mit = mOgitorsRoot->GetSceneManager()->getMovableObjectIterator("Light");
    while(mit.hasMoreElements())
    {
        Ogre::Light *l = static_cast<Ogre::Light*>(mit.getNext());
        if(l->getType() == Ogre::Light::LT_DIRECTIONAL && l->getCastShadows())
        {
            vDir = l->getDerivedDirection();
            cDiffuse = l->getDiffuseColour();
            break;
        }
    }

    mTerrainGlobalOptions->setLightMapDirection(vDir);
    mTerrainGlobalOptions->setCompositeMapAmbient(mOgitorsRoot->GetSceneManager()->getAmbientLight());
    mTerrainGlobalOptions->setCompositeMapDiffuse(cDiffuse);

    terrainDir = OgitorsRoot::getSingletonPtr()->GetProjectOptions()->TerrainDirectory + "/terrain/";

    OFS::FileList TGAList = mOgitorsRoot->GetProjectFile()->listFiles(terrainDir.c_str(), OFS::OFS_FILE);

    for(unsigned int t = 0; t < TGAList.size(); t++)
    {
        int pos = TGAList[t].name.find("_density.tga");
        if(pos > 0)
        {
            Ogre::Image _img;
            Ogre::String sLoc = terrainDir + TGAList[t].name;

            // Block to ensure streams are freed when exiting the block
            {
                OFS::OFSHANDLE *iHandle = new OFS::OFSHANDLE();
                mOgitorsRoot->GetProjectFile()->openFile( *iHandle, sLoc.c_str() );
                Ogre::DataStreamPtr img_stream = Ogre::DataStreamPtr(OGRE_NEW OfsDataStream(mOgitorsRoot->GetProjectFile(), iHandle));
                _img.load(img_stream);
            }

            Ogre::String nLoc = terrainDir + TGAList[t].name.substr(0, pos);
            nLoc += "_density.png";

            OgitorsUtils::SaveImageOfs( _img, nLoc );
            mOgitorsRoot->GetProjectFile()->deleteFile( sLoc.c_str() );
        }
    }

    registerForUpdates();

    mLoaded->set(true);
    return true;
}
Пример #10
0
//----------------------------------------------------------------------------------------
void OfsTreeWidget::fillRecycleBin(QTreeWidgetItem *pItem)
{
    OFS::FileList list = mFile->listRecycleBinFiles();

    if( list.size() > 0 )
        pItem->setIcon(0, QIcon(":/icons/recyclebin_full.svg"));
    else
        pItem->setIcon(0, QIcon(":/icons/recyclebin_empty.svg"));

    std::sort(list.begin(), list.end(), OFS::FileEntry::Compare);

    for(unsigned int i = 0;i < list.size();i++)
    {
        Ogre::String name = list[i].name;
        Ogre::String ext_name = name;

        QIcon icon = mUnknownFileIcon;

        if( list[i].flags & OFS::OFS_DIR )
            icon = mOgitorMainWindow->mIconProvider.icon(QFileIconProvider::Folder);
        else
        {
            int ext_pos = ext_name.find_last_of(".");

            if(ext_pos > 0)
            {
                ext_name.erase(0, ext_pos);
            
                FileIconMap::iterator it = mOgitorMainWindow->mFileIconMap.find(ext_name);
                if(it == mOgitorMainWindow->mFileIconMap.end())
                {
                    std::string filename = "./qtOgitor_icontest";
                    filename += ext_name;

                    std::fstream stream;
                    stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc);
                    stream.close();

                    QFileInfo info(QString(filename.c_str()));
                    icon = mOgitorMainWindow->mIconProvider.icon(info);
                    if(icon.isNull())
                        icon = mUnknownFileIcon;
                    
                    mOgitorMainWindow->mFileIconMap.insert(FileIconMap::value_type(ext_name, icon));

                    QFile::remove(QString(filename.c_str()));
                }
                else
                    icon = it->second;
            }
        }

        QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
        item->setIcon(0, icon);
        item->setTextColor(0, Qt::black);
        item->setWhatsThis(0, QString("%1").arg(list[i].id));
        item->setToolTip(0, QString(name.c_str()) + QString(" (%1)").arg(list[i].id));

        pItem->addChild(item);
    }
}
Пример #11
0
//----------------------------------------------------------------------------------------
void OfsTreeWidget::fillTreeFiles(QTreeWidgetItem *pItem, std::string path)
{
    OFS::FileList list = mFile->listFiles(path.c_str(), OFS::OFS_FILE);

    std::sort(list.begin(), list.end(), OFS::FileEntry::Compare);

    for(unsigned int i = 0;i < list.size();i++)
    {
        Ogre::String name = list[i].name;
        Ogre::String ext_name = name;

        QIcon icon = mUnknownFileIcon;
        int ext_pos = ext_name.find_last_of(".");

        if(ext_pos > 0)
        {
            ext_name.erase(0, ext_pos);
            
            FileIconMap::iterator it = mOgitorMainWindow->mFileIconMap.find(ext_name);
            if(it == mOgitorMainWindow->mFileIconMap.end())
            {
                std::string filename = "./qtOgitor_icontest";
                filename += ext_name;

                std::fstream stream;
                stream.open(filename.c_str(), std::fstream::in | std::fstream::out | std::fstream::binary | std::fstream::trunc);
                stream.close();

                QFileInfo info(QString(filename.c_str()));
                icon = mOgitorMainWindow->mIconProvider.icon(info);
                if(icon.isNull())
                    icon = mUnknownFileIcon;
                    
                mOgitorMainWindow->mFileIconMap.insert(FileIconMap::value_type(ext_name, icon));

                QFile::remove(QString(filename.c_str()));
            }
            else
                icon = it->second;
        }

        QTreeWidgetItem* item = new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString(name.c_str())));
        item->setIcon(0, icon);
        item->setTextColor(0, Qt::black);

        std::string fullpath = path + name;
        item->setWhatsThis(0, QString(fullpath.c_str()));

        if(mCapabilities & CAP_SHOW_COLORS)
        {
            bool isReadOnly = (list[i].flags & OFS::OFS_READONLY) > 0;
            bool isHidden = (list[i].flags & OFS::OFS_HIDDEN) > 0;

            QColor textColor = Qt::black;

            if(isReadOnly && isHidden)
                textColor = QColor(255, 210, 210);
            else if(isReadOnly)
                textColor = QColor(255, 0, 0);
            else if(isHidden)
                textColor = QColor(210, 210, 210);

            if(list[i].flags & OFS::OFS_LINK)
                textColor.setBlue(255); 

            item->setTextColor(0, textColor);
        }

        pItem->addChild(item);

        mItemMap.insert(NameTreeWidgetMap::value_type(fullpath, item));
    }
}