Example #1
0
void ProjectManager::saveProject() const
{
    
    auto defManager = contextManager_->queryInterface<IDefinitionManager>();
    auto fileSystem = contextManager_->queryInterface<IFileSystem>();
    auto uiFramework = contextManager_->queryInterface<IUIFramework>();
    if (uiFramework && defManager && fileSystem)
    {
        std::string projectFile = genProjectFileName( curProject_->getProjectName() );
        std::string projectDataFile = genProjectDataFileName( curProject_->getProjectName() );
        std::string projectSettingFile = genProjectSettingFileName( curProject_->getProjectName() );

        //save project data
        curProject_->saveData( projectDataFile.c_str() );

        //save project itself
        ResizingMemoryStream stream;
        XMLSerializer serializer( stream, *defManager );
        serializer.serialize( curProject_->getProjectName() );
        serializer.serialize( projectDataFile );
        serializer.sync();
        fileSystem->writeFile( 
            projectFile.c_str(), stream.buffer().c_str(), stream.buffer().size(), std::ios::out | std::ios::binary );
    }
    else
    {
        assert( false );
    }
    
}
Example #2
0
bool VariantStreamHandler::write(const Variant& v, const NodePtr& node, bool writeType)
{
	// Variant only accepts binary/text streams for streamin/out, so we get to do this fun little stream dance.
	ResizingMemoryStream s;
	TextStream ts(s);
	ts << v;

	// Get the type to be used - leave it null if we shouldn't write the type, setValueRawData won't write a type
	const char* nodeTypeName = nullptr;
	size_t nodeTypeSize = 0;
	if (writeType)
	{
		nodeTypeName = variantName_;
		nodeTypeSize = strlen(nodeTypeName);
	}

	// ResizingMemoryStream is not guaranteed to be null terminated.
	node->setValueRawData(s.buffer().c_str(), s.buffer().size(), nodeTypeName, nodeTypeSize);
	node->setHandlerName(handlerName_);

	auto variantTypeName = this->getReservedNames().variantInternalType;
	auto typeNode = node->createEmptyChild(variantTypeName, strlen(variantTypeName));
	const char* internalTypeName = v.type()->typeId().getName();
	typeNode->setValueString(internalTypeName, strlen(internalTypeName));

	return true;
}
Example #3
0
void Project::saveData( const char * dataFile ) const
{
    auto defManager = contextManager_.queryInterface<IDefinitionManager>();
    auto fileSystem = contextManager_.queryInterface<IFileSystem>();
    auto cmdManager = contextManager_.queryInterface<ICommandManager>();
    assert( defManager && fileSystem && cmdManager );
    ResizingMemoryStream stream;
    XMLSerializer serializer( stream, *defManager );
    defManager->serializeDefinitions( serializer );
    serializer.serialize( projectData_ );
    serializer.sync();
    fileSystem->writeFile( 
        dataFile, stream.buffer().c_str(), 
        stream.buffer().size(), std::ios::out | std::ios::binary );

    auto em = contextManager_.queryInterface<IEnvManager>();
    em->saveEnvState( envId_ );
}