//--------------------------------------------------------------------------- // This function pulls the raw compressed data out of the file and sticks it in the buffer // passed in. This way, we can load the textures directly from file to RAM and not // have to decompress them!! long FastFile::readFastRAW (long fastFileHandle, void *bfr, long size) { size; long result = 0; if ((fastFileHandle >= 0) && (fastFileHandle < numFiles) && files[fastFileHandle].inuse) { logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); if (size >= files[fastFileHandle].pfe->size) { result = fread(bfr,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (result != files[fastFileHandle].pfe->size) { //READ Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (result != files[fastFileHandle].pfe->size) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); result = fread(bfr,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } return result; } return FILE_NOT_OPEN; }
bool ForceGroupBar::setPilotVideo( const char* pVideo, MechWarrior* pPilot ) { if ( !pVideo ) { if ( ForceGroupIcon::bMovie ) { delete ForceGroupIcon::bMovie; ForceGroupIcon::bMovie = NULL; } else if ( ForceGroupIcon::pilotVideoTexture ) gos_DestroyTexture( ForceGroupIcon::pilotVideoTexture ); ForceGroupIcon::pilotVideoTexture = 0; ForceGroupIcon::pilotVideoPilot = 0; } else if (ForceGroupIcon::bMovie || ControlGui::instance->isMoviePlaying() || ForceGroupIcon::pilotVideoTexture || !prefs.pilotVideos) { // one already playing... // OR we don't want them playing. return 0; } else { for ( int i = 0; i < iconCount; i++ ) { if ( icons[i] && icons[i]->unit->getPilot() == pPilot ) { ForceGroupIcon::pilotVideoPilot = pPilot; FullPathFileName aviPath; aviPath.init( moviePath, pVideo, ".bik" ); if ( (frameRate > 15.0) && fileExists(aviPath) && prefs.pilotVideos) // This is about correct. Slower then this and movie has hard time keeping up! { //Update the RECT every frame. What if we shift Icons around cause someone died!! RECT vRect; vRect.left = icons[i]->bmpLocation[icons[i]->locationIndex][1].x; vRect.right = icons[i]->pilotLocation[icons[i]->locationIndex][2]; vRect.top = icons[i]->bmpLocation[icons[i]->locationIndex][3].y; vRect.bottom = icons[i]->bmpLocation[icons[i]->locationIndex][1].y; ForceGroupIcon::bMovie = new MC2Movie; ForceGroupIcon::bMovie->init(aviPath,vRect,true); } else // make a still texture { char realPilotName[9]; //Set everything to zero so the strncpy below doesn't go off into LALA land!! memset(realPilotName,0,9); strncpy(realPilotName,pPilot->getName(),8); FullPathFileName path; path.init( moviePath, realPilotName, ".tga" ); if (fileExists(path)) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, path, 0 ); else { char realMovieName[256]; char realMoviePath[1024]; _splitpath(path,NULL,realMoviePath,realMovieName,NULL); //Not in main installed directory and not in fastfile. Look on CD. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,realMoviePath); strcat(actualPath,realMovieName); strcat(actualPath,".tga"); bool fileThere = fileExists(actualPath); if (fileThere) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, actualPath, 0 ); bool openFailed = false; while (!fileThere) { openFailed = true; EnterWindowMode(); char data[2048]; char msg[1024]; char msg1[512]; char title[256]; cLoadString(IDS_MC2_movieMISSING,msg1,511); cLoadString(IDS_MC2_CDMISSING,msg,1023); cLoadString(IDS_MC2_MISSING_TITLE,title,255); sprintf(data,msg1,path,msg); DWORD result = MessageBox(NULL,data,title,MB_OKCANCEL | MB_ICONWARNING); if (result == IDCANCEL) { ExitGameOS(); return 1; } fileThere = fileExists(actualPath); if (fileThere) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, actualPath, 0 ); } if (openFailed && (Environment.fullScreen == 0) && prefs.fullScreen) EnterFullScreenMode(); } } break; } } } return 1; }
//--------------------------------------------------------------------------- long FastFile::open (char* fName) { //------------------------------------------------------------- long fNameLength = strlen(fName); fileName = new char [fNameLength+1]; //fileName = (char *)gos_Malloc(fNameLength+1); //magic 26092011 if (!fileName) return(NO_RAM_FOR_FILENAME); strncpy(fileName,fName,fNameLength+1); handle = fopen(fileName,"r"); if (handle != NULL) { logicalPosition = 0; fileSize(); //Sets Length } else { //Check on CD. They may not have been installed. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,fileName); handle = fopen(actualPath,"r"); if (handle == NULL) { //OPEN Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (handle == NULL) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } handle = fopen(actualPath,"r"); } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } else { logicalPosition = 0; fileSize(); //Sets Length } } //--------------------------------------------- //-- Read in ALL of the file names and offsets logicalPosition = fseek(handle,0,SEEK_SET); //--------------------------------------------- //-- First Long is Version Number of FastFile unsigned long result = 0; unsigned long version = 0; result = fread((&version),1,sizeof(long),handle); logicalPosition += sizeof(long); if (result != sizeof(long)) { long lastError = errno; return lastError; } if (version != FASTFILE_VERSION && version != FASTFILE_VERSION_LZ) return FASTFILE_VERSION; if (version == FASTFILE_VERSION_LZ) useLZCompress = true; //--------------------------------------------- //-- Second Long is number of filenames present. result = fread((&numFiles),1,sizeof(long),handle); logicalPosition += sizeof(long); if (result != sizeof(long)) { long lastError = errno; return lastError; } files = (FILE_HANDLE*)malloc(sizeof(FILE_HANDLE) * numFiles); for (long i=0;i<numFiles;i++) { files[i].pfe = (FILEENTRY *)malloc(sizeof(FILEENTRY)); memset(files[i].pfe,0,sizeof(FILEENTRY)); unsigned long result = 0; result = fread(files[i].pfe,1,sizeof(FILEENTRY),handle); files[i].inuse = FALSE; files[i].pos = 0; } return (result); }
//--------------------------------------------------------------------------- long FastFile::readFast (long fastFileHandle, void *bfr, long size) { size; long result = 0; if ((fastFileHandle >= 0) && (fastFileHandle < numFiles) && files[fastFileHandle].inuse) { logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); //ALL files in the fast file are now zLib compressed. NO EXCEPTIONS!! // This fixes a bug where the zLib Compressed version is the same length // as the raw version. Yikes but this is rare. Finally happened though! // -fs /* if (files[fastFileHandle].pfe->size == files[fastFileHandle].pfe->realSize) { result = fread(bfr,1,size,handle); logicalPosition += size; if (result != size) { long lastError = errno; return lastError; } } else //File is NOW zLib Compressed. Read In Appropriately */ { if (!LZPacketBuffer) { LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize); if (!LZPacketBuffer) return 0; } if ((long)LZPacketBufferSize < files[fastFileHandle].pfe->size) { LZPacketBufferSize = files[fastFileHandle].pfe->size; free(LZPacketBuffer); LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize); if (!LZPacketBuffer) return 0; } if (LZPacketBuffer) { result = fread(LZPacketBuffer,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; if (result != files[fastFileHandle].pfe->size) { //READ Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (result != files[fastFileHandle].pfe->size) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); result = fread(LZPacketBuffer,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } //-------------------------------------------------------- //USED to LZ Compress here. It is NOW zLib Compression. // We should not try to use old fastfiles becuase version check above should fail when trying to open!! unsigned long decompLength = 0; if (useLZCompress) { decompLength = LZDecomp((MemoryPtr)bfr,LZPacketBuffer,files[fastFileHandle].pfe->size); } else { decompLength = files[fastFileHandle].pfe->realSize; long error = uncompress((MemoryPtr)bfr,&decompLength,LZPacketBuffer,files[fastFileHandle].pfe->size); if (error != Z_OK) STOP(("Error %d UnCompressing File %s from FastFile %s",error,files[fastFileHandle].pfe->name,fileName)); } if ((long)decompLength != files[fastFileHandle].pfe->realSize) result = 0; else result = decompLength; } } return result; } return FILE_NOT_OPEN; }
//--------------------------------------------------------------------------- long File::open (const char* fName, FileMode _mode, long numChild) { gosASSERT( !isOpen() ); //------------------------------------------------------------- long fNameLength = strlen(fName); fileName = (char *)systemHeap->Malloc(fNameLength+1); gosASSERT(fileName != NULL); strncpy(fileName,fName,fNameLength+1); fileMode = _mode; _fmode = _O_BINARY; _strlwr(fileName); if (fileMode == CREATE) { handle = _creat(fileName,_S_IWRITE); if (handle == INVALID_HANDLE_VALUE) { lastError = errno; return lastError; } } else { //---------------------------------------------------------------- //-- First, see if file is in normal place. Useful for patches!! handle = _open(fileName,_O_RDONLY); //------------------------------------------ //-- Next, see if file is in fastFile. if (handle == INVALID_HANDLE_VALUE) { lastError = errno; fastFile = FastFileFind(fileName,fastFileHandle); if (!fastFile) { //Not in main installed directory and not in fastfile. Look on CD. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,fileName); handle = _open(actualPath,_O_RDONLY); if (handle == INVALID_HANDLE_VALUE) { bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (handle == INVALID_HANDLE_VALUE) { openFailed = true; //OK, check to see if the CD is actually present. // Do this by checking for tgl.fst on the CD Path. // If its there, the CD is present BUT the file is missing. // MANY files in MechCommander 2 are LEGALLY missing! // Tell it to the art staff. char testCDPath[2048]; strcpy(testCDPath,CDInstallPath); strcat(testCDPath,"tgl.fst"); DWORD findCD = fileExists(testCDPath); if (findCD == 1) //File exists. CD is in drive. Return 2 to indicate file not found. return 2; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } handle = _open(actualPath,_O_RDONLY); } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } if (logFileTraffic) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"FASTF Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } //--------------------------------------------------------------------- //-- FastFiles are all compressed. Must read in entire chunk into RAM //-- Then close fastfile!!!!! inRAM = TRUE; fileImage = (unsigned char *)malloc(fileSize()); if (fileImage) { fastFile->readFast(fastFileHandle,fileImage,fileSize()); physicalLength = getLength(); //------------------------------------ //-- Image is in RAM. Shut the file. //fastFile->closeFast(fastFileHandle); //fastFile = NULL; //fastFileHandle = -1; logicalPosition = 0; } return NO_ERR; } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } return(NO_ERR); }