Update of /cvsroot/freevo/freevo/src/games
In directory sc8-pr-cvs1:/tmp/cvs-serv16051

Modified Files:
        genesisitem.py snesitem.py 
Added Files:
        zipped_rom.py 
Log Message:
zipped rom support for snes and genesis

--- NEW FILE: zipped_rom.py ---
#if 0 /*
# -----------------------------------------------------------------------
# zipped_rom.py - Handles game roms that are zipped
# -----------------------------------------------------------------------
# $Id: zipped_rom.py,v 1.1 2004/01/10 21:25:01 mikeruelle Exp $
#
# Notes:
# Todo:        
#
# -----------------------------------------------------------------------
# $Log: zipped_rom.py,v $
# Revision 1.1  2004/01/10 21:25:01  mikeruelle
# zipped rom support for snes and genesis
#
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al. 
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#   
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#   
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#   
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#   
# ----------------------------------------------------------------------- */
#endif

from zipfile import *
import os.path
from string import rfind, lower

def unzip_rom(file, ext_list):
    """
    Unzips a zipped ROM and returns the name of the unzipped file
    which is placed in /tmp, or returns simply the 'file' argument if it is not
    zipped. ext_list is a list of extensions that ROMS can use.
    Returns the name of the unzipped ROM, or None.
    """
    if is_zipfile(file):
        zip_file = ZipFile(file)
        info = zip_file.namelist()
        for f in info:
             ext_pos = rfind(f, '.')
             if ext_pos > -1:
                 ext = f[ext_pos+1:]
                 if lower(ext) in ext_list:
                     tmp_file = os.path.join('/tmp', os.path.basename(f))
                     content = zip_file.read(f)
                     unzipped_file = open(os.path.join('/tmp', tmp_file), 'w')
                     unzipped_file.write(content)
                     unzipped_file.close()
                     return tmp_file
    return None


Index: genesisitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/genesisitem.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** genesisitem.py      29 Dec 2003 22:30:35 -0000      1.4
--- genesisitem.py      10 Jan 2004 21:25:01 -0000      1.5
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.5  2004/01/10 21:25:01  mikeruelle
+ # zipped rom support for snes and genesis
+ #
  # Revision 1.4  2003/12/29 22:30:35  dischi
  # move to new Item attributes
***************
*** 64,67 ****
--- 67,74 ----
  from string import *
  from re import *
+ from zipped_rom import unzip_rom
+ 
+ # Extensions used by GENESIS ROMs
+ genesisromExtensions = ['smd', 'bin']
  
  class GenesisItem(Item):
***************
*** 73,77 ****
          romName = ''
  
!         genesisFile = open(file, 'rb')
          fileExt = lower(os.path.splitext(os.path.basename(file))[1])
          if  fileExt == '.bin':
--- 80,90 ----
          romName = ''
  
!         genesisFile = None
!         unzipped = unzip_rom(file, genesisromExtensions)
!         if unzipped:
!             genesisFile = open(unzipped, 'rb')
!         else:
!             genesisFile = open(file, 'rb')
! 
          fileExt = lower(os.path.splitext(os.path.basename(file))[1])
          if  fileExt == '.bin':
***************
*** 86,89 ****
--- 99,105 ----
          else:
              romName = os.path.splitext(os.path.basename(file))[0]
+         genesisFile.close()
+         if unzipped:
+             os.unlink(unzipped)
          # Some guys modify the internal rom name with som crap -> detect it now
          if lower(romName[0:6]) == 'dumped' or lower(romName[0:6]) == 'copied':

Index: snesitem.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/games/snesitem.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** snesitem.py 29 Dec 2003 22:30:35 -0000      1.13
--- snesitem.py 10 Jan 2004 21:25:01 -0000      1.14
***************
*** 10,13 ****
--- 10,16 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.14  2004/01/10 21:25:01  mikeruelle
+ # zipped rom support for snes and genesis
+ #
  # Revision 1.13  2003/12/29 22:30:35  dischi
  # move to new Item attributes
***************
*** 68,71 ****
--- 71,78 ----
  from string import *
  from re import *
+ from zipped_rom import unzip_rom
+ 
+ # Extensions used by SNES ROMs
+ snesromExtensions = ['smc', 'sfc', 'fig']
  
  # Used to detect the internal rome information, as described in 'SNESKART.DOC v1.3'
***************
*** 215,220 ****
          self.mode  = 'file'            # file, dvd or vcd
          self.filename = file
  
-         snesFile = open(file, 'rb')
          for offset in snesromFileOffset:
              snesFile.seek(offset)
--- 222,233 ----
          self.mode  = 'file'            # file, dvd or vcd
          self.filename = file
+         
+         snesFile = None
+         unzipped = unzip_rom(file, snesromExtensions)
+         if unzipped:
+             snesFile = open(unzipped, 'rb')
+         else:
+             snesFile = open(file, 'rb')
  
          for offset in snesromFileOffset:
              snesFile.seek(offset)
***************
*** 237,240 ****
--- 250,256 ----
                      break
          snesFile.close()
+         if unzipped:
+             os.unlink(unzipped)
+ 
          if DEBUG:
              print 'SNES rom name : %s - %s -> %s' % 
(ord(romCountry),os.path.basename(file), romName)




-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to