Exemple #1
0
/*
 * fopen() for a compressed file
 */
struct zfile *zfile_fopen (const char *name, const char *mode)
{
    struct zfile *l;
    FILE *f;
    char zipname[1000];

    if( *name == '\0' )
	return NULL;
    l = zfile_create ();
    l->name = strdup (name);
#ifdef SINGLEFILE
    if (zfile_opensinglefile (l))
	return l;
#endif
    f = openzip (l->name, zipname);
    if (f) {
	if (strcasecmp (mode, "rb")) {
	    zfile_fclose (l);
	    fclose (f);
	    return 0;
	}
	l->zipname = strdup (zipname);
    }
    if (!f) {
	f = fopen (name, mode);
	if (!f) {
	    zfile_fclose (l);
	    return 0;
	}
    }
    l->f = f;
    l = zuncompress (l);
    return l;
}
Exemple #2
0
void OpenAirfieldDetails() {
  TCHAR zfilename[MAX_PATH];

  zAirfieldDetails = NULL;

  _tcscpy(szAirfieldDetailsFile,szAirfieldFile);

  if (_tcslen(szAirfieldDetailsFile)>0) {
    ExpandLocalPath(szAirfieldDetailsFile);
    _tcscpy(zfilename, szAirfieldDetailsFile);
    _tcscpy(szAirfieldFile,_T(""));
  } else {
	#if 0
	LocalPath(zfilename, _T(KD_WAYPOINTS));
	_tcscat(zfilename, _T(DIRSEP));
	_tcscat(zfilename, _T(LKF_AIRFIELDS));
	#else
	_tcscpy(zfilename, _T(""));
	#endif
  }
  if (_tcslen(zfilename)>0) {
    StartupStore(_T(". open AirfieldFile <%s> %s"), zfilename, NEWLINE);
    zAirfieldDetails = openzip(zfilename, "rb");
  }
};
Exemple #3
0
static ZIP* cache_openzip(int pathtype, int pathindex, const char* zipfile) {
	ZIP* zip;
	unsigned i;

	/* search in the cache buffer */
	for(i=0;i<ZIP_CACHE_MAX;++i) {
		if (zip_cache_map[i] && zip_cache_map[i]->pathtype == pathtype && zip_cache_map[i]->pathindex == pathindex && strcmp(zip_cache_map[i]->zip,zipfile)==0) {
			/* found */
			unsigned j;

/*
			logerror("Zip cache HIT  for %s\n", zipfile);
*/

			/* reset the zip directory */
			rewindzip( zip_cache_map[i] );

			/* store */
			zip = zip_cache_map[i];

			/* shift */
			for(j=i;j>0;--j)
				zip_cache_map[j] = zip_cache_map[j-1];

			/* set the first entry */
			zip_cache_map[0] = zip;

			return zip_cache_map[0];
		}
	}
	/* not found */

/*
	logerror("Zip cache FAIL for %s\n", zipfile);
*/

	/* open the zip */
	zip = openzip( pathtype, pathindex, zipfile );
	if (!zip)
		return 0;

	/* close the oldest entry */
	if (zip_cache_map[ZIP_CACHE_MAX-1]) {
		/* close last zip */
		closezip(zip_cache_map[ZIP_CACHE_MAX-1]);
		/* reset the entry */
		zip_cache_map[ZIP_CACHE_MAX-1] = 0;
	}

	/* shift */
	for(i=ZIP_CACHE_MAX-1;i>0;--i)
		zip_cache_map[i] = zip_cache_map[i-1];

	/* set the first entry */
	zip_cache_map[0] = zip;

	return zip_cache_map[0];
}
Exemple #4
0
int zfile_exists (const char *name)
{
    char fname[2000];
    FILE *f;

    strcpy (fname, name);
    f = openzip (fname, 0);
    if (!f)
	f = fopen(name,"rb");
    if (!f)
	return 0;
    fclose (f);
    return 1;
}
Exemple #5
0
// nearly same as PicoCartLoad, but works with zipfiles
int CartLoadZip(const char *fname, unsigned char **prom, unsigned int *psize)
{
	unsigned char *rom=0;
	struct zipent* zipentry;
	int size;
	ZIP *zipfile = openzip(fname);

	if(!zipfile) return 1;

	// find first bin or smd
	while((zipentry = readzip(zipfile)) != 0)
	{
		char *ext;
		if(strlen(zipentry->name) < 5) continue;
		ext = zipentry->name+strlen(zipentry->name)-4;

		if(!strcasecmp(ext, ".bin") || !strcasecmp(ext, ".smd") || !strcasecmp(ext, ".gen")) break;
	}

	if(!zipentry) {
		closezip(zipfile);
		return 4; // no roms
	}

	size = zipentry->uncompressed_size;

	size=(size+3)&~3; // Round up to a multiple of 4

	// Allocate space for the rom plus padding
	rom=PicoCartAlloc(size);
	if (rom==NULL) { closezip(zipfile); return 2; }

	if(readuncompresszip(zipfile, zipentry, (char *)rom) != 0) {
		free(rom);
		rom = 0;
		closezip(zipfile);
		return 5; // unzip failed
	}

	closezip(zipfile);

	// Check for SMD:
	if ((size&0x3fff)==0x200) { DecodeSmd(rom,size); size-=0x200; } // Decode and byteswap SMD
	else Byteswap(rom,size); // Just byteswap

	if (prom)  *prom=rom;
	if (psize) *psize=size;

	return 0;
}
Exemple #6
0
int ident_zip(char *fn)
{
   ZIP* zip;
   struct zipent* zipf;
   printf("Zip file to ident = '%s'\n", fn);
   if ((zip = openzip(fn)) == 0) {
      printf("Error, cannot open zip file '%s' !\n", fn);
      return 1;
   };
   while (zipf = readzip(zip)) {
      upper_case(zipf->name);
      romident(zipf->name, zipf->crc32, zipf->uncompressed_size);
   };
   closezip(zip);
   return 0;
}
Exemple #7
0
/* this code tries opening the image as a raw ZIP file, and if relevant, returns the
 * zip file and the entry */
char *mess_try_image_file_as_zip(int pathindex, const char *path,
	const struct IODevice *dev)
{
	zip_file *zip = NULL;
	zip_entry *zipentry = NULL;
	char *name;
	const char *ext;
	int is_zip;
	char *new_path = NULL;
	char path_sep[2] = { PATH_SEPARATOR, '\0' };

	name = osd_basename((char *) path);
	if (!name)
		goto done;

	ext = strrchr(name, '.');
	is_zip = (ext && !mame_stricmp(ext, ".zip"));

	if (is_zip)
	{
		zip = openzip(FILETYPE_IMAGE, pathindex, path);
		if (!zip)
			goto done;
	
		while((zipentry = readzip(zip)) != NULL)
		{
			ext = strrchr(zipentry->name, '.');
			if (!dev || (ext && findextension(dev->file_extensions, ext)))
			{
				new_path = malloc(strlen(path) + 1 + strlen(zipentry->name) + 1);
				if (!new_path)
					goto done;
				strcpy(new_path, path);
				strcat(new_path, path_sep);
				strcat(new_path, zipentry->name);
				break;
			}
		}
	}

done:
	if (zip)
		closezip(zip);
	return new_path;
}
Exemple #8
0
void ReadWayPoints(void)
{
  #if TESTBENCH
  StartupStore(TEXT(". ReadWayPoints%s"),NEWLINE);
  #endif

  TCHAR szFile1[MAX_PATH] = TEXT("\0");
  TCHAR szFile2[MAX_PATH] = TEXT("\0");
        
  ZZIP_FILE *fp=NULL;

    LockTaskData();
    CloseWayPoints(); // BUGFIX 091104 duplicate waypoints entries
    InitVirtualWaypoints();	// 091103

    _tcscpy(szFile1,szWaypointFile);

    _tcscpy(szWaypointFile,_T(""));
      
    if (_tcslen(szFile1)>0) {
      ExpandLocalPath(szFile1);
      fp = openzip(szFile1, "rt");
    } else {
    }

    if(fp != NULL)
      {
        globalFileNum = 0;
        WpFileType[1]=ReadWayPointFile(fp, szFile1);
        zzip_fclose(fp);
        fp = 0;
        // read OK, so set the registry to the actual file name
        ContractLocalPath(szFile1);
	_tcscpy(szWaypointFile,szFile1);
      } else {
      StartupStore(TEXT("--- No waypoint file 1%s"),NEWLINE);
    }

  // read additional waypoint file

    // reset to empty until we verified it is existing
    _tcscpy(szFile2,szAdditionalWaypointFile);
    _tcscpy(szAdditionalWaypointFile,_T(""));

    if (_tcslen(szFile2)>0){
      ExpandLocalPath(szFile2);
      fp = openzip(szFile2, "rt");
      if(fp != NULL){
        globalFileNum = 1;
        WpFileType[2]=ReadWayPointFile(fp, szFile2);
        zzip_fclose(fp);
        fp = NULL;
        // read OK, so set the registry to the actual file name
        ContractLocalPath(szFile2);
	_tcscpy(szAdditionalWaypointFile,szFile2);
      } else {
        StartupStore(TEXT("--- No waypoint file 2%s"),NEWLINE);
      }
    }
	
    // each time we load WayPoint, we need to init WaypointCalc !!
    InitWayPointCalc();

  UnlockTaskData();

}
Exemple #9
0
/**
 * @brief Load language MSG file into memory
 *
 * @param fillup Switch value:
 *	- false - load from scratch removing anything existing
 *	-  true - load over existing messages, adding only missing items filling up gaps
 *
 * @return @c false if language file problem, in this case english is reloaded from calling function
 */
bool LKLoadMessages(bool fillup) {
  TCHAR sFile[MAX_PATH];
  TCHAR sPath[MAX_PATH];
  TCHAR suffix[20];
  #if DEBUG_GETTEXT
  int maxsize=0;
  #endif

  static bool doinit=true;

  if (doinit) {
    std::fill(std::begin(LKMessages), std::end(LKMessages), (TCHAR*)NULL);
	doinit=false;
  } else {
	if (!fillup) {
		// init data when reloading language files or changing it
		// but not in fillup mode of course
        LKUnloadMessage();
	}
  }

  LocalPath(sPath,_T(LKD_LANGUAGE));
  _tcscpy(suffix,_T("_MSG.TXT"));
  _stprintf(sFile,_T("%s%s%s%s"), sPath, _T(DIRSEP), LKLangSuffix, suffix);

  ZZIP_FILE *hFile = openzip(sFile, "rt");
	if (hFile == NULL) {
	StartupStore(_T("... LoadText Missing Language File: <%s>%s"),sFile,NEWLINE);
	return false;
  } else {
	if (fillup)
		StartupStore(_T(". Language fillup load file: <%s>%s"),sFile,NEWLINE);
	else
		StartupStore(_T(". Language load file: <%s>%s"),sFile,NEWLINE);
  }

  // search for beginning of code index, in the range _@M1_  _@M9999_
  TCHAR sTmp[300];
  TCHAR scapt[MAX_MESSAGE_SIZE+1];
  TCHAR scaptraw[MAX_MESSAGE_SIZE+1];

  bool havewarned=false;
  while (ReadULine(hFile, sTmp, array_size(sTmp))) {

	unsigned int slen=_tcslen(sTmp); // includes cr or lf or both
	if ( (slen<9) || (sTmp[0]!='_') || (sTmp[1]!='@') || (sTmp[2]!='M') ) {
        #if DEBUG_GETTEXT
        if(slen>0 && sTmp[0]!='#') {
            StartupStore(_T(".... MSG_ENG missing _@M line <%s>\n"),sTmp);
        }
        #endif
		continue;
	}

    // get the item index number, quick conversion from unicode
    unsigned short inumber = 0;
    for (unsigned int i = 0; i < slen - 4 && isdigit(sTmp[3 + i]); i++) {
        inumber = (inumber * 10) + ((char)sTmp[3 + i] - '0');
    }

	if (inumber >=MAX_MESSAGES) {
		if (!havewarned) {
			StartupStore(_T("...... ERROR LOADING NON-COMPATIBLE MSG FILE!%s"),NEWLINE);
			havewarned=true;
		}
		StartupStore(_T("...... MSG token <%d> over limit! <%s>%s"),inumber,sTmp,NEWLINE);
		continue;
	}

	int start=0;
	for (unsigned i=3; i<slen; i++) {
		if (sTmp[i]=='\"') {
			start=i;
			break;
		}
	}

	int end=0;
	if (start==0) {
		#if DEBUG_GETTEXT
		StartupStore(_T(".... MSG_ENG no start\n"));
		#endif
		continue;
	}
	for (unsigned i=start+1; i<slen; i++) {
		if (sTmp[i]=='\"') {
			sTmp[i]='\0';
			end=i;
			break;
		}
	}
	if (end==0) {
		#if DEBUG_GETTEXT
		StartupStore(_T(".... MSG_ENG no end <%s> start=%d\n"),sTmp,start);
		#endif
		continue;
	}
	int newlen;
	newlen=_tcslen(&sTmp[start+1]);
	if (newlen>MAX_MESSAGE_SIZE) {
		#if DEBUG_GETTEXT
		StartupStore(_T(".... MSG_ENG caption too big, len=%d\n"),newlen);
		#endif
		continue;
	}
	if (newlen==0) {
        #if DEBUG_GETTEXT
		StartupStore(_T(".... MSG_ENG TOKEN # %d : caption is empty, null text.\n"),inumber);
		#endif
		continue;
	}
    #if DEBUG_GETTEXT
	if (newlen>maxsize) maxsize=newlen;
    #endif

	// transcode special charcaters while loading from file
	TCHAR tcode;
	bool donetcode;
	_tcscpy(scaptraw,&sTmp[start+1]);
    unsigned j=0;
	for (unsigned i=0; i<_tcslen(scaptraw); i++) {
		donetcode=false;
		if (scaptraw[i] == '\\') {
			if ( (i+1) <_tcslen(scaptraw)) {
				switch(scaptraw[i+1]) {
					case 'n':
						tcode='\n';
						i++;
						break;
					case 'r':
						tcode='\r';
						i++;
						break;
					default:
						tcode='\\';
						break;
				}
				scapt[j++]=tcode;
				donetcode=true;
			}
		}
		if (!donetcode) {
			scapt[j++]=scaptraw[i];
		}
	}
	scapt[j]='\0';

	if (LKMessages[inumber]) {
		// only for debugging translations
		#if TESTBENCH
		if (!fillup)
			StartupStore(_T("... INVALID LANGUAGE MESSAGE INDEX <%d> duplicated!\n"),inumber);
		#endif
		continue;
	}
	#if TESTBENCH
	#if (WINDOWSPC>0)
	// CAUTION, on a PNA this would freeze the device if language file is not updated!
	// StartupStore is locking and unlocking threads at each run!!
	if (fillup)
		StartupStore(_T("... Fillup: message index %d is missing from translation\n"),inumber);
	#endif
	#endif

#ifndef UNICODE
    LKASSERT(ValidateUTF8(scapt));
#endif

	LKMessages[inumber] = (TCHAR *)malloc((_tcslen(scapt)+1)*sizeof(TCHAR));
	LKASSERT(LKMessages[inumber]!=NULL);
	_tcscpy(LKMessages[inumber],scapt);
	if (inumber>=MAX_MESSAGES) {
		#if TESTBENCH
		StartupStore(_T("... TOO MANY MESSAGES, MAX %d%s"), MAX_MESSAGES, NEWLINE);
		#endif
		break;
	}

  }
  zzip_fclose(hFile);
  return true;
}
Exemple #10
0
// _@Hnnnn@
// minimal: _@H1_  maximal: _@H1234_
// this function is not thread safe ...
const TCHAR *LKgethelptext(const TCHAR *TextIn) {

  static TCHAR sFile[MAX_PATH];
  static TCHAR sPath[MAX_PATH];
  static TCHAR sTmp[MAX_HELP+1];
  static TCHAR sHelp[MAX_HELP+1];

  bool foundnotfound=false;

  if (TextIn == NULL) return TextIn;
  short tlen=_tcslen(TextIn);
  if ( (tlen<5) || (TextIn[0]!='_') || (TextIn[1]!='@') || (TextIn[tlen-1]!='_') ) return TextIn;

    // get the item index number, quick conversion from unicode
    unsigned short inumber = 0;
    for (short i = 0; i < tlen - 4; i++) {
        inumber = (inumber * 10) + ((char)TextIn[3 + i] - '0');
    }

  // get the item index number, quick conversion from unicode

  #if DEBUG_GETTEXT
  StartupStore(_T(".... Help item TextIn=<%s> number=%d \n"),TextIn, inumber);
  #endif

  // get the type character
  char ttype = TextIn[2];
  TCHAR suffix[20];

  if (ttype=='H') {
	_tcscpy(suffix,_T("_HELP.TXT"));
	LocalPath(sPath,_T(LKD_LANGUAGE));
	_stprintf(sFile,_T("%s%s%s%s"),sPath, _T(DIRSEP), LKLangSuffix, suffix);

	// Help File, dynamically handled
	#if DEBUG_GETTEXT
	StartupStore(_T("... Open Language file type <%C>: <%s>%s"),ttype,sFile,NEWLINE);
	#endif

	TCHAR sNum[10];
	_stprintf(sNum,_T("%u"),inumber);

  ZZIP_FILE *helpFile = openzip(sFile, "rb");
	if (helpFile == NULL) {
		StartupStore(_T("... Missing HELP FILE <%s>%s"),sFile,NEWLINE);
		// we can only have one Help call at a time, from the user interface. Ok static sHelp.
		_stprintf(sHelp,_T("ERROR, help file not found:\r\n%s\r\nCheck configuration!"),sFile);
		return (sHelp);
	}

	// search for beginning of code index   @000
	bool found=false;
	while (ReadULine(helpFile, sTmp, array_size(sTmp))) {
		unsigned slen=_tcslen(sTmp); // includes cr or lf or both
		if (slen<3|| slen>8) {
			#if DEBUG_GETTEXT
			StartupStore(_T("... skip line <3||>8 : %s\n"),sTmp);
			#endif
			continue;
		}

		if (sTmp[0]=='#') {
			#if DEBUG_GETTEXT
			StartupStore(_T("... skip remark: %s\n"),sTmp);
			#endif
			continue;
		}
		if (sTmp[0]=='@') {
			for (unsigned i=1; i<slen; i++) {
				if ( sTmp[i] < '0' || sTmp[i] > '9' )  {
					sTmp[i] = '\0';
					break;
				}
			}
			// sTmp[slen-1]='\0'; // remove cr
			if ( _tcscmp(&sTmp[1],sNum) == 0 ) {
				#if DEBUG_GETTEXT
				StartupStore(_T("... found correct index: %s\n"),sTmp);
				#endif
				found=true;
				break;
			} else {
				// this one should be the very last line in the help file
				if ( _tcscmp(&sTmp[1],_T("9999")) == 0 ) {
					foundnotfound=true;
					#if DEBUG_GETTEXT
					StartupStore(_T("... found NOTFOUND index: %s\n"),&sTmp[1]);
					#endif
					// warning this means that placing 9999 not at the end of HELP file will
					// make all other messages ignored! always check HELP file to have 9999 at the end
					break;
				} else {
					#if DEBUG_GETTEXT
					StartupStore(_T("... found wrong index: %s not %s\n"),&sTmp[1],sNum);
					#endif
				}
			}
		}
	}
	if (!found && !foundnotfound) {
		#if DEBUG_GETTEXT
		StartupStore(_T("... index <%s> not found in help file <%s>\n"),sNum,sFile);
		#endif
		_stprintf(sHelp,_T("ERROR: index <%s> not found in language help file:\r\n%s\r\n"),sNum,sFile);
		zzip_fclose(helpFile);
		return (sHelp);
	}

	// now load the help text for this index
	_tcscpy(sHelp,_T(""));
	int hlen=0;
	while (ReadULine(helpFile, sTmp, array_size(sTmp))) {

		int slen=_tcslen(sTmp); // including cr or lf or both
		if (slen==0 || sTmp[0]=='#') continue;
		if (slen>2 && slen<9) {
			// is it another index marker?
			if (sTmp[0]=='@') {
				if (hlen==0)
					continue; // multihelp section, continue loading help
				else
					break; // another marker, close the help
			}
		}
		if ( sTmp[slen-1]=='\r' ) {
			sTmp[slen-1]='\0';
			slen--;
		}

		// add it to the help, if possible
		if ( (hlen+slen+2) > MAX_HELP) {
			#if DEBUG_GETTEXT
			StartupStore(_T("... help too long: truncating line <%s>\n"),sTmp);
			#endif
			_tcsncat(sHelp,sTmp,MAX_HELP-hlen-1);
			break;
		}

		hlen+=slen;
		#if DEBUG_GETTEXT
		//StartupStore(_T(".. adding line <%s>\n"),sTmp);
		#endif
		_tcscat(sHelp,sTmp);
		_tcscat(sHelp,_T("\r\n"));
	}

	zzip_fclose(helpFile);
	return (sHelp);

  } // end ttype == H

  StartupStore(_T(".... Unknown Text type <%c> in <%s>%s"),ttype,TextIn,NEWLINE);
  return TextIn;

}
Exemple #11
0
void LKReadLanguageFile(const TCHAR* szFileName) {
  static TCHAR oldLang[4];

  if (DoInit[MDI_READLANGUAGEFILE]) {
	_tcscpy(LKLangSuffix,_T(""));
	_tcscpy(oldLang,_T("XXX"));
	DoInit[MDI_READLANGUAGEFILE]=false;
  }

  bool english=false;
  TCHAR szFile1[MAX_PATH] = _T("\0");
  _tcscpy(LKLangSuffix,_T(""));
  _tcscpy(szFile1,szFileName);
  tryeng:
  if (_tcslen(szFile1)==0) {
	_tcscpy(szFile1,_T("%LOCAL_PATH%\\\\_Language\\ENGLISH.LNG"));
	english=true;
  }
  ExpandLocalPath(szFile1);
  // SetRegistryString(szRegistryLanguageFile, TEXT("\0")); // ?

  ZZIP_FILE *langFile = openzip(szFile1, "rt");
  if (langFile == NULL) {
	if (english) {
		StartupStore(_T("--- CRITIC, NO ENGLISH LANGUAGE FILES!%s"),NEWLINE);
		// critic point, no default language! BIG PROBLEM here!
	} else {
		StartupStore(_T("--- NO LANGUAGE FILE FOUND <%s>, retrying with ENGlish!%s"),szFile1,NEWLINE);
		_tcscpy(szFile1,_T(""));
		goto tryeng;
	}
	return;
  }

  bool found=false;
  TCHAR sTmp[200];
  TCHAR mylang[30];
  while (ReadULine(langFile, sTmp, array_size(sTmp))) {
	if (_tcslen(sTmp)<3) continue;
	if ((sTmp[0]=='L')&&(sTmp[1]=='=')) {
		_tcscpy(mylang,&sTmp[2]);

		for (unsigned short i=0; i<_tcslen(mylang); i++) {
			if (mylang[i]=='\r' || mylang[i]=='\n') {
				mylang[i]='\0';
				break;
			}
		}
		found=true;
		break;
	}
  }

  if (found) {
	if (_tcslen(mylang)>3) mylang[3]='\0';
	_tcscpy(LKLangSuffix,mylang);
  }

  if (_tcscmp(oldLang,LKLangSuffix)!=0) {

	if ( !LKLoadMessages(false) ) {
		// force reload of english
		if (_tcscmp(_T("ENG"),LKLangSuffix) == 0 ) {
			StartupStore(_T("... CRITICAL, no english langauge available!%s"),NEWLINE);
		} else {
			StartupStore(_T("... LoadText failed, fallback to english language\n"));
			_tcscpy(LKLangSuffix,_T("ENG"));
			LKLoadMessages(false);
		}
	} else  {
		_tcscpy(oldLang,mylang);
		// Now overload english messages filling gaps in translations
		// only if current lang is not english of course: no reason to load it twice
		if (_tcscmp(_T("ENG"),LKLangSuffix) != 0 ) {
			_tcscpy(LKLangSuffix,_T("ENG"));
			LKLoadMessages(true);
			_tcscpy(LKLangSuffix,oldLang);
		}
	}
  }
  zzip_fclose(langFile);

  FillDataOptions(); // Load infobox list
  return;
}
Exemple #12
0
static mame_file *image_fopen_custom(mess_image *img, int filetype, int read_or_write)
{
	const char *sysname;
	char *lpExt;
	const game_driver *gamedrv = Machine->gamedrv;

	assert(img);

	if (!img->name)
		return NULL;

	if (img->fp)
	{
		/* If already open, we won't open the file again until it is closed. */
		return NULL;
	}

	do
	{
		sysname = gamedrv->name;
		logerror("image_fopen: trying %s for system %s\n", img->name, sysname);

		img->fp = mame_fopen(sysname, img->name, filetype, read_or_write);

		if (img->fp && (read_or_write == OSD_FOPEN_READ))
		{
			lpExt = strrchr( img->name, '.' );
			if (lpExt && (mame_stricmp( lpExt, ".ZIP" ) == 0))
			{
				int pathindex;
				int pathcount = osd_get_path_count(filetype);
				zip_file *zipfile;
				zip_entry *zipentry;
				char *newname;
				char *name;
				char *zipname;
				const char *ext;
				const struct IODevice *dev;

				mame_fclose( img->fp );
				img->fp = NULL;

				dev = image_device(img);
				assert(dev);

				newname = NULL;

				zipname = image_malloc( img, strlen( sysname ) + 1 + strlen( img->name ) + 1 );
				if( osd_is_absolute_path( img->name ) )
				{
					strcpy( zipname, img->name );
				}
				else
				{
					strcpy( zipname, sysname );
					strcat( zipname, osd_path_separator() );
					strcat( zipname, img->name );
				}

				for (pathindex = 0; pathindex < pathcount; pathindex++)
				{
					zipfile = openzip(filetype, pathindex, zipname);
					if (zipfile)
					{
						zipentry = readzip(zipfile);
						while( zipentry )
						{
							/* mess doesn't support paths in zip files */
							name = osd_basename( zipentry->name );
							lpExt = strrchr(name, '.');
							if (lpExt)
							{
								lpExt++;

								ext = dev->file_extensions;
								while(*ext)
								{
									if( mame_stricmp( lpExt, ext ) == 0 )
									{
										if( newname )
										{
											image_freeptr( img, newname );
										}
										newname = image_malloc(img, strlen(img->name) + 1 + strlen(name) + 1);
										if (!newname)
											return NULL;

										strcpy(newname, img->name);
										strcat(newname, osd_path_separator());
										strcat(newname, name);
									}
									ext += strlen(ext) + 1;
								}
							}
							zipentry = readzip(zipfile);
						}
						closezip(zipfile);
					}
					if( !newname )
					{
						return NULL;
					}
					img->fp = mame_fopen(sysname, newname, filetype, read_or_write);
					if (img->fp)
					{
						image_freeptr(img, img->name);
						img->name = newname;
						break;
					}
				}
				image_freeptr( img, zipname );
			}
		}
		gamedrv = mess_next_compatible_driver(gamedrv);
	}
	while(!img->fp && gamedrv);

	if (img->fp)
	{
		logerror("image_fopen: found image %s for system %s\n", img->name, sysname);
		img->length = mame_fsize(img->fp);
		img->hash = NULL;
	}

	return img->fp;
}
Exemple #13
0
SHPTreeHandle msSHPDiskTreeOpen(const TCHAR* pszTree, int debug)
{
    TCHAR *pszFullname, *pszBasename;
    SHPTreeHandle	psTree;

    char		pabyBuf[16];
    int			i;
    char		bBigEndian;

    /* -------------------------------------------------------------------- */
    /*	Establish the byte order on this machine.			    */
    /* -------------------------------------------------------------------- */
    i = 1;
    if( *((uchar *) &i) == 1 )
        bBigEndian = MS_FALSE;
    else
        bBigEndian = MS_TRUE;

    /* -------------------------------------------------------------------- */
    /*	Initialize the info structure.					    */
    /* -------------------------------------------------------------------- */
    psTree = (SHPTreeHandle) malloc(sizeof(SHPTreeInfo));

    /* -------------------------------------------------------------------- */
    /*	Compute the base (layer) name.  If there is any extension	    */
    /*	on the passed in filename we will strip it off.			    */
    /* -------------------------------------------------------------------- */
    pszBasename = (TCHAR *) malloc((_tcslen(pszTree)+5) * sizeof(TCHAR) * 2);
    _tcscpy( pszBasename, pszTree );
    for( i = _tcslen(pszBasename)-1;
            i > 0 && pszBasename[i] != _T('.') && pszBasename[i] != _T('/') && pszBasename[i] != _T('\\');
            i-- ) {}

    if( pszBasename[i] == _T('.') )
        pszBasename[i] = _T('\0');

    /* -------------------------------------------------------------------- */
    /*	Open the .shp and .shx files.  Note that files pulled from	    */
    /*	a PC to Unix with upper case filenames won't work!		    */
    /* -------------------------------------------------------------------- */
    pszFullname = (TCHAR *) malloc((_tcslen(pszBasename) + _tcslen(_T(MS_INDEX_EXTENSION)) + 1) * sizeof(TCHAR) * 2);
    _stprintf( pszFullname, _T("%s%s"), pszBasename, _T(MS_INDEX_EXTENSION));

    if (FileExists(pszFullname))  // prevent codegurad warnings (open unexisting file for reading)
        psTree->zfp = openzip(pszFullname, "rb" );
    else
        psTree->zfp = NULL;


    msFree(pszBasename); // don't need these any more
    msFree(pszFullname);

    if( psTree->zfp == NULL ) {
        msFree(psTree);
        return( NULL );
    }

    zzip_fread( pabyBuf, 8, 1, psTree->zfp );

    memcpy( &psTree->signature, pabyBuf, 3 );
    if( strncmp(psTree->signature,"SQT",3) )
    {
        /* ---------------------------------------------------------------------- */
        /*     must check if the 2 first bytes equal 0 of max depth that cannot   */
        /*     be more than 65535. If yes, we must swap all value. The problem    */
        /*     here is if there's no Depth (bytea 5,6,7,8 in the file) all bytes  */
        /*     will be set to 0. So,we will test with the number of shapes (bytes */
        /*     1,2,3,4) that cannot be more than 65535 too.                       */
        /* ---------------------------------------------------------------------- */
#if MAPSHAPEERROR
        if (debug)
        {
            msDebug("WARNING in msSHPDiskTreeOpen(): %ls is in old index format "
                    "which has been deprecated.  It is strongly recommended to "
                    "regenerate it in new format.\n", pszTree);
        }
#endif
        if((pabyBuf[4] == 0 && pabyBuf[5] == 0 &&
                pabyBuf[6] == 0 && pabyBuf[7] == 0))
        {
            psTree->LSB_order = !(pabyBuf[0] == 0 && pabyBuf[1] == 0);
        }
        else
        {
            psTree->LSB_order = !(pabyBuf[4] == 0 && pabyBuf[5] == 0);
        }
        psTree->needswap = ((psTree->LSB_order) != (!bBigEndian));

        /* ---------------------------------------------------------------------- */
        /*     poor hack to see if this quadtree was created by a computer with a */
        /*     different Endian                                                   */
        /* ---------------------------------------------------------------------- */
        psTree->version = 0;
    }
    else
    {
        psTree->needswap = (( pabyBuf[3] == MS_NEW_MSB_ORDER ) ^ ( bBigEndian ));

        psTree->LSB_order = ( pabyBuf[3] == MS_NEW_LSB_ORDER );
        memcpy( &psTree->version, pabyBuf+4, 1 );
        memcpy( &psTree->flags, pabyBuf+5, 3 );

        zzip_fread( pabyBuf, 8, 1, psTree->zfp );
    }

    if( psTree->needswap ) SwapWord( 4, pabyBuf );
    memcpy( &psTree->nShapes, pabyBuf, 4 );

    if( psTree->needswap ) SwapWord( 4, pabyBuf+4 );
    memcpy( &psTree->nDepth, pabyBuf+4, 4 );

    return( psTree );
}