plString plComponentBase::IGetUniqueName(plMaxNodeBase* target)
{
    // Make sure we've actually got multiple *used* targets.  (Some could be nil)
    int numUsedTargs = 0;
    int thisTargIdx = -1;
    for (int i = 0; i < fTargsPB->Count(kTargs); i++)
    {
        plMaxNodeBase* thisTarg = (plMaxNodeBase*)fTargsPB->GetINode(kTargs, 0, i);

        if (thisTarg)
            numUsedTargs++;

        if (thisTarg == target)
            thisTargIdx = i;

        // If we've figured out whether or not we have multiple targets, and we
        // found which target this one is, we can break out early
        if (numUsedTargs > 1 && thisTargIdx != -1)
            break;
    }

    hsAssert(thisTargIdx != -1, "Bad target for IGetUniqueName");

    if (numUsedTargs > 1)
        return plFormat("{}_{}", GetINode()->GetName(), thisTargIdx);
    else
        return plString::FromUtf8(GetINode()->GetName());
}
void plResponderComponent::ISetupDefaultWait(plMaxNode* node, plErrorMsg* pErrMsg,
                                             int state, CmdIdxs& cmdIdxs, int &numCallbacks)
{
    IParamBlock2 *statePB = (IParamBlock2*)fCompPB->GetReferenceTarget(kResponderState, 0, state);
    plResponderModifier *responder = IGetResponderMod(node);
    hsTArray<plResponderModifier::plResponderCmd>& cmds = responder->fStates[state].fCmds;

    int numCmds = cmds.Count();
    for (int i = 0; i < numCmds; i++)
    {
        IParamBlock2 *waitPB = GetWaitBlk(statePB, i);
        ResponderWait::FixupWaitBlock(waitPB);

        // If we're supposed to wait for this command, and it converted, create a callback
        if (ResponderWait::GetWaitOnMe(waitPB) && cmdIdxs.find(i) != cmdIdxs.end())
        {
            int convertedIdx = cmdIdxs[i];

            ResponderWaitInfo waitInfo;
            waitInfo.responderName = plString::FromUtf8(GetINode()->GetName());
            waitInfo.receiver = responder->GetKey();
            waitInfo.callbackUser = numCallbacks++;
            waitInfo.msg = cmds[convertedIdx].fMsg;
            waitInfo.point = plString::Null;

            IParamBlock2 *pb = (IParamBlock2*)statePB->GetReferenceTarget(kStateCmdParams, 0, i);
            plResponderCmd *cmd = plResponderCmd::Find(pb);

            cmd->CreateWait(node, pErrMsg, pb, waitInfo);
        }
    }
}
Exemple #3
0
static int GetINodeFromPath(const char *pFilename, iNodeEntry **pOutInode) {
  if (strcmp(pFilename, "/") == 0) {
    if (GetINode(ROOT_INODE, pOutInode) != 0)
      return -1;
    return ROOT_INODE;
  }
  return GetINodeFromPathAux(pFilename + 1, ROOT_INODE, pOutInode);
}
void plResponderComponent::IConvertCmds(plMaxNode* node, plErrorMsg* pErrMsg, int state, CmdIdxs& cmdIdxs)
{
    IParamBlock2 *statePB = (IParamBlock2*)fCompPB->GetReferenceTarget(kResponderState, 0, state);
    plResponderModifier *responder = IGetResponderMod(node);

    // Add the messages to the logic modifier
    for (int i = 0; i < statePB->Count(kStateCmdParams); i++)
    {
        plMessage *msg = nil;

        BOOL enabled = statePB->GetInt(kStateCmdEnabled, 0, i);
        if (!enabled)
            continue;

        IParamBlock2 *cmdPB = (IParamBlock2*)statePB->GetReferenceTarget(kStateCmdParams, 0, i);

        try
        {
            plResponderCmd *cmd = plResponderCmd::Find(cmdPB);
            if (cmd)
                msg = cmd->CreateMsg(node, pErrMsg, cmdPB);
        }
        catch (char *reason)
        {
            char buf[512];

            char stateName[128];
            const char *curStateName = fCompPB->GetStr(kResponderStateName, 0, state);
            if (curStateName && *curStateName != '\0')
                strcpy(stateName, fCompPB->GetStr(kResponderStateName, 0, state));
            else
                sprintf(stateName, "State %d", state+1);

            sprintf(buf,
                "A responder command failed to export.\n\nResponder:\t%s\nState:\t\t%s\nCommand:\t%d\n\nReason: %s",
                GetINode()->GetName(), stateName, i+1, reason);

            pErrMsg->Set(true, "Responder Warning", buf).Show();
            pErrMsg->Set(false);
        }

        if (msg)
        {
            msg->SetSender(responder->GetKey());
            responder->AddCommand(msg, state);
            int idx = responder->fStates[state].fCmds.Count()-1;
            cmdIdxs[i] = idx;
        }
    }
}
Exemple #5
0
static int GetINodeFromPathAux(const char *pFilename, const ino inode, iNodeEntry **pOutInode) {

  iNodeEntry *pInode = alloca(sizeof(*pInode));
  if (GetINode(inode, &pInode) != 0)
    return -1;

  char dirEntryBlock[BLOCK_SIZE];
  if (ReadBlock(pInode->Block[0], dirEntryBlock) == -1)
    return -1;

  DirEntry *pDirEntry = (DirEntry*)dirEntryBlock;
  if (pDirEntry == NULL)
    return -1;

  char *pos = strchr(pFilename, '/');
  char path[FILENAME_SIZE];
  if (pos != NULL) {
    strncpy(path, pFilename, (pos - pFilename));
    path[(pos - pFilename)] = 0;
  } else {
    strcpy(path, pFilename);
  }

  const size_t nDir = NumberofDirEntry(pInode->iNodeStat.st_size);
  size_t i = 0;
  for (; i < nDir; ++i) {
    if (strcmp(pDirEntry[i].Filename, path) == 0) {
      if (GetINode(pDirEntry[i].iNode, pOutInode) != 0)
        return -1;
      if (pos != NULL && strcmp(pos, "/") && ((*pOutInode)->iNodeStat.st_mode & G_IFDIR)) {
        return GetINodeFromPathAux(pos + 1, pDirEntry[i].iNode, pOutInode);
      }
      return pDirEntry[i].iNode;
    }
  }
  return -1;
}
Exemple #6
0
static int GetFreeINode(iNodeEntry **pOutInode) {
  const int inode = GetFreeRessource(FREE_INODE_BITMAP);
  if (inode != -1) {
    if (GetINode(inode, pOutInode) != -1)
    {
      CleanINode(pOutInode);
      (*pOutInode)->iNodeStat.st_ino = inode;
      if (WriteINodeToDisk(*pOutInode) == -1)
        return -1;
      printf("GLOFS: Saisie i-node %d\n", (*pOutInode)->iNodeStat.st_ino);
      return (*pOutInode)->iNodeStat.st_ino;
    }
  }
  return -1;
}
bool plInventoryObjComponent::PreConvert(plMaxNode *node, plErrorMsg *pErrMsg)
{
    plLocation loc = node->GetLocation();
    plSceneObject *obj = node->GetSceneObject();

    // Create and register the ClickDrag's logic component
    plLogicModifier *logic = new plLogicModifier;
    plString tmpName = plFormat("{}_{}_LogicModifier", obj->GetKeyName(), GetINode()->GetName());
    plKey logicKey = hsgResMgr::ResMgr()->NewKey(tmpName, logic, node->GetLocation());
    hsgResMgr::ResMgr()->AddViaNotify(logicKey, new plObjRefMsg(obj->GetKey(), plRefMsg::kOnCreate, -1, plObjRefMsg::kModifier), plRefFlags::kActiveRef);

    fLogicModKeys[node] = logicKey;



return true;
}
Exemple #8
0
//===============================================
// Create the directory "path"
// Returns 0 on success or a negative error code
//===============================================
long CreateDir(char *name)
{
	char *parentDirectory, *fileName;
	u_int32_t parentINodeNo, group;
	struct ext2_dir_entry_2 *newEntry;
	struct ext2_inode parentINode;
	struct FCB *fcb = CreateFileWithType(name, EXT2_FT_DIR);

	if (!fcb)
		return -ENOENT;

	// Get inode number of parent directory
	parentDirectory = AllocUMem((size_t)strlen(name) + 1);
	strcpy(parentDirectory, name);
	fileName = strrchr(parentDirectory, '/');
	fileName[0] = 0;
	parentINodeNo = GetFileINode(parentDirectory);
	DeallocMem(parentDirectory);

	newEntry = AllocUMem(sizeof(struct ext2_dir_entry_2));
	memset(newEntry, 0, sizeof(struct ext2_dir_entry_2));
	newEntry->file_type = EXT2_FT_DIR;
	newEntry->inode = fcb->inodeNumber;
	fcb->inode->i_links_count++;
	newEntry->name_len = 1;
	newEntry->rec_len = 12;
	newEntry->name[0] = '.';
	(void)WriteFile(fcb, (char *) newEntry, 12);
	newEntry->inode = parentINodeNo;

	GetINode(parentINodeNo, &parentINode);
	parentINode.i_links_count++;
	PutINode(parentINodeNo, &parentINode);
	newEntry->name_len = 2;
	newEntry->rec_len = 0x3F4;
	newEntry->name[1] = '.';
	(void)WriteFile(fcb, (char *) newEntry, 12);
	group = fcb->inodeNumber / sb.s_inodes_per_group;
	group_descriptors[group].bg_used_dirs_count++;
	fcb->inode->i_mode = (u_int16_t)(EXT2_S_IFDIR | EXT2_S_IRUSR | EXT2_S_IWUSR
			| EXT2_S_IXUSR | EXT2_S_IRGRP | EXT2_S_IXGRP | EXT2_S_IROTH
			| EXT2_S_IXOTH);
	fcb->inode->i_size = (u_int32_t)block_size;
	(void)CloseFile(fcb);
	return 0;
}
Exemple #9
0
//==============================================
// Open the file "path" and assign an FCB to it
//==============================================
struct FCB *OpenFileByInodeNumber(u_int32_t inode)
{
	struct FCB *fcb = AllocKMem(sizeof(struct FCB));
	fcb->inode = AllocKMem(sizeof(struct ext2_inode));
	fcb->inodeNumber = inode;
	GetINode(inode, fcb->inode);
	fcb->nextFCB = 0;
	fcb->fileCursor = 0;
	fcb->bufCursor = 0;
	fcb->buffer = AllocKMem((size_t)block_size);
	fcb->bufferIsDirty = 0;
	fcb->inodeIsDirty = 0;
	fcb->index1 = fcb->index2 = fcb->index3 = fcb->index4 = 0;
	fcb->currentBlock = fcb->inode->i_block[0];
	ReadBlock(fcb->currentBlock, fcb->buffer);
	return fcb;
}
Exemple #10
0
bool plMtlEventComponent::SetupProperties(plMaxNode* node, plErrorMsg* pErrMsg)
{
    Mtl* mtl = fCompPB->GetMtl(kMtlMtl);

    if (!mtl)
    {
        pErrMsg->Set(true,
                    "Mtl Event Component",
                    "Component %s does not have a valid material selected.\n"
                    "It will not be exported.",
                    GetINode()->GetName()).Show();
        pErrMsg->Set(false);
        fCanExport = false;
    }
    else
        fCanExport = true;

    return plActivatorBaseComponent::SetupProperties(node, pErrMsg);
}
Exemple #11
0
bool plAnimEventComponent::SetupProperties(plMaxNode* node, plErrorMsg* pErrMsg)
{
    plComponentBase* animComp;
    plMaxNode* animNode;
    if (!gAnimEventProc.GetCompAndNode(fCompPB, animComp, animNode))
    {
        pErrMsg->Set(true,
                    "Anim Event Component",
                    "Component %s does not have a valid anim component and node selected.\n"
                    "It will not be exported.",
                    GetINode()->GetName()).Show();
        pErrMsg->Set(false);
        fCanExport = false;
    }
    else
        fCanExport = true;

    return plActivatorBaseComponent::SetupProperties(node, pErrMsg);
}
Exemple #12
0
//==============================================
// Open the file "path" and assign an FCB to it
//==============================================
struct FCB *OpenFile(char *path)
{
	struct FCB *fcb = AllocKMem(sizeof(struct FCB));
	fcb->inode = AllocKMem(sizeof(struct ext2_inode));
	fcb->inodeNumber = GetFileINode(path);
	if (!fcb->inodeNumber)
	{
		DeallocMem(fcb);
		return (struct FCB *) -ENOENT;
	}
	GetINode(fcb->inodeNumber, fcb->inode);
	fcb->nextFCB = 0;
	fcb->fileCursor = 0;
	fcb->bufCursor = 0;
	fcb->buffer = AllocKMem((size_t)block_size);
	fcb->bufferIsDirty = 0;
	fcb->inodeIsDirty = 0;
	fcb->index1 = fcb->index2 = fcb->index3 = fcb->index4 = 0;
	fcb->currentBlock = fcb->inode->i_block[0];
	ReadBlock(fcb->currentBlock, fcb->buffer);
	return fcb;
}
Exemple #13
0
void    plAnimStealthNode::SetNodeName( const char *parentName )
{
    INode *node = GetINode();
    if( node != nil )
    {
        char name[ 512 ], newName[ 512 ];
        sprintf( name, "%s : %s", parentName, GetSegmentName() );

        if( GetCOREInterface()->GetINodeByName( name ) != nil )
        {
            // For whatever reason, MakeNameUnique() doesn't ACTUALLY make a name unique!
            // So we just need to more or less do it ourselves...
            int i;
            for( i = 1; i < 1024; i++ )
            {
                sprintf( newName, "%s(%d)", name, i );
                if( GetCOREInterface()->GetINodeByName( newName ) == nil )
                    break;
            }
            if( i == 1024 )
            {
                // You've got to be kidding me...
                char msg[ 2048 ];
                sprintf( msg, "WARNING: For some reason, we cannot find a unique name for the node '%s'. This"
                            " will most likely cause export problems. Exactly how many of these do we HAVE??",
                            name );
                hsMessageBox( msg, "WARNING!", hsMessageBoxNormal );
            }
        }
        else
            strcpy( newName, name );


        node->SetName( newName );
    }
}
void plResponderComponent::IConvertCmdWaits(plMaxNode* node, plErrorMsg* pErrMsg,
                                            int state, CmdIdxs& cmdIdxs, int &numCallbacks)
{
    IParamBlock2 *statePB = (IParamBlock2*)fCompPB->GetReferenceTarget(kResponderState, 0, state);
    plResponderModifier *responder = IGetResponderMod(node);
    hsTArray<plResponderModifier::plResponderCmd>& cmds = responder->fStates[state].fCmds;

    int numWaits = statePB->Count(kStateCmdWait);
    for (int i = 0; i < numWaits; i++)
    {
        IParamBlock2 *waitPB = GetWaitBlk(statePB, i);

        int wait = ResponderWait::GetWaitingOn(waitPB);

        // If the waiter and waitee both converted, create the callback
        if (cmdIdxs.find(wait) != cmdIdxs.end() && cmdIdxs.find(i) != cmdIdxs.end())
        {
            int convertedIdx = cmdIdxs[wait];

            ResponderWaitInfo waitInfo;
            waitInfo.responderName = plString::FromUtf8(GetINode()->GetName());
            waitInfo.receiver = responder->GetKey();
            waitInfo.callbackUser = numCallbacks++;
            waitInfo.msg = cmds[convertedIdx].fMsg;
            waitInfo.point = ResponderWait::GetWaitPoint(waitPB);

            responder->AddCallback(state, convertedIdx, waitInfo.callbackUser);
            cmds[cmdIdxs[i]].fWaitOn = waitInfo.callbackUser;

            IParamBlock2 *pb = (IParamBlock2*)statePB->GetReferenceTarget(kStateCmdParams, 0, wait);
            plResponderCmd *cmd = plResponderCmd::Find(pb);

            cmd->CreateWait(node, pErrMsg, pb, waitInfo);
        }
    }
}
Exemple #15
0
bool plPythonFileComponent::PreConvert(plMaxNode *node, plErrorMsg *pErrMsg)
{
    IParamBlock2 *pb = (IParamBlock2*)fCompPB->GetReferenceTarget(kPythonFilePB);
    plAutoUIBlock *block = FindAutoUI(pb);

    if (!block)
        return false;

    // if this is a multi-modifier python file component then is this the main (or first) maxnode
    bool    mainMultiModierNode = false;

    plPythonFileMod *mod = new plPythonFileMod;

    // create the modifier key ourselves so that we can get the name of the modifier in the name
    plSceneObject *obj = node->GetSceneObject();
    plKey modKey;
    if( fCompPB->GetInt( kPythonFileIsGlobal ) )
    {
        // Do we already have this guy?
        plPythonFileMod *existingOne = plPythonFileMod::ConvertNoRef( sCommonPythonLib.FindObject( plPythonFileMod::kGlobalNameKonstant ) );
        if( existingOne != nil )
        {
            // This component already exists, which can happen since it's in a common page. So we need
            // to nuke the key and its object so we can reuse it.
            modKey = existingOne->GetKey();

            // But first detach it from its target sceneObject
            if( existingOne->GetTarget( 0 ) != nil )
                existingOne->GetTarget( 0 )->GetKey()->Release( modKey );

            if( !sCommonPythonLib.RemoveObjectAndKey( modKey ) )
            {
                pErrMsg->Set( true, "Python File Component Error", 
                                    "The global Python File Component %s is attempting to export over an already "
                                    "existing component of the same name, and the exporter is unable to delete the "
                                    "old object to replace it. This would be a good time to call mcn for help.", GetINode()->GetName() ).Show(); 
                pErrMsg->Set( false );
            }

            // Pointer is invalid now anyways...
            existingOne = nil;
        }

        // Also make sure we have an age SDL object to attach to (currently only used for python, hence why it's safe here)
        obj = plSceneObject::ConvertNoRef( sCommonPythonLib.FindObject( plSDL::kAgeSDLObjectName ) );
        if( obj != nil )
        {
            plKey foo = obj->GetKey();
            if( !sCommonPythonLib.RemoveObjectAndKey( foo ) )
            {
                pErrMsg->Set( true, "Python File Component Error", 
                                    "The global Python File Component %s is attempting to export over an already "
                                    "existing component of the same name, and the exporter is unable to delete the "
                                    "old sceneObject to replace it. This would be a good time to call mcn for help.", GetINode()->GetName() ).Show(); 
                pErrMsg->Set( false );
            }

            // Pointer is invalid now anyways...
            obj = nil;
        }

        // Create us a new sceneObject to attach to
        obj = new plSceneObject;

        const plLocation &globalLoc = plPluginResManager::ResMgr()->GetCommonPage( node->GetLocation(), plAgeDescription::kGlobal );
        hsAssert( globalLoc.IsValid(), "Invalid common page location!!!" );
        modKey = hsgResMgr::ResMgr()->NewKey(plPythonFileMod::kGlobalNameKonstant, mod, globalLoc );

        // Make a key for our special sceneObject too
        plKey sdlObjectKey = hsgResMgr::ResMgr()->NewKey( plSDL::kAgeSDLObjectName, obj, globalLoc );
        plPluginResManager::ResMgr()->AddLooseEnd(sdlObjectKey);
    }
    else
    {
        if (block->IsMultiModifier())
        {
            // yup, then only create one modifier that will all the objects will attach to
            // in other words, one python module with many attached sceneobjects
            if ( fModKeys.empty())
            {
                // its empty so create the first and only one
                modKey = hsgResMgr::ResMgr()->NewKey(IGetUniqueName(node), mod, node->GetLocation());
                mainMultiModierNode = true;
            }
            else
            {
                // else we just take the first one (should be the only one)
                PythonKeys::iterator pos;
                pos = fModKeys.begin();
                modKey = pos->second;

                // Guess we won't be using that modifier we new'd up there. Does that mean we should delete it? Sure.
                delete mod;
                mod = nil;
            }
        }
        else    // else, nope... create a modifier for each object its attached to
        {
            modKey = hsgResMgr::ResMgr()->NewKey(IGetUniqueName(node), mod, node->GetLocation());
        }
    }
    hsgResMgr::ResMgr()->AddViaNotify(modKey, new plObjRefMsg(obj->GetKey(), plRefMsg::kOnCreate, -1, plObjRefMsg::kModifier), plRefFlags::kActiveRef);
    fModKeys[node] = modKey;

    // only let non-multimodifier or multimodifier then only the main node register for notifies
    if ( !block->IsMultiModifier() || mainMultiModierNode )
    {
        int nParams = block->NumParams();
        for (int i = 0; i < nParams; i++)
        {
            plAutoUIParam *param = block->GetParam(i);

            if (param->GetParamType() == plAutoUIParam::kTypeActivator)
            {
                // Register the modifier to recieve notifies from this activator.
                // We'll let the modifier know the activator key when it's available,
                // in the convert pass.
                int numcomps = param->GetCount(pb);
                for (int j=0; j< numcomps; j++ )
                {
                    plComponentBase *comp = param->GetComponent(pb,j);
                    if (comp)
                        comp->AddReceiverKey(modKey);
                }
            }

            if (param->GetParamType() == plAutoUIParam::kTypeGUIDialog)
            {
                // Register the modifier to recieve notifies from this activator.
                // We'll let the modifier know the activator key when it's available,
                // in the convert pass.
                int numcomps = param->GetCount(pb);
                for (int j=0; j< numcomps; j++ )
                {
                    plComponentBase *comp = param->GetComponent(pb,j);
                    if (comp && comp->ClassID() == GUI_DIALOG_COMP_CLASS_ID )
                    {
                        // convert the comp to a GUIDialog component, so we can talk to it
                        plGUIDialogComponent *dialog_comp = (plGUIDialogComponent*)comp;
                        dialog_comp->SetNotifyReceiver(modKey);
                    }
                }
            }
        }
    }

    return true;
}