#include "importMetadataCmd.h"
#include "metadataPluginStrings.h"
#include <maya/MObject.h>
#include <maya/MSyntax.h>
#include <maya/MStatus.h>
#include <maya/MString.h>
#include <maya/MStringResource.h>
#include <maya/MArgDatabase.h>
#include <maya/MFileObject.h>
#include <maya/adskDataStream.h>
#include <maya/adskDataChannel.h>
#include <maya/adskDataAssociations.h>
#include <maya/adskDataAssociationsSerializer.h>
#include <maya/adskDataChannelSerializer.h>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string>
static const char* flagString ( "-s" );
static const char* flagStringLong ( "-string" );
void* importMetadataCmd::creator()
{
return new importMetadataCmd;
}
const char* importMetadataCmd::name()
{
return "importMetadata";
}
MSyntax importMetadataCmd::cmdSyntax()
{
MSyntax syntax = metadataBase::cmdSyntax();
return syntax;
}
importMetadataCmd::importMetadataCmd()
{
}
importMetadataCmd::~importMetadataCmd()
{
}
bool
importMetadataCmd::isUndoable() const
{
return fMode == kCreate;
}
{
MStatus status = metadataBase::checkArgs( argsDb );
if( status != MS::kSuccess ) return status;
fStringFlag.parse(argsDb, flagString);
if( fStringFlag.isSet() )
{
if( fFile )
{
msg.
format( fmt, flagString );
displayWarning( msg );
}
if( !fStringFlag.isModeValid(fMode) )
{
msg.
format( fmt, flagString );
displayError(msg);
return MS::kFailure;
}
if( ! fStringFlag.isArgValid() )
{
displayError( errMsg );
return MS::kFailure;
}
fString = fStringFlag.arg();
}
else if( ! fFile )
{
msg.
format( fmt, flagString );
displayError( msg );
return MS::kFailure;
}
else if( ! fFile->exists() )
{
displayError(msg);
status = MS::kNotFound;
}
return status;
}
MStatus importMetadataCmd::doCreate()
{
assert( fSerializer );
std::string errors;
if( fString.length() > 0 )
{
std::stringstream inStream( fString.asChar() );
associationsRead = fSerializer->read( inStream, errors );
if( ! associationsRead )
{
displayError(msg);
return MS::kFailure;
}
}
else if( fFile )
{
std::ifstream inStream( fFile->resolvedFullName().asChar() );
associationsRead = fSerializer->read( inStream, errors );
inStream.close();
if( ! associationsRead )
{
msg.
format( fmt, fFile->resolvedFullName(), err );
displayError(msg);
return MS::kFailure;
}
}
else
{
assert( fFile );
return MS::kFailure;
}
assert( associationsRead );
for( unsigned int i=0; i<fObjects.length(); ++i )
{
if( MS::kSuccess != status ) continue;
displayInfo( node.name(&status) );
fDGModifier.setMetadata( fObjects[i], *associationsRead );
if( MS::kSuccess == fDGModifier.doIt() )
{
for( unsigned int c=0; c<associationsRead->channelCount(); ++c )
{
{
if( cStream )
{
msg.
format( resultFmt, node.name(), cName, sName );
appendToResult( msg );
}
}
}
}
else
{
msg.
format( fmt, node.name() );
displayError( msg );
status = MS::kFailure;
}
}
return status;
}
MStatus importMetadataCmd::redoIt()
{
return fDGModifier.doIt();
}
MStatus importMetadataCmd::undoIt()
{
return fDGModifier.undoIt();
}