#include "StdAfx.h"
#include "moduleLogic.h"
#include "moduleLogicCmd.h"
#ifndef MAC_PLUGIN
#define MAXPATHLEN 1024
#endif
#define LINE (MAXPATHLEN * 3)
#define KEYWORD_MAYAVERSION _T("MAYAVERSION")
#define KEYWORD_PLATFORM _T("PLATFORM")
#define KEYWORD_LOCALE _T("LOCALE")
#define KEYWORD_SEPARATOR _T(":")
void MModuleLogic::ModuleDetectionLogicInit (threadData *data) {
data->szVersion =data->szVersion.substringW (0, 3) ;
for ( unsigned int i =0 ; i < data->szModules.length () ; i++ ) {
MString cmd, modName =data->szModules [i] ;
cmd.
format (_T(
"moduleInfo -d -mn \"^1s\";"), modName) ;
if ( ext != _T("xml") )
continue ;
MModuleLogic::InitNewModules (data, modName, modFile) ;
}
}
void MModuleLogic::InitNewModules (threadData *data,
MString &modName,
MString &packageFile) {
MModuleLogic::executePackageContents (data, packageFile) ;
}
void MModuleLogic::ModuleDetectionLogicCmdExecute (threadData *data) {
if ( threadData::bWaitingForCommand == false ) {
threadData::bWaitingForCommand =true ;
}
}
void MModuleLogic::ModuleDetectionLogic (threadData *data, bool bInitNow ) {
for (
unsigned int i =0 ; i < newModules.
length () ; i++ ) {
if ( ext == _T("xml") && !MModuleLogic::isPackageReady (data, modFile) )
continue ;
cmd.
format (_T(
"loadModule -load \"^1s\";"), modFile) ;
data->szModules.append (newModulesName [0]) ;
if ( ext != _T("xml") )
continue ;
MModuleLogic::InitNewModules (data, newModulesName [0], modFile) ;
}
threadData::bWaitingForCommand =false ;
}
bool MModuleLogic::isPackageReady (threadData *data,
MString &modFile) {
xmlDocPtr doc =xmlParseFile (modFile.
asChar ()) ;
if ( doc == NULL )
return (false) ;
xmlXPathContextPtr context =xmlXPathNewContext (doc) ;
mxpath.
format (_T(
"//Components/RuntimeRequirements[(not(@OS) or contains(@OS, '^1s')) and (not(@Platform) or contains(@Platform, 'Maya'))]"), data->szPlatform) ;
xmlChar *xpath =(xmlChar *)mxpath.
asChar () ;
xmlXPathObjectPtr result =xmlXPathEvalExpression (xpath, context) ;
bool bOk =true ;
if ( result != NULL && !xmlXPathNodeSetIsEmpty (result->nodesetval) ) {
for ( int j =0 ; j < result->nodesetval->nodeNr && bOk ; j++ ) {
xmlNodePtr reqNode =result->nodesetval->nodeTab [j] ;
context->node =reqNode->parent ;
xmlChar *xpathComp =(xmlChar *)"./ComponentEntry" ;
xmlXPathObjectPtr resultEntries =xmlXPathEvalExpression (xpathComp, context) ;
if ( resultEntries != NULL && !xmlXPathNodeSetIsEmpty (resultEntries->nodesetval) ) {
for ( int k =0 ; k < resultEntries->nodesetval->nodeNr && bOk ; k++ ) {
xmlNodePtr compNode =resultEntries->nodesetval->nodeTab [k] ;
xmlChar *compName =xmlGetProp (compNode, (xmlChar *)"ModuleName") ;
bOk =false ;
if ( compName != NULL )
{
xmlFree (compName) ;
}
}
}
if ( resultEntries != NULL )
{
xmlXPathFreeObject (resultEntries) ;
}
}
}
if ( result != NULL )
{
xmlXPathFreeObject (result) ;
}
if ( context != NULL )
{
xmlXPathFreeContext (context) ;
}
xmlFreeDoc (doc) ;
return (bOk) ;
}
bool MModuleLogic::executePackageContents (threadData *data,
MString &modFile) {
xmlDocPtr doc =xmlParseFile (modFile.
asChar ()) ;
if ( doc == NULL )
return (false) ;
xmlXPathContextPtr context =xmlXPathNewContext (doc) ;
mxpath.
format (_T(
"//Components/RuntimeRequirements[(not(@OS) or contains(@OS, '^1s')) and (not(@Platform) or contains(@Platform, 'Maya'))]"), data->szPlatform) ;
xmlChar *xpath =(xmlChar *)mxpath.
asChar () ;
xmlXPathObjectPtr result =xmlXPathEvalExpression (xpath, context) ;
if ( result != NULL && !xmlXPathNodeSetIsEmpty (result->nodesetval) ) {
for ( int j =0 ; j < result->nodesetval->nodeNr ; j++ ) {
xmlNodePtr reqNode =result->nodesetval->nodeTab [j] ;
context->node =reqNode->parent ;
MModuleLogic::executeComponentEntry (data, context) ;
}
}
if ( result != NULL )
{
xmlXPathFreeObject (result) ;
}
if ( context != NULL )
{
xmlXPathFreeContext (context) ;
}
xmlFreeDoc (doc) ;
return (true) ;
}
bool MModuleLogic::executeComponentEntry (threadData *data, xmlXPathContextPtr &context) {
xmlChar *xpath =(xmlChar *)"./ComponentEntry" ;
xmlXPathObjectPtr result =xmlXPathEvalExpression (xpath, context) ;
if ( result != NULL && !xmlXPathNodeSetIsEmpty (result->nodesetval) ) {
for ( int j =0 ; j < result->nodesetval->nodeNr ; j++ ) {
xmlNodePtr compNode =result->nodesetval->nodeTab [j] ;
xmlChar *compName =xmlGetProp (compNode, (xmlChar *)"ModuleName") ;
xmlChar *autoload =xmlGetProp (compNode, (xmlChar *)"AutoLoad") ;
xmlChar *cmdInvoke =xmlGetProp (compNode, (xmlChar *)"LoadOnCommandInvocation") ;
if ( autoload != NULL && xmlStrcasecmp (autoload, (xmlChar *)"true") == 0 ) {
cmd.
format (_T(
"if ( !`pluginInfo -query -loaded \"^1s\"` ) loadPlugin -quiet \"^1s\";"), fobj.
resolvedName ()) ;
cmd.
format (_T(
"pluginInfo -edit -autoload true \"^1s\";"), st) ;
} else if ( cmdInvoke != NULL && xmlStrcasecmp (cmdInvoke, (xmlChar *)"true") == 0 ) {
}
if ( cmdInvoke != NULL )
{
xmlFree (cmdInvoke) ;
}
if ( autoload != NULL )
{
xmlFree (autoload) ;
}
if ( compName != NULL )
{
xmlFree (compName) ;
}
}
}
if ( result != NULL )
{
xmlXPathFreeObject (result) ;
}
return (true) ;
}