Example #1
0
int AgiEngine::loadObjects(const char *fname) {
	Common::File fp;
	uint32 flen;
	uint8 *mem;

	_objects = NULL;
	_game.numObjects = 0;

	debugC(5, kDebugLevelResources, "(Loading objects '%s')", fname);

	if (!fp.open(fname))
		return errBadFileOpen;

	fp.seek(0, SEEK_END);
	flen = fp.pos();
	fp.seek(0, SEEK_SET);

	if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) {
		fp.close();
		return errNotEnoughMemory;
	}

	fp.read(mem, flen);
	fp.close();

	decodeObjects(mem, flen);
	free(mem);
	return errOK;
}
Example #2
0
/**
 * Read and decode objects, and store them in the internal structure.
 *
 * @param  fp    File pointer
 * @param  flen  File length
 */
int AgiEngine::readObjects(Common::File &fp, int flen) {
	uint8 *mem;

	if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) {
		fp.close();
		return errNotEnoughMemory;
	}

	fp.read(mem, flen);
	fp.close();

	decodeObjects(mem, flen);
	free(mem);
	return errOK;
}
Example #3
0
bool deserializeIDBKeyPath(const uint8_t* data, size_t size, Optional<IDBKeyPath>& result)
{
    if (!data || !size)
        return false;

    auto decoder = KeyedDecoder::decoder(data, size);

    KeyPathType type;
    bool succeeded = decoder->decodeEnum("type", type, [](KeyPathType value) {
        return value == KeyPathType::Null || value == KeyPathType::String || value == KeyPathType::Array;
    });
    if (!succeeded)
        return false;

    switch (type) {
    case KeyPathType::Null:
        break;
    case KeyPathType::String: {
        String string;
        if (!decoder->decodeString("string", string))
            return false;
        result = IDBKeyPath(WTFMove(string));
        break;
    }
    case KeyPathType::Array: {
        Vector<String> vector;
        succeeded = decoder->decodeObjects("array", vector, [](KeyedDecoder& decoder, String& result) {
            return decoder.decodeString("string", result);
        });
        if (!succeeded)
            return false;
        result = IDBKeyPath(WTFMove(vector));
        break;
    }
    }
    return true;
}
Example #4
0
void
ivol_BuildNode (
  pwr_tStatus		*status,
  ivol_sNode		*lnp,
  const co_mFormat      *formatp
)
{
  gdb_sVolume		*vp;
  pwr_sMountObject	*MountObject;
  cdh_uVolumeId		sys_vid;
  pwr_tObjid		sys_oid;
  pwr_tObjid		oid;
  gdb_sObject		*op;
  gdb_sObject		*vop;
  gdb_sObject		*mop;
  pool_sQlink		*vl;
  gdb_sClass		*cp;
  pool_sQlink		*cl;
  co_mFormat            fm;
  pwr_tTime		time;
  
  
  pwr_dStatus(sts, status, GDH__SUCCESS);

  /* Fill in remaining node information.  */

  gdbroot->db->nod_oid = lnp->nod_oid;

  gdbroot->my_node->nod_oid = gdbroot->db->nod_oid;
  gdbroot->my_node->vol_oid = gdbroot->db->vol_oid;

  /* Create the system volume and mount it in the root voulme.  */

  sys_vid.pwr	  = gdbroot->db->vid;
  sys_vid.v.vid_3 = cdh_eVid3_local;
  sys_oid.vid	  = sys_vid.pwr;
  sys_oid.oix	  = pwr_cNObjectIx;
  time_GetTime(&time);

  vp = gdb_LoadVolume(sts, sys_vid.pwr, "", pwr_eClass_SystemVolume, gdbroot->db->nid, 
                      time, gdb_mLoad_build, co_GetOwnFormat(&fm));
  if (vp == NULL) errh_Bugcheck(*sts, "");

  /* Create the volume object.  */

  vop = loadObject(sts, vp, vp->g.name.orig, sys_oid, pwr_eClass_SystemVolume,
    sizeof(pwr_sSystemVolume), pwr_cNObjid, net_mGo__, pwr_cNObjid); 
  if (vop == NULL) errh_Bugcheck(*sts, "");
  vop->u.n.flags.b.bodyDecoded = 1;

  /* Create the 'pwrNode' object.  */

  oid = vol_Oid(sts, vp, pwr_eClass_NodeHier);
  op = loadObject(sts, vp, "pwrNode", oid, pwr_eClass_NodeHier,
    sizeof(pwr_sNodeHier), sys_oid, net_mGo__, pwr_cNObjid); 
  if (op == NULL) errh_Bugcheck(*sts, "");
  op->u.n.flags.b.bodyDecoded = 1;

  errh_Info("Created pwrNode, oid: %s", cdh_ObjidToString(NULL, oid, 1));
  /* Create a mount object in the root volume, to mount the 'pwrNode' object.  */

  pwr_Assert(gdbroot->my_volume != NULL);

  oid = vol_Oid(sts, gdbroot->my_volume, pwr_eClass_MountObject);
  mop = loadObject(sts, gdbroot->my_volume, "pwrNode", oid, pwr_eClass_MountObject,
    sizeof(pwr_sMountObject), gdbroot->db->vol_oid, net_mGo_isMountClient, op->g.oid); 
  if (mop == NULL) errh_Bugcheck(*sts, "");
  mop->u.n.flags.b.bodyDecoded = 1;
  
  MountObject = pool_Address(NULL, gdbroot->rtdb, mop->u.n.body);
  strcpy(MountObject->Description, "Mounts the system volume object pwr_Node.");
  MountObject->Object = op->g.oid;

  /* Build all native volumes.  */

  for (
    vl = pool_Qsucc(sts, gdbroot->pool, &gdbroot->db->vol_lh);
    vl != &gdbroot->db->vol_lh;
    vl = pool_Qsucc(sts, gdbroot->pool, vl)
  ) {
    vp = pool_Qitem(vl, gdb_sVolume, l.vol_ll);

    if (vp->l.flags.b.isNative) ivol_BuildVolume(sts, vp);
  }

  /* Link class definitions.  */

  for (
    cl = pool_Qsucc(sts, gdbroot->pool, &gdbroot->db->class_lh);
    cl != &gdbroot->db->class_lh;
  ) {
    cp = pool_Qitem(cl, gdb_sClass, class_ll);
    /* NOTA BENE !! mvol_LinkClass will change the linkage.  */
    cl = pool_Qsucc(sts, gdbroot->pool, cl);

    mvol_LinkClass(sts, cp, gdb_mAdd__);
  }

  /* Link Sub classes to attributes.  */

  for (
    cl = pool_Qsucc(sts, gdbroot->pool, &gdbroot->db->class_lh);
    cl != &gdbroot->db->class_lh;
  ) {
    cp = pool_Qitem(cl, gdb_sClass, class_ll);
    cl = pool_Qsucc(sts, gdbroot->pool, cl);

    if (cp->hasSc)
      mvol_LinkSubClassToAttribute(sts, cp);
  }

  /* Build ScObjects for native volumes.  */

  for (
    vl = pool_Qsucc(sts, gdbroot->pool, &gdbroot->db->vol_lh);
    vl != &gdbroot->db->vol_lh;
    vl = pool_Qsucc(sts, gdbroot->pool, vl)
  ) {
    vp = pool_Qitem(vl, gdb_sVolume, l.vol_ll);

    if (vp->l.flags.b.isNative)
      buildScObjects(sts, vp);
  }


  /* Build class attribute tree */
  mvol_BuildCatt(sts);


  convFctn = dvms_GetFctns(formatp);
  if (convFctn != NULL)
    decodeObjects(formatp->b.bo);
  convFctn = NULL;

  mountClients(sts, gdbroot->my_volume);
}