# Bryan Schumaker (8/7/2010)

import libsaria
from libsaria import path
plugin = None
export = None

dev = ""
if libsaria.__dev__ == True:
	dev = "-dev"

def open_plugin(file):
	global plugin
	if plugin == None:
		from libsaria import plugin
	plugin.install(file)

def open_xml(file):
	global export
	if export == None:
		import export
	export.import_xml(file)

def open_music(file):
	try:
		from libsaria.sources import file as file_source
		file_source.load_file(file)
	except Exception, e:
		print e

mapping = {".py":open_plugin, ".xml":open_xml}
def universal_open(file):
	file = file.replace("%20", " ")
	file = file.replace("%22", "\"")
	if path.is_dir(file):
		libsaria.sources.new_source(file)
		return
	base, ext = path.splitext(file)
	func = mapping.get(ext, open_music)
	func(file)
