Beispiel #1
0
boolean W_AddFile(const char *filename, boolean allowDuplicate)
{
	char    alterFileName[256];
	wadinfo_t header;
	DFILE  *handle;
	unsigned int length;
	filelump_t *fileinfo, singleinfo;
	filelump_t *freeFileInfo;
	filerecord_t *rec;
	const char *extension;

	// Filename given?
	if(!filename || !filename[0])
		return true;

	if((handle = F_Open(filename, "rb")) == NULL)
	{
		// Didn't find file. Try reading from the data path.
		R_PrependDataPath(filename, alterFileName);
		if((handle = F_Open(alterFileName, "rb")) == NULL)
		{
			Con_Message("W_AddFile: ERROR: %s not found!\n", filename);
			return false;
		}
		// We'll use this instead.
		filename = alterFileName;
	}

	// Do not read files twice.
	if(!allowDuplicate && !M_CheckFileID(filename))
	{
		F_Close(handle);		// The file is not used.
		return false;
	}

	Con_Message("W_AddFile: %s\n", M_Pretty(filename));

	// Determine the file name extension.
	extension = strrchr(filename, '.');
	if(!extension)
		extension = "";
	else
		extension++;			// Move to point after the dot.

	// Is it a zip/pk3 package?
	if(!stricmp(extension, "zip") || !stricmp(extension, "pk3"))
	{
		return Zip_Open(filename, handle);
	}

	// Get a new file record.
	rec = W_RecordNew();
	strcpy(rec->filename, filename);
	convertSlashes(rec->filename);
	rec->handle = handle;

	// If we're not loading for startup, flag the record to be a Runtime one.
	if(!loadingForStartup)
		rec->flags = FRF_RUNTIME;

	if(stricmp(extension, "wad") && stricmp(extension, "gwa"))
	{
		// Single lump file.
		fileinfo = &singleinfo;
		freeFileInfo = NULL;
		singleinfo.filepos = 0;
		singleinfo.size = F_Length(handle);
		M_ExtractFileBase(filename, singleinfo.name);
		rec->numlumps = 1;
	}
	else
	{
		// WAD file.
		F_Read(&header, sizeof(header), handle);
		if(!strncmp(header.identification, "JWAD", 4))
		{
			// This is treated like an IWAD, but we won't set the
			// iwadLoaded flag.
			rec->iwad = true;
		}
		else if(strncmp(header.identification, "IWAD", 4))
		{
			if(strncmp(header.identification, "PWAD", 4))
			{					// Bad file id
				Con_Error("Wad file %s doesn't have IWAD or PWAD id\n",
						  filename);
			}
		}
		else
		{
			// Found an IWAD.
			iwadLoaded = true;
			if(!stricmp(extension, "wad"))
				rec->iwad = true;
		}
		header.numlumps = LONG(header.numlumps);
		header.infotableofs = LONG(header.infotableofs);
		length = header.numlumps * sizeof(filelump_t);
		if(!(fileinfo = malloc(length)))
		{
			Con_Error("W_AddFile: fileinfo malloc failed\n");
		}
		freeFileInfo = fileinfo;
		F_Seek(handle, header.infotableofs, SEEK_SET);
		F_Read(fileinfo, length, handle);
		rec->numlumps = header.numlumps;
	}

	// Insert the lumps to lumpinfo, into their rightful places.
	W_InsertLumps(fileinfo, rec);

	if(freeFileInfo)
		free(freeFileInfo);

	PrimaryLumpInfo = lumpinfo;
	PrimaryLumpCache = lumpcache;
	PrimaryNumLumps = numlumps;

	// Print the 'CRC' number of the IWAD, so it can be identified.
	if(rec->iwad)
		Con_Message("  IWAD identification: %08x\n",
					W_CRCNumberForRecord(rec - records));

	// glBSP: Also load a possible GWA.
	if(!stricmp(extension, "wad"))
	{
		char    buff[256];

		strcpy(buff, filename);
		strcpy(buff + strlen(buff) - 3, "gwa");

		// If GL data exists, load it.
		if(F_Access(buff))
		{
			W_AddFile(buff, allowDuplicate);
		}
	}

	return true;
}
Beispiel #2
0
uint8_t Update_Font(void)
{
	uint32_t fcluster=0;	   
	uint32_t i;
	//uint8_t temp[512];  //零时空间	 在这里定义,会内存溢出
	uint32_t tempsys[2];  //临时记录文件起始位置和文件大小
	float prog;
	uint8_t t;		 
	FileInfoStruct FileTemp;//零时文件夹   				    	 
	//得到根目录的簇号
	if(FAT32_Enable)fcluster=FirstDirClust;
	else fcluster=0;			   
	FileTemp=F_Search(fcluster,(unsigned char *)folder[0],T_FILE);//查找system文件夹	  
	if(FileTemp.F_StartCluster==0)return 1;						  //系统文件夹丢失			  
	{	 										 
		//先查找字体
		FileTemp=F_Search(FileTemp.F_StartCluster,(unsigned char *)folder[1],T_FILE);//在system文件夹下查找FONT文件夹
		if(FileTemp.F_StartCluster==0)return 2;//字体文件夹丢失	

		fcluster=FileTemp.F_StartCluster;      //字体文件夹簇号	    
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[2],T_SYS);//在system文件夹下查找SYS文件
		if(FileTemp.F_StartCluster==0)return 3;//FONT12字体文件丢失	 
		LCD_ShowString1(20,90,"Write UNI2GBK to FLASH...",RED,BLACK);		
		LCD_ShowString1(108,110,"%",RED,BLACK);		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{		 
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				M45PE_Write(temp,i+100000,512);//从100K字节处开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum1(84,110,t,3,16);//显示数值
			}					    
		}
		UNI2GBKADDR=100000;//UNI2GBKADDR从100K处开始写入.
		tempsys[0]=UNI2GBKADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //UNI2GBKADDR 大小
		M45PE_Write((uint8_t*)tempsys,0,8);//记录在地址0~7处

		Delay(1000);			    
		//printf("UNI2GBK写入FLASH完毕!\n");
		//printf("写入数据长度:%d\n",FileTemp.F_Size);
		//printf("UNI2GBKSADDR:%d\n\n",UNI2GBKADDR);
		
		FONT16ADDR=FileTemp.F_Size+UNI2GBKADDR;//F16的首地址 
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[0],T_FON);//在system文件夹下查找FONT16字体文件
		if(FileTemp.F_StartCluster==0)return 4;//FONT16字体文件丢失	 
	
		LCD_ShowString1(20,90,"Write FONT16 to FLASH... ",RED,BLACK);		
 		//printf("开始FONT16写入FLASH...\n");		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				M45PE_Write(temp,i+FONT16ADDR,512);//从0开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum1(84,110,t,3,16);//显示数值
			}
		}												   
		tempsys[0]=FONT16ADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //FONT16ADDR 大小
		M45PE_Write((uint8_t*)tempsys,8,8);//记录在地址8~15处
		
		Delay(1000);	    
		//printf("FONT16写入FLASH完毕!\n");
		//printf("写入数据长度:%d\n",FileTemp.F_Size);


		FONT12ADDR=FileTemp.F_Size+FONT16ADDR;//F16的首地址
		//printf("FONT16SADDR:%d\n\n",FONT16ADDR);
		//LCD_ShowString(20,60,"Write FONT12 to FLASH... ");		
		//FONT12暂时不加入
		/*			  
		FileTemp=F_Search(fcluster,(unsigned char *)sysfile[1],T_FON);//在system文件夹下查找FONT12字体文件
		if(FileTemp.F_StartCluster==0)return 5;//FONT12字体文件丢失	 
		printf("开始FONT12写入FLASH...\n");		
		F_Open(&FileTemp);//打开该文件
		i=0;	  
		while(F_Read(&FileTemp,temp))//成功读出512个字节
		{
			if(i<FileTemp.F_Size)//不超过文件大小
			{
				M45PE_Write(temp,i+FONT12ADDR,512);//从0开始写入512个数据   
				i+=512;//增加512个字节
			}
			prog=(float)i/FileTemp.F_Size;
			prog*=100;
			if(t!=prog)
			{
				t=prog;
				if(t>100)t=100;
				LCD_ShowNum(84,80,t,3,16);//显示数值
			}
		}	    
		tempsys[0]=FONT12ADDR;
		tempsys[1]=FileTemp.F_Size;	 	  //FONT16ADDR 大小
		M45PE_Write((uint8_t*)tempsys,16,8);//记录在地址16~23处

		printf("FONT12写入FLASH完毕!\n");
		printf("写入数据长度:%d\n",FileTemp.F_Size);   
		printf("FONT12SADDR:%d\n\n",FONT12ADDR); */
	}
	t=0xBB;
   	M45PE_Write(&t,24,1);//写入字库存在标志	0XAA
	LCD_ShowString1(20,90,"  Font Update Successed  ",RED,BLACK);		    
	Delay(1000);		
	Delay(1000);		
	return 0;//成功
}
Beispiel #3
0
void writeSKL(tModel_t *m, tAnim_t *a, const char *outFName) {
	FILE *out;
	int i, j, k, v, t, addVerts;

	out = F_Open(outFName,"wb");

	fprintf(out,"//////////////////////////////////////////////////////////////////////////\n");
	fprintf(out,"//\n");
	fprintf(out,"// Exported by md5_2_skX\n");
	fprintf(out,"//\n");
	fprintf(out,"//////////////////////////////////////////////////////////////////////////\n");
	fprintf(out,"\n");

	fprintf(out,"SKELETON\n");
	fprintf(out,"VERSION 1\n");

	fprintf(out,"\n");
	fprintf(out,"NUMMATERIALS %i\n",m->numSurfaces);	

	for(i = 0; i < m->numSurfaces; i++) {
		fprintf(out,"MATERIAL %i %s\n",i,m->surfs[i].name);
	}

	fprintf(out,"\n");
	fprintf(out,"NUMBONES %i\n",m->numBones);

	for(i = 0; i < m->numBones; i++) {
		fprintf(out,"BONE %i %i %s\n",i,m->bones[i].parent,m->bones[i].name);	
	}

	fprintf(out,"NUMVERTS %i\n",getTotalVertCount(m));
	v = 0;
	for(i = 0; i < m->numSurfaces; i++) {
		tVert_t *vt;
		tSurf_t *sf;
		
		sf = m->surfs + i;
		vt = sf->verts;
		for(j = 0; j < sf->numVerts; j++,v++,vt++) {
			fprintf(out,"VERT %i\n",v);
			fprintf(out,"NORMAL %f %f %f\n",vt->normal[0],vt->normal[1],vt->normal[2]);
			//fprintf(out,"NORMAL 1 0 0\n");
			fprintf(out,"BONES %i\n",vt->numWeights);
			for(k = 0; k < vt->numWeights; k++) {
				fprintf(out,"BONE %i %f %f %f %f\n",vt->weights[k].boneNum,vt->weights[k].boneWeight,
					vt->weights[k].offset[0],vt->weights[k].offset[1],vt->weights[k].offset[2]);
			}
			fprintf(out,"\n");
		}
	}	

	fprintf(out,"\n");
	fprintf(out,"NUMFACES %i\n",getTotalTriCount(m));
	
	t = 0;
	addVerts = 0;
	for(i = 0; i < m->numSurfaces; i++) {
		tTri_t *tt;
		tSurf_t *sf;
		
		sf = m->surfs + i;
		tt = sf->tris;
		for(j = 0; j < sf->numTris; j++,t++,tt++) {
			int v0, v1, v2;
			tVert_t *vp0, *vp1, *vp2;
			
			v0 = tt->indexes[0] + addVerts;
			v1 = tt->indexes[1] + addVerts;			
			v2 = tt->indexes[2] + addVerts;

			vp0 = sf->verts + tt->indexes[0];
			vp1 = sf->verts + tt->indexes[1];
			vp2 = sf->verts + tt->indexes[2];

			// TRI <surface/material index> 
			fprintf(out,"TRI %i",i);
			fprintf(out," %i %f %f", v0, vp0->texCoords[0], vp0->texCoords[1]);
			fprintf(out," %i %f %f", v1, vp1->texCoords[0], vp1->texCoords[1]);
			fprintf(out," %i %f %f", v2, vp2->texCoords[0], vp2->texCoords[1]);
			fprintf(out,"\n");

		}
		addVerts += sf->numVerts;
	}	


	fprintf(out,"\n");
	fprintf(out,"FRAMERATE %f\n",a->frameRate);
	fprintf(out,"NUMFRAMES %i\n",a->numFrames);
	fprintf(out,"\n");
	for(i = 0; i < a->numFrames; i++) {
		tFrame_t *f;
		bone_t *bones, *b;
		
		bones = b = setupMD5AnimBones(a,i);
		md5AnimateBones(m,bones); 
		f = a->frames + i;
		fprintf(out,"\nFRAME %i\n",i);
		for(j = 0; j < a->numBones; j++,b++) {
			vec3_t axis[3];

			fprintf(out,"BONE %i\n",j);
			fprintf(out,"OFFSET %f %f %f\n",
				b->p[0],b->p[1],b->p[2]);

			QuatToAxis(b->q,axis);

			fprintf(out,"X %f %f %f\n",axis[0][0],axis[0][1],axis[0][2]);
			fprintf(out,"Y %f %f %f\n",axis[1][0],axis[1][1],axis[1][2]);
			fprintf(out,"Z %f %f %f\n",axis[2][0],axis[2][1],axis[2][2]);
			

			fprintf(out,"\n");
			
		}
	}


	fprintf(out,"\nNUMBOXES 0\n");
	fprintf(out,"\n");
	fprintf(out,"END\n");
	fclose(out);

	T_Printf("Wrote %s\n",outFName);
}
Beispiel #4
0
/*
 * Opens the file zip, reads the directory and stores the info for later
 * access. If prevOpened is not NULL, all data will be read from there.
 */
boolean Zip_Open(const char *fileName, DFILE * prevOpened)
{
	DFILE  *file;
	package_t *pack;
	centralend_t summary;
	void   *directory;
	char   *pos;
	char    buf[512];
	zipentry_t *entry;
	int     index;

	if(prevOpened == NULL)
	{
		// Try to open the file.
		if((file = F_Open(fileName, "rb")) == NULL)
		{
			Con_Message("Zip_Open: %s not found.\n", fileName);
			return false;
		}
	}
	else
	{
		// Use the previously opened file.
		file = prevOpened;
	}

	VERBOSE(Con_Message("Zip_Open: %s\n", M_Pretty(fileName)));

	// Scan the end of the file for the central directory end record.
	if(!Zip_LocateCentralDirectory(file))
	{
		Con_Error("Zip_Open: %s: Central directory not found.\n",
				  M_Pretty(fileName));
	}

	// Read the central directory end record.
	F_Read(&summary, sizeof(summary), file);

	// Does the summary say something we don't like?
	if(summary.diskEntryCount != summary.totalEntryCount)
	{
		Con_Error("Zip_Open: %s: Multipart Zip files are not supported.\n",
				  M_Pretty(fileName));
	}

	// Read the entire central directory into memory.
	directory = malloc(summary.size);
	F_Seek(file, summary.offset, SEEK_SET);
	F_Read(directory, summary.size, file);

	pack = Zip_NewPackage();
	strcpy(pack->name, fileName);
	pack->file = file;

	// Read all the entries.
	pos = directory;
	for(index = 0; index < summary.totalEntryCount;
		index++, pos += sizeof(centralfileheader_t))
	{
		localfileheader_t localHeader;
		centralfileheader_t *header = (void *) pos;
		char   *nameStart = pos + sizeof(centralfileheader_t);

		// Advance the cursor past the variable sized fields.
		pos +=
			header->fileNameSize + header->extraFieldSize +
			header->commentSize;

		Zip_CopyStr(buf, nameStart, header->fileNameSize, sizeof(buf));

		// Directories are skipped.
		if(buf[header->fileNameSize - 1] == '/' && !header->size)
			continue;

		// Do we support the format of this file?
		if(header->compression != ZFC_NO_COMPRESSION ||
		   header->compressedSize != header->size)
		{
			Con_Error("Zip_Open: %s: '%s' is compressed.\n  Compression is "
					  "not supported.\n", M_Pretty(fileName), buf);
		}
		if(header->flags & ZFH_ENCRYPTED)
		{
			Con_Error("Zip_Open: %s: '%s' is encrypted.\n  Encryption is "
					  "not supported.\n", M_Pretty(fileName), buf);
		}

		// Convert all slashes to backslashes, for compatibility with 
		// the sys_filein routines.
		Dir_FixSlashes(buf);

		// Make it absolute.
		M_PrependBasePath(buf, buf);

		// We can add this file to the zipentry list.
		entry = Zip_NewFile(buf);
		entry->package = pack;
		entry->size = header->size;

		// Read the local file header, which contains the correct
		// extra field size (Info-ZIP!).
		F_Seek(file, header->relOffset, SEEK_SET);
		F_Read(&localHeader, sizeof(localHeader), file);

		entry->offset =
			header->relOffset + sizeof(localfileheader_t) +
			header->fileNameSize + localHeader.extraFieldSize;
	}

	// The central directory is no longer needed.
	free(directory);

	Zip_SortFiles();
	Zip_RemoveDuplicateFiles();

	// File successfully opened!
	return true;
}