0

textures: be more resilient against corrupted jars

This commit is contained in:
Nicolas F
2020-10-04 19:45:39 +02:00
parent 01ed588278
commit 47a0604b5a

View File

@@ -184,6 +184,26 @@ class Textures(object):
"""
if verbose: logging.info("Starting search for {0}".format(filename))
# Look for the file is stored in with the overviewer
# installation. We include a few files that aren't included with Minecraft
# textures. This used to be for things such as water and lava, since
# they were generated by the game and not stored as images. Nowdays I
# believe that's not true, but we still have a few files distributed
# with overviewer.
# Do this first so we don't try all .jar files for stuff like "water.png"
programdir = util.get_program_path()
if verbose: logging.info("Looking for texture in overviewer_core/data/textures")
path = os.path.join(programdir, "overviewer_core", "data", "textures", filename)
if os.path.isfile(path):
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode)
elif hasattr(sys, "frozen") or imp.is_frozen("__main__"):
# windows special case, when the package dir doesn't exist
path = os.path.join(programdir, "textures", filename)
if os.path.isfile(path):
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode)
# A texture path was given on the command line. Search this location
# for the file first.
if self.find_file_local_path:
@@ -228,7 +248,6 @@ class Textures(object):
# Look in the location of the overviewer executable for the given path
programdir = util.get_program_path()
path = os.path.join(programdir, filename)
if os.path.isfile(path):
if verbose: logging.info("Found %s in '%s'", filename, path)
@@ -297,34 +316,20 @@ class Textures(object):
jarpath = os.path.join(versiondir, jarname, jarname + ".jar")
if os.path.isfile(jarpath):
jar = zipfile.ZipFile(jarpath)
try:
jar = zipfile.ZipFile(jarpath)
jar.getinfo(filename)
if verbose: logging.info("Found %s in '%s'", filename, jarpath)
self.jars[jarpath] = jar
return jar.open(filename)
except (KeyError, IOError) as e:
pass
except (zipfile.BadZipFile) as e:
logging.warning("Your jar {0} is corrupted, I'll be skipping it, but you "
"should probably look into that.".format(jarpath))
if verbose: logging.info("Did not find file {0} in jar {1}".format(filename, jarpath))
# Last ditch effort: look for the file is stored in with the overviewer
# installation. We include a few files that aren't included with Minecraft
# textures. This used to be for things such as water and lava, since
# they were generated by the game and not stored as images. Nowdays I
# believe that's not true, but we still have a few files distributed
# with overviewer.
if verbose: logging.info("Looking for texture in overviewer_core/data/textures")
path = os.path.join(programdir, "overviewer_core", "data", "textures", filename)
if os.path.isfile(path):
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode)
elif hasattr(sys, "frozen") or imp.is_frozen("__main__"):
# windows special case, when the package dir doesn't exist
path = os.path.join(programdir, "textures", filename)
if os.path.isfile(path):
if verbose: logging.info("Found %s in '%s'", filename, path)
return open(path, mode)
raise TextureException("Could not find the textures while searching for '{0}'. Try specifying the 'texturepath' option in your config file.\nSet it to the path to a Minecraft Resource pack.\nAlternately, install the Minecraft client (which includes textures)\nAlso see <http://docs.overviewer.org/en/latest/running/#installing-the-textures>\n(Remember, this version of Overviewer requires a 1.16-compatible resource pack)\n(Also note that I won't automatically use snapshots; you'll have to use the texturepath option to use a snapshot jar)".format(filename))