예제 #1
0
void C4Network2Res::OnChunk(const C4Network2ResChunk &rChunk)
{
	if (!fLoading) return;
	// correct resource?
	if (rChunk.getResID() != getResID()) return;
	// add resource data
	CStdLock FileLock(&FileCSec);
	bool fSuccess = rChunk.AddTo(this, pParent->getIOClass());
#ifdef C4NET2RES_DEBUG_LOG
	// log
	Application.InteractiveThread.ThreadLogS("Network: Res: %s chunk %d to resource %s (%s)%s", fSuccess ? "added" : "could not add", rChunk.getChunkNr(), Core.getFileName(), szFile, fSuccess ? "" : "!");
#endif
	if (fSuccess)
	{
		// status changed
		fDirty = true;
		// remove load waits
		for (C4Network2ResLoad *pLoad = pLoads, *pNext; pLoad; pLoad = pNext)
		{
			pNext = pLoad->Next();
			if (static_cast<uint32_t>(pLoad->getChunk()) == rChunk.getChunkNr())
				RemoveLoad(pLoad);
		}
	}
	// complete?
	if (Chunks.isComplete())
		EndLoad();
	// check: start new loads?
	else
		StartNewLoads();
}
예제 #2
0
C4Network2Res::Ref C4Network2Res::Derive()
{
	// Called before the file is changed. Rescues all files and creates a
	// new resource for the file. This resource is flagged as "anonymous", as it
	// has no official core (no res ID, to be exact).
	// The resource gets its final core when FinishDerive() is called.

	// For security: This doesn't make much sense if the resource is currently being
	// loaded. So better assume the caller doesn't know what he's doing and check.
	if (isLoading()) return NULL;

	CStdLock FileLock(&FileCSec);
	// Save back original file name
	char szOrgFile[_MAX_PATH+1];
	SCopy(szFile, szOrgFile, _MAX_PATH);
	bool fOrgTempFile = fTempFile;

	// Create a copy of the file, if neccessary
	if (!*szStandalone || SEqual(szStandalone, szFile))
	{
		if (!pParent->FindTempResFileName(szOrgFile, szFile))
			{ Log("Derive: could not find free name for temporary file!"); return NULL; }
		if (!C4Group_CopyItem(szOrgFile, szFile))
			{ Log("Derive: could not copy to temporary file!"); return NULL; }
		// set standalone
		if (*szStandalone)
			SCopy(szFile, szStandalone, _MAX_PATH);
		fTempFile = true;
	}
	else
	{
		// Standlone exists: Just set szFile to point on the standlone. It's
		// assumed that the original file isn't of intrest after this point anyway.
		SCopy(szStandalone, szFile, _MAX_PATH);
		fTempFile = true;
	}

	Application.InteractiveThread.ThreadLogS("Network: Resource: deriving from %d:%s, original at %s", getResID(), Core.getFileName(), szFile);

	// (note: should remove temp file if something fails after this point)

	// create new resource
	C4Network2Res::Ref pDRes = new C4Network2Res(pParent);
	if (!pDRes) return NULL;

	// initialize
	if (!pDRes->SetDerived(Core.getFileName(), szOrgFile, fOrgTempFile, getType(), getResID()))
		return NULL;

	// add to list
	pParent->Add(pDRes);

	// return new resource
	return pDRes;
}
예제 #3
0
void UCamPool::UCamPoolInit()
{
  int i;
  // set name and version
  setResID(getResID(), 200);
  camCnt = 0;
  cmdExe = NULL;
  verboseMessages = false;
  for (i = 0; i < MAX_MOUNTED_CAMERAS; i++)
    cam[i] = NULL;
  imageLog = new UImageLog();
  resVersion = getResVersion();
  createBaseVar();
  replaySetFileName("image.log");
  imageLog->setLogName("image");
  imgPool = NULL;
}
예제 #4
0
bool XMLToSndManifest(const wchar_t* cFilename)
{
	wstring sXMLFile = cFilename;
	sXMLFile += TEXT(".xml");
	
	XMLDocument* doc = new XMLDocument;
	int iErr = doc->LoadFile(ws2s(sXMLFile).c_str());
	if(iErr != XML_NO_ERROR)
	{
		cout << "Error parsing XML file " << ws2s(sXMLFile) << ": Error " << iErr << endl;
		delete doc;
		return false;
	}
	//Grab root element
	XMLElement* root = doc->RootElement();
	if(root == NULL)
	{
		cout << "Error: Root element NULL in XML file " << ws2s(sXMLFile) << endl;
		delete doc;
		return false;
	}
	
	//Roll through child elements
	list<soundTakeGroup> lSoundTakeGroups;
	vector<takeRecord> vSoundTakes;
	XMLElement* elem = root->FirstChildElement("sound");
	i32 iCurTake = 0;
	while(elem != NULL)
	{
		soundTakeGroup stg;
		const char* id = elem->Attribute("id");
		if(id == NULL)
		{
			cout << "Error: Unable to get id of XML element in file " << ws2s(sXMLFile) << endl;
			delete doc;
			return false;
		}
		stg.logicalId = getSoundId(s2ws(id).c_str());	//TODO: Hash this?
		stg.firstTakeIdx = vSoundTakes.size();
		stg.numTakes = 0;
		
		//Get the takes for this sound
		XMLElement* elem2 = elem->FirstChildElement("take");
		while(elem2 != NULL)
		{
			iCurTake++;
			takeRecord tr;
			const char* cName = elem2->Attribute("filename");
			if(cName == NULL)
			{
				cout << "Error: Unable to get filename of take record in file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("channels", &tr.channels) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get channels from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("samplespersec", &tr.samplesPerSec) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get samplesPerSec from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("samplecountperchannel", &tr.sampleCountPerChannel) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get sampleCountPerChannel from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("vorbisworkingsetsizebytes", &tr.vorbisWorkingSetSizeBytes) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get vorbisWorkingSetSizeBytes from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("vorbismarkerssizebytes", &tr.vorbisMarkersSizeBytes) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get vorbisMarkersSizeBytes from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			if(elem2->QueryIntAttribute("vorbispacketssizebytes", &tr.vorbisPacketsSizeBytes) != XML_NO_ERROR)
			{
				cout << "Error: Unable to get vorbisPacketsSizeBytes from take " << iCurTake << " from file " << ws2s(sXMLFile) << endl;
				delete doc;
				return false;
			}
			wstring sName = s2ws(cName);
			sName.erase(sName.size()-4);	//Delete the ".ogg" ending from the wstring
			tr.resId = getResID(sName);		//Get the resource ID from this filename
			vSoundTakes.push_back(tr);
			elem2 = elem2->NextSiblingElement("take");
			stg.numTakes++;
		}
		
		lSoundTakeGroups.push_back(stg);	//Hang onto this
		elem = elem->NextSiblingElement("sound");	//Next item
	}
	delete doc;	//We're done with this
	
	//Repack
	FILE* f = _wfopen(cFilename, TEXT("wb"));	//Open file for writing
	if(f == NULL)
	{
		cout << "Unable to open file " << cFilename << " for writing." << endl;
		return false;
	}
	
	//Write the soundManifestHeader
	i32 curOffset = sizeof(soundManifestHeader);
	soundManifestHeader smh;
	smh.sounds.count = lSoundTakeGroups.size();
	smh.sounds.offset = curOffset;
	smh.takes.count = vSoundTakes.size();
	curOffset += lSoundTakeGroups.size() * sizeof(soundTakeGroup);
	smh.takes.offset = curOffset;
	fwrite(&smh, 1, sizeof(soundManifestHeader), f);
	
	//Write out sounds
	for(list<soundTakeGroup>:: iterator i = lSoundTakeGroups.begin(); i != lSoundTakeGroups.end(); i++)
		fwrite(&(*i), 1, sizeof(soundTakeGroup), f);
	
	//Write out sound takes
	for(unsigned int i = 0; i < vSoundTakes.size(); i++)
		fwrite(&vSoundTakes[i], 1, sizeof(takeRecord), f);
	
	//Done	
	fclose(f);
	return true;
}