/* ================== SCR_ReadNextFrame ================== */ byte *SCR_ReadNextFrame (void) { int32_t r; int32_t command; byte samples[22050/14*4]; byte compressed[0x20000]; int32_t size; byte *pic; cblock_t in, huf1; int32_t start, end, count; // read the next frame r = FS_FRead (&command, 4, 1, cl.cinematic_file); if (r == 0) // we'll give it one more chance r = FS_FRead (&command, 4, 1, cl.cinematic_file); if (r != 4) return NULL; command = LittleLong(command); if (command == 2) return NULL; // last frame marker if (command == 1) { // read palette FS_Read (cl.cinematicpalette, sizeof(cl.cinematicpalette), cl.cinematic_file); cl.cinematicpalette_active = 0; // dubious.... exposes an edge case } // decompress the next frame FS_Read (&size, 4, cl.cinematic_file); size = LittleLong(size); if (size > sizeof(compressed) || size < 1) Com_Error (ERR_DROP, "Bad compressed frame size"); FS_Read (compressed, size, cl.cinematic_file); // read sound start = cl.cinematicframe*cin.s_rate/14; end = (cl.cinematicframe+1)*cin.s_rate/14; count = end - start; FS_Read (samples, count*cin.s_width*cin.s_channels, cl.cinematic_file); S_RawSamples (count, cin.s_rate, cin.s_width, cin.s_channels, samples, Cvar_VariableValue("s_volume")); in.data = compressed; in.count = size; huf1 = Huff1Decompress (in); pic = huf1.data; cl.cinematicframe++; return pic; }
void SV_ReadServerFile(void) { fileHandle_t f; char name[MAX_OSPATH], string[128]; char comment[32]; char mapcmd[MAX_TOKEN_CHARS]; Com_DPrintf("SV_ReadServerFile()\n"); Com_sprintf(name, sizeof(name), "save/current/server.ssv"); FS_FOpenFile(name, &f, FS_READ); if (!f) { Com_Printf("Couldn't read %s\n", name); return; } /* read the comment field */ FS_Read(comment, sizeof(comment), f); /* read the mapcmd */ FS_Read(mapcmd, sizeof(mapcmd), f); /* read all CVAR_LATCH cvars these will be things like coop, skill, deathmatch, etc */ while (1) { char cvarname[LATCH_CVAR_SAVELENGTH] = {0}; if (!FS_FRead(cvarname, 1, sizeof(cvarname), f)) { break; } FS_Read(string, sizeof(string), f); Com_DPrintf("Set %s = %s\n", cvarname, string); Cvar_ForceSet(cvarname, string); } FS_FCloseFile(f); /* start a new game fresh with new cvars */ SV_InitGame(); strcpy(svs.mapcmd, mapcmd); /* read game state */ Com_sprintf(name, sizeof(name), "%s/save/current/game.ssv", FS_Gamedir()); ge->ReadGame(name); }
static size_t ovc_read (void *ptr, size_t size, size_t nmemb, void *datasource) { bgTrack_t *track = (bgTrack_t *)datasource; if (!size || !nmemb) return 0; #ifdef OGG_DIRECT_FILE return fread(ptr, 1, size * nmemb, track->file) / size; #else Com_Printf("Calling FS_FRead\n"); // return FS_Read(ptr, size * nmemb, track->file) / size; return FS_FRead(ptr, size * nmemb, 1, track->file) / size; #endif }
/* ============== SV_ReadServerFile ============== */ void SV_ReadServerFile (void) { fileHandle_t f; char fileName[MAX_OSPATH], varName[128], string[128]; char comment[32]; char mapcmd[MAX_TOKEN_CHARS]; Com_DPrintf("SV_ReadServerFile()\n"); Com_sprintf (fileName, sizeof(fileName), "save/current/server.ssv"); FS_FOpenFile (fileName, &f, FS_READ); if (!f) { Com_Printf ("Couldn't read %s\n", fileName); return; } // read the comment field FS_Read (comment, sizeof(comment), f); // read the mapcmd FS_Read (mapcmd, sizeof(mapcmd), f); // read all CVAR_LATCH cvars // these will be things like coop, skill, deathmatch, etc while (1) { if (!FS_FRead (varName, 1, sizeof(varName), f)) break; FS_Read (string, sizeof(string), f); Com_DPrintf ("Set %s = %s\n", varName, string); Cvar_ForceSet (varName, string); } FS_FCloseFile(f); // start a new game fresh with new cvars SV_InitGame (); // strncpy (svs.mapcmd, mapcmd); Q_strncpyz (svs.mapcmd, mapcmd, sizeof(svs.mapcmd)); // read game state Com_sprintf (fileName, sizeof(fileName), "%s/save/current/game.ssv", FS_Gamedir()); ge->ReadGame (fileName); }
void SpiFlashDownFromSD(bool ForceDownload,const u8 *CfgPath,u8 *FileBuf,u8 *PageBuf) { u8 Buffer2[16]; u8 *pTmp; u8 *pSecStart[MaxSecItem]; u8 *pSecEnd[MaxSecItem]; u8 *pAddr[MaxDownItem]; u8 *pBinPath[MaxDownItem]; u8 EarseSecFlag; //存储每个文件的匹配结果 u8 CurSecItem=0;//当前解析的扇区配置项 u8 CurDownItemNum=0;//当前扇区项下面的下载项个数 u8 *pCfg; int i,j; UINT ReadByte; u32 SecStart,SecEnd; FS_FILE *pFileObj; //打开配置文件 if((CfgPath[0]==0)||(CfgPath==NULL)) return; if ((pFileObj=FS_FOpen((void *)CfgPath, FA_OPEN_EXISTING | FA_READ)) == 0 ) { Debug("Cannot open file \"%s\"\n\r",CfgPath); return; } //读取配置文件 if((ReadByte=FS_FRead((void *)FileBuf, CfgFileSize,1,pFileObj ))==0) { Debug("Read cfg file error!\n\r"); FS_FClose(pFileObj); return; } //Debug("Cfg content:\n\r%s\n\r",Cfg); //关闭配置文件 if( FS_FClose(pFileObj) == -1 ) { Debug("Close file error\n"); return; } pCfg=FileBuf; //检查配置文件版本 if((pTmp=(void *)strstr((void *)pCfg,"#"))==NULL) return; if((pCfg=(void *)strstr((void *)pTmp,";"))==NULL) return; pTmp++; *pCfg++=0; if(strcmp((void *)pTmp,"m25p16 1.0")) { Debug("Cfg file %s version is error!(%s!=%s)\n\r",CfgPath,"m25p16 1.0",pTmp); return; } //检查配置项完整性 if((pTmp=(void *)strstr((void *)pCfg,"$"))==NULL) return; *pTmp++=0; //开始提取配置文件内容 while(1) { *pTmp='%';//恢复上一个扇区项 //先获取扇区项 if((pSecStart[CurSecItem]=(void *)strstr((void *)pCfg,"%"))==NULL) return; if((pSecEnd[CurSecItem]=(void *)strstr((void *)pSecStart[CurSecItem],"-"))==NULL) return; if((pCfg=(void *)strstr((void *)pSecEnd[CurSecItem],";"))==NULL) return; *pSecStart[CurSecItem]++=0; *pSecEnd[CurSecItem]++=0; *pCfg++=0; Debug("Current SectorItem:%d,SecStart:%s,SecEnd:%s\n\r",CurSecItem,pSecStart[CurSecItem],pSecEnd[CurSecItem]); SecStart=StrToUint((void *)pSecStart[CurSecItem]); SecEnd=StrToUint((void *)pSecEnd[CurSecItem]); if(SecStart>SecEnd) return;//扇区错误 if(SecEnd>31) return;//扇区错误 EarseSecFlag=0;//置0擦除标志 if((pTmp=(void *)strstr((void *)pCfg,"%"))!=NULL) *pTmp=0;//先屏蔽下一个扇区项 else pTmp=FileBuf; //再获取下载项 for(i=0; i<MaxDownItem; i++) { if((pBinPath[i]=(void *)strstr((void *)pCfg,"="))==NULL) return;//找到文件路径 if((pAddr[i]=(void *)strstr((void *)pBinPath[i],"@"))==NULL) return;//找到起始页数 if((pCfg=(void *)strstr((void *)pAddr[i],";"))==NULL) return;//找到本条结尾位置 *pBinPath[i]++=0; *pAddr[i]++=0; *pCfg++=0; Debug("=%s download to page %s\n\r",pBinPath[i],pAddr[i]); if(strstr((void *)pCfg,"=")==NULL) //也没有下一个下载项了 { i++; break; } } CurDownItemNum=i; Debug("Current DownItem Max Num:%d\n\r",CurDownItemNum); if(!ForceDownload) { for(i=0; i<CurDownItemNum; i++) { //打开bin文件 if ((pFileObj=FS_FOpen((void *)pBinPath[i], FA_OPEN_EXISTING | FA_READ)) ==0 ) { Debug("Cannot open file %s,Cancle download\n\r",pBinPath[i]); return; } //对比每个下载项文件和flash page的头16字节内容 if((ReadByte=FS_FRead((void *)PageBuf, sizeof(Buffer2), 1,pFileObj)) != 0) { if(ReadByte) { //读取spi flash内容进行匹配 Q_SpiFlashSync(FlashRead,SPI_FLASH_PAGE_SIZE*StrToUint((void *)pAddr[i]),sizeof(Buffer2),Buffer2); for(j=0; j<sizeof(Buffer2); j++) { //Debug("%x?=%x\n\r",Buffer2[j],Buffer[j]); if(Buffer2[j]!=PageBuf[j]) { EarseSecFlag=1; Debug("We need erase sectors becase of file %s first %d bytes.\n\r",pBinPath[i],sizeof(Buffer2)); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); goto Erase; } } //if(j==sizeof(Buffer2)) //{ // Debug("We needn't download file %s to spi flash\n\r",pBinPath[i]); //} } else //没有读到内容 { Debug("File %s is NULL,cancle download\n\r",pBinPath[i]); return; } } //对比每个下载项文件和flash page的尾16字节内容 FS_FSeek(pFileObj,-sizeof(Buffer2),FS_SEEK_END); if((ReadByte=FS_FRead((void *)PageBuf, sizeof(Buffer2), 1,pFileObj)) != 0) { if(ReadByte) { //读取spi flash内容进行匹配 Q_SpiFlashSync(FlashRead, SPI_FLASH_PAGE_SIZE*StrToUint((void *)pAddr[i])+FS_GetFileSize(pFileObj)-sizeof(Buffer2), sizeof(Buffer2),Buffer2); for(j=0; j<sizeof(Buffer2); j++) { //Debug("%x?=%x\n\r",Buffer2[j],Buffer[j]); if(Buffer2[j]!=PageBuf[j]) { EarseSecFlag=1; Debug("We need erase sectors becase of file %s last %d byte.\n\r",pBinPath[i],sizeof(Buffer2)); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); goto Erase; } } if(j==sizeof(Buffer2)) { Debug("We needn't download file %s to spi flash\n\r",pBinPath[i]); } } else //没有读到内容 { Debug("File %s is NULL,cancle download\n\r",pBinPath[i]); return; } } if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); } } Erase: //擦除扇区 if(EarseSecFlag||ForceDownload) { for(i=SecStart; i<=SecEnd; i++) { Debug("Erase sector %d(page %d to %d)\n\r",i,i<<8,(i<<8)+256); Q_SpiFlashSync(FlashSectorEarse,i<<16,0,NULL); } //烧录文件 for(i=0; i<CurDownItemNum; i++) { Debug("#Download %s ",pBinPath[i]); if ((pFileObj=FS_FOpen((void *)pBinPath[i], FA_OPEN_EXISTING | FA_READ)) == 0 ) { Debug("Cannot open file %s\n\r",pBinPath[i]); return; } for(ReadByte=0,j=StrToUint((void *)pAddr[i]);; j++) { if((ReadByte=FS_FRead((void *)PageBuf, SPI_FLASH_PAGE_SIZE, 1,pFileObj)) != 0) { //读到非0个数据 Q_SpiFlashSync(FlashWrite,j*SPI_FLASH_PAGE_SIZE,ReadByte,PageBuf); Debug("."); //显示进度条 } else //读到0个数据,说明读到文件末了 { break; } } Debug("\n\rHave Download \"%s\" to spi flash,from page %d to page %d\n\r",pBinPath[i],StrToUint((void *)pAddr[i]),j-1); if( FS_FClose(pFileObj) == -1 ) Debug("Close file %s error\n",pBinPath[i]); } } if(++CurSecItem==MaxSecItem) return;//下一个扇区项 } }
FS_i32 FS_FileCpy(const TCHAR*path1, const TCHAR*path2) //path1: souce file path2: destination file { FS_FILE *src; FS_FILE * dst; FS_i32 read_size,write_size; FS_i32 src_size, dst_size; struct stat buf; _DISK_INFO info; FS_i8 *buffer; if( !strcmp((const char *)path1, (const char *)path2) ) { FS_Debug("FSW_ERROR:can not copy a file to itself\r\n"); return 0; } if( -1 == FS_Stat( path1, &buf ) ) return 0; src_size = buf.st_size; if(GetDiskInfo(path2,&info)==-1) { FS_Debug("FSW_ERROR:getdiskinfo err\r\n"); return 0; } if(src_size > info.free_size) { FS_Debug("there is no enough space on the flash!\n\r"); return 0; } src = FS_FOpen(path1, FA_READ|FA_OPEN_EXISTING); if(0 == src) { FS_Debug("FSW_ERROR:cannot open the source file\r\n"); return 0; } dst = FS_FOpen(path2, FA_CREATE_ALWAYS|FA_WRITE); if(0 == dst) { FS_Debug("FSW_ERROR:cannot create the distance file\r\n"); FS_FClose(src); return 0; } buffer=Q_Mallco(COPY_FILE_BUFFER); do{ read_size = FS_FRead(buffer, COPY_FILE_BUFFER,1,src); write_size = FS_FWrite(buffer, read_size,1,dst); if(write_size < read_size) { FS_Debug("FSW_ERROR:file write error\r\n"); Q_Free(buffer); goto CP_FILE_ERROR; } }while(read_size == COPY_FILE_BUFFER); Q_Free(buffer); FS_FClose(src); FS_FClose(dst); if( -1 == FS_Stat( path2, &buf ) ) return 0; dst_size = buf.st_size; if(dst_size < src_size) { FS_Debug("there is an unkown flash operation during the copyfile!\n\r"); FS_Unlink(path2); return 0; } return 1; CP_FILE_ERROR: FS_FClose(src); FS_FClose(dst); return 0; }
byte * SCR_ReadNextFrame(void) { int r; int command; byte samples[22050 / 14 * 4]; byte compressed[0x20000]; int size; byte *pic; cblock_t in, huf1; int start, end, count; /* read the next frame */ r = FS_FRead(&command, 4, 1, cl.cinematic_file); if (r == 0) { /* we'll give it one more chance */ r = FS_FRead(&command, 4, 1, cl.cinematic_file); } if (r != 4) { return NULL; } command = LittleLong(command); if (command == 2) { return NULL; /* last frame marker */ } if (command == 1) { /* read palette */ FS_Read(cl.cinematicpalette, sizeof(cl.cinematicpalette), cl.cinematic_file); cl.cinematicpalette_active = 0; } /* decompress the next frame */ FS_Read(&size, 4, cl.cinematic_file); size = LittleLong(size); if (((unsigned long)size > sizeof(compressed)) || (size < 1)) { Com_Error(ERR_DROP, "Bad compressed frame size"); } FS_Read(compressed, size, cl.cinematic_file); /* read sound */ start = cl.cinematicframe * cin.s_rate / 14; end = (cl.cinematicframe + 1) * cin.s_rate / 14; count = end - start; FS_Read(samples, count * cin.s_width * cin.s_channels, cl.cinematic_file); if (cin.s_width == 2) { for (r = 0; r < count * cin.s_channels; r++) { ((short *)samples)[r] = LittleShort(((short *)samples)[r]); } } S_RawSamples(count, cin.s_rate, cin.s_width, cin.s_channels, samples, Cvar_VariableValue("s_volume")); in.data = compressed; in.count = size; huf1 = Huff1Decompress(in); pic = huf1.data; cl.cinematicframe++; return pic; }