2012-11-11 11:09:15 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding=utf-8
|
2012-11-19 23:00:31 +01:00
|
|
|
import sys, os
|
2012-11-19 23:00:16 +01:00
|
|
|
from optparse import OptionParser
|
|
|
|
from optparse import Option, OptionValueError
|
2012-08-21 19:28:14 +02:00
|
|
|
from PyQt4.QtGui import QApplication
|
|
|
|
from PyQt4.QtCore import QTranslator, QString, QLocale
|
2012-11-25 13:44:20 +01:00
|
|
|
from GUI.VenPri import MWQwad, nusDownloadingCLI, PackingCLI, UnpackingCLI, ShowTMD
|
2012-11-25 19:31:25 +01:00
|
|
|
from TitleIDs import TitleDict, IOSdict, swap_dic, ChannelCLIDict, ChannelJAPDict, ChannelPALDict, ChannelUSADict, ChannelJAPVerDict, ChannelPALVerDict, ChannelUSAVerDict
|
2012-08-21 19:28:14 +02:00
|
|
|
|
2013-06-17 10:00:37 +02:00
|
|
|
if os.getenv("QWAD_X_DIR"):
|
|
|
|
os.chdir(os.getenv("QWAD_X_DIR"))
|
|
|
|
else:
|
|
|
|
os.chdir(os.getenv("HOME"))
|
|
|
|
|
2012-11-19 23:00:16 +01:00
|
|
|
class MultipleOption(Option):
|
|
|
|
ACTIONS = Option.ACTIONS + ("extend",)
|
|
|
|
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
|
|
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
|
|
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
2012-11-11 11:09:15 +01:00
|
|
|
|
2012-11-19 23:00:16 +01:00
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
|
|
if action == "extend":
|
|
|
|
values.ensure_value(dest, []).append(value)
|
|
|
|
else:
|
|
|
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
2012-11-11 11:09:15 +01:00
|
|
|
|
2013-06-17 10:00:37 +02:00
|
|
|
VERSION = '0.7'
|
2012-11-11 11:09:15 +01:00
|
|
|
|
2012-11-24 20:41:47 +01:00
|
|
|
def opts():
|
2012-11-19 23:03:01 +01:00
|
|
|
description = """NUS-Downloader, WadManager and TMD-Viewer for Linux"""
|
2012-11-19 23:00:16 +01:00
|
|
|
parser = OptionParser(option_class=MultipleOption,
|
|
|
|
usage='usage: qwad [OPTIONS] ARGUMENT',
|
|
|
|
description=description)
|
2012-11-19 23:11:25 +01:00
|
|
|
parser.add_option('-d', '--download',
|
2012-11-19 23:00:16 +01:00
|
|
|
action="extend", type="string",
|
|
|
|
dest='download',
|
|
|
|
metavar='Arguments',
|
2012-11-25 11:49:09 +01:00
|
|
|
help="IOS Version Output Decrypt Pack")
|
|
|
|
parser.add_option('-u', "--unpack", dest="unpack", action="extend",
|
|
|
|
type="string", metavar='Arguments', help="unpack a WAD")
|
2012-11-25 11:58:04 +01:00
|
|
|
parser.add_option('-p', "--pack", dest="pack", action="extend",
|
|
|
|
type="string", metavar='Arguments', help="pack folder as WAD")
|
2012-11-19 23:11:25 +01:00
|
|
|
parser.add_option('-g', "--getversions", dest="getversions",
|
|
|
|
action="store_true", default=False, help="get available versions for IOS")
|
2012-11-19 23:14:00 +01:00
|
|
|
parser.add_option('-c', "--convert", dest="convert",
|
2012-11-25 13:44:20 +01:00
|
|
|
action="store_true", default=False, help="convert between IOSxx and hex-value")
|
|
|
|
parser.add_option('-t', "--tmdinfo", default=False, dest="tmdinfo", action="store_true",
|
|
|
|
help="Show infos provided by TMD file")
|
2012-11-19 23:00:16 +01:00
|
|
|
parser.add_option("-v", "--version", dest="version",
|
|
|
|
action="store_true", default=False, help="print version and exit")
|
2012-11-11 11:09:15 +01:00
|
|
|
|
2012-11-19 23:00:16 +01:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if options.version:
|
|
|
|
print "%s" % VERSION
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if options.download:
|
2012-11-25 19:31:25 +01:00
|
|
|
if args[0] is "0":
|
|
|
|
args[0] = None
|
|
|
|
if "." in str(options.download[0]):
|
|
|
|
dld = ChannelCLIDict[str(options.download[0][:-4])]
|
|
|
|
reg = str(options.download[0][-3:])
|
|
|
|
if "pal" in reg or "PAL" in reg:
|
|
|
|
xarg = ChannelPALDict[str(dld)]
|
|
|
|
elif "usa" in reg or "USA" in reg:
|
|
|
|
xarg = ChannelUSADict[str(dld)]
|
|
|
|
elif "jap" in reg or "JAP" in reg:
|
|
|
|
xarg = ChannelJAPDict[str(dld)]
|
|
|
|
else:
|
|
|
|
print "specified region %s is invalid" % reg
|
|
|
|
sys.exit(1)
|
|
|
|
nusdow = nusDownloadingCLI(int(str(xarg).lower(),16), args[0], args[1], args[2], args[3])
|
|
|
|
elif "IOS" in str(options.download[0]) or "BC" in str(options.download[0]) or "MIOS" in str(options.download[0]):
|
|
|
|
xarg = TitleDict[str(options.download[0])]
|
|
|
|
nusdow = nusDownloadingCLI(int(str(xarg).lower(),16), args[0], args[1], args[2], args[3])
|
|
|
|
else:
|
2013-06-17 10:00:37 +02:00
|
|
|
nusdow = nusDownloadingCLI(int(str(options.download[0]).lower(),16), args[0], args[1], args[2], args[3])
|
2012-11-25 19:31:25 +01:00
|
|
|
nusdow.start()
|
|
|
|
sys.exit(0)
|
2012-11-19 23:00:16 +01:00
|
|
|
|
2012-11-19 23:11:25 +01:00
|
|
|
if options.getversions:
|
2012-11-25 19:31:25 +01:00
|
|
|
if "." in str(args[0]):
|
|
|
|
dld = ChannelCLIDict[str(args[0][:-4])]
|
|
|
|
reg = str(args[0][-3:])
|
|
|
|
if "pal" in reg or "PAL" in reg:
|
|
|
|
xarg = ChannelPALVerDict[str(dld)]
|
|
|
|
elif "usa" in reg or "USA" in reg:
|
|
|
|
xarg = ChannelUSAVerDict[str(dld)]
|
|
|
|
elif "jap" in reg or "JAP" in reg:
|
|
|
|
xarg = ChannelJAPVerDict[str(dld)]
|
|
|
|
else:
|
|
|
|
print "specified region %s is invalid" % reg
|
|
|
|
sys.exit(1)
|
|
|
|
print "Available Versions for %s: %s" % (dld, xarg)
|
|
|
|
elif "IOS" in str(args[0]) or "BC" in str(args[0]) or "MIOS" in str(args[0]):
|
|
|
|
print "Available Versions for %s: %s" % (str(args[0]), IOSdict[str(args[0])])
|
|
|
|
else:
|
|
|
|
NewDict = swap_dic(TitleDict)
|
|
|
|
xarg = NewDict[str(args[0])]
|
|
|
|
print "Available Versions for %s: %s" % (str(args[0]), IOSdict[str(xarg)])
|
|
|
|
sys.exit(0)
|
2012-11-19 23:11:25 +01:00
|
|
|
|
2012-11-19 23:14:00 +01:00
|
|
|
if options.convert:
|
2012-11-25 19:31:25 +01:00
|
|
|
if "." in str(args[0]):
|
|
|
|
dld = ChannelCLIDict[str(args[0][:-4])]
|
|
|
|
reg = str(args[0][-3:])
|
|
|
|
if "pal" in reg or "PAL" in reg:
|
|
|
|
xarg = ChannelPALDict[str(dld)]
|
|
|
|
elif "usa" in reg or "USA" in reg:
|
|
|
|
xarg = ChannelUSADict[str(dld)]
|
|
|
|
elif "jap" in reg or "JAP" in reg:
|
|
|
|
xarg = ChannelJAPDict[str(dld)]
|
|
|
|
else:
|
|
|
|
print "specified region %s is invalid" % reg
|
|
|
|
sys.exit(1)
|
|
|
|
print "%s == %s" % (dld, xarg)
|
|
|
|
elif "IOS" in str(args[0]) or "BC" in str(args[0]) or "MIOS" in str(args[0]):
|
|
|
|
print "%s == %s" % (str(args[0]), TitleDict[str(args[0])])
|
|
|
|
else:
|
|
|
|
NewDict = swap_dic(TitleDict)
|
|
|
|
xarg = NewDict[str(args[0])]
|
|
|
|
print "%s == %s" % (str(args[0]), xarg)
|
|
|
|
sys.exit(0)
|
2012-11-19 23:14:00 +01:00
|
|
|
|
2012-11-25 11:49:09 +01:00
|
|
|
if options.unpack:
|
2012-11-25 19:31:25 +01:00
|
|
|
if os.access(str(options.unpack[0]), os.R_OK):
|
|
|
|
wad = str(options.unpack[0])
|
|
|
|
else:
|
|
|
|
print "WAD file %s does not exist." % str(options.unpack[0])
|
|
|
|
sys.exit(1)
|
|
|
|
if os.access(str(args[0]), os.W_OK):
|
|
|
|
folder = str(args[0])
|
|
|
|
else:
|
|
|
|
os.mkdir(str(args[0]), 0755)
|
|
|
|
if os.access(str(args[0]), os.W_OK):
|
|
|
|
UnpackingCLI(wad, str(args[0])).start()
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print "Output folder %s not writeable." % str(args[0])
|
|
|
|
sys.exit(1)
|
2012-11-25 11:49:09 +01:00
|
|
|
|
2012-11-25 11:58:04 +01:00
|
|
|
if options.pack:
|
2012-11-25 19:31:25 +01:00
|
|
|
if os.access(str(options.pack[0]), os.R_OK):
|
|
|
|
folder = str(options.pack[0])
|
|
|
|
else:
|
|
|
|
print "Input folder %s not readable." % str(options.pack[0])
|
|
|
|
sys.exit(1)
|
|
|
|
if os.access(os.path.dirname(str(args[0])), os.W_OK):
|
2012-11-25 11:58:04 +01:00
|
|
|
PackingCLI(folder, str(args[0])).start()
|
|
|
|
sys.exit(0)
|
2012-11-25 19:31:25 +01:00
|
|
|
else:
|
|
|
|
print "Output file %s can't be created." % str(args[0])
|
|
|
|
sys.exit(1)
|
2012-11-25 11:58:04 +01:00
|
|
|
|
2012-11-25 13:44:20 +01:00
|
|
|
if options.tmdinfo:
|
|
|
|
if os.access(str(args[0]), os.R_OK):
|
|
|
|
ShowTMD(str(args[0]))
|
|
|
|
sys.exit(0)
|
|
|
|
else:
|
|
|
|
print "Can't access %s." % str(args[0])
|
|
|
|
sys.exit(1)
|
|
|
|
|
2012-11-24 20:41:47 +01:00
|
|
|
def main():
|
|
|
|
# load our own translations
|
2012-08-21 19:28:14 +02:00
|
|
|
translator = QTranslator()
|
|
|
|
translator.load(QString("i18n/Qwad_%1").arg(QLocale.system().name()))
|
2012-11-24 20:41:47 +01:00
|
|
|
# load Qt translations
|
2012-08-21 19:28:14 +02:00
|
|
|
qttranslator = QTranslator()
|
|
|
|
qttranslator.load(QString("qt_%1").arg(QLocale.system().name()))
|
2012-11-24 20:41:47 +01:00
|
|
|
# misc stuff
|
2012-08-21 19:28:14 +02:00
|
|
|
Vapp = QApplication(sys.argv)
|
2012-11-24 20:41:47 +01:00
|
|
|
Vapp.setOrganizationName("Nanolx")
|
2012-08-21 19:28:14 +02:00
|
|
|
Vapp.setApplicationName("Qwad")
|
|
|
|
Vapp.installTranslator(translator)
|
|
|
|
Vapp.installTranslator(qttranslator)
|
|
|
|
VentanaP = MWQwad()
|
|
|
|
VentanaP.show()
|
|
|
|
sys.exit(Vapp.exec_())
|
|
|
|
|
2012-11-19 23:00:16 +01:00
|
|
|
if __name__ == "__main__":
|
2012-11-24 20:41:47 +01:00
|
|
|
opts()
|
2012-11-19 23:00:16 +01:00
|
|
|
main()
|