Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitelisting of extensions for consoles #92

Merged
merged 17 commits into from
Oct 13, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ relative-exe-path=WinGens\gens-launcher.exe

[WinVisualBoyAdvance]
download-location=http://consolegrid.com/ice_emulators/WinVisualBoyAdvance.zip
relative-exe-path=WinVisualBoyAdvance\VisualBoyAdvance.exe
relative-exe-path=WinVisualBoyAdvance\VisualBoyAdvance.exe
2 changes: 1 addition & 1 deletion consoles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ emulator=

[Nintendo DS]
nickname=DS
emulator=
emulator=
27 changes: 22 additions & 5 deletions ice/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from rom import ROM

class Console():

@classmethod
def settings_consoles(self):
consoles = []
Expand All @@ -33,13 +34,17 @@ def settings_consoles(self):
nickname = name
if 'nickname' in console_data:
nickname = console_data['nickname']
console = Console(nickname, name)
extensions = ""
if 'extensions' in console_data:
extensions = console_data['extensions']
console = Console(nickname, name, extensions)
consoles.append(console)
return consoles

def __init__(self,shortname,fullname):
def __init__(self,shortname,fullname,extensions):
self.shortname = shortname
self.fullname = fullname
self.extensions = extensions
self.emulator = emulator_manager.lookup_emulator(self)
self.__create_directories_if_needed__()

Expand Down Expand Up @@ -67,7 +72,19 @@ def roms_directory(self):
C:\Users\Scott\Documents\ROMs\PS2
"""
return os.path.join(filesystem_helper.roms_directory(),self.shortname)


def valid_rom(self,path):
"""
This function determines if a given path is actually a valid ROM file.
If a list of extensions is supplied for this console, we check if the path has a valid extension
If no extensions are defined for this console, we just accept any file
"""

if self.extensions == "":
return True
extension = os.path.splitext(path)[1].lower()
return any(extension == ('.'+x.strip().lower()) for x in self.extensions.split(','))

def find_all_roms(self):
"""
Reads a list of all the ROMs from the appropriate directory for the
Expand All @@ -85,7 +102,7 @@ def find_all_roms(self):
# accidently added as well
if not pf.is_windows() and filename.startswith('.'):
continue
if self.emulator is not None and not self.emulator.valid_rom(file_path):
if self.emulator is not None and not self.valid_rom(file_path):
log_file("Ignoring Non-ROM file: %s" % file_path)
continue
roms.append(ROM(file_path,self))
Expand Down Expand Up @@ -113,4 +130,4 @@ def supported_consoles():
# Cache it for next time
supported_consoles.cached = sc
return supported_consoles.cached
supported_consoles.cached = None
supported_consoles.cached = None
12 changes: 1 addition & 11 deletions ice/emulators/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ def is_functional(self):
A basic emulator is always functional.
"""
return True

def valid_rom(self,path):
"""
This function determines if a given path is actually a valid ROM file.
There are many different file extensions that could be used as ROMs,
and it would be a pretty bad user experience if a valid rom got ignored
by Ice, so I will err on the side of "Valid". The exception to this is
bsnes, whose functionality should be described in it's class
"""
return True

@abc.abstractmethod
def command_string(self):
Expand Down Expand Up @@ -84,4 +74,4 @@ def replace_contents_of_file(self,file_path,replacement_function):
old_file.close()
# Replace file_path with new file
os.remove(file_path)
shutil.move(abs_path, file_path)
shutil.move(abs_path, file_path)