diff --git a/GUI/VenPri.py b/GUI/VenPri.py index e648f4f..e7cfa8a 100644 --- a/GUI/VenPri.py +++ b/GUI/VenPri.py @@ -327,6 +327,18 @@ class Unpacking(Thread): self.qobject.emit(SIGNAL("Exception"),e) self.qobject.emit(SIGNAL("Done")) +class UnpackingCLI(Thread): + def __init__(self, wadpath, dirpath): + Thread.__init__(self) + self.wadpath = wadpath + self.dirpath = dirpath + def run(self): + try: + WAD.loadFile(self.wadpath).dumpDir(self.dirpath) + except Exception, e: + print e + print "Done" + class Packing(Unpacking): def __init__(self, dirpath, wadpath, QMW, deletedir = False): Unpacking.__init__(self, wadpath, dirpath, QMW) @@ -350,6 +362,25 @@ class Packing(Unpacking): self.qobject.emit(SIGNAL("Exception"),e) self.qobject.emit(SIGNAL("Done")) +class PackingCLI(UnpackingCLI): + def __init__(self, dirpath, wadpath, deletedir = False): + UnpackingCLI.__init__(self, wadpath, dirpath) + self.deletedir = deletedir + def run(self): + try: + print self.dirpath + print self.wadpath + WAD.loadDir(self.dirpath).dumpFile(self.wadpath) + if self.deletedir: + print "Cleaning temporary files" + rmtree(self.dirpath) + except Exception, e: + if self.deletedir: + print "Cleaning temporary files" + rmtree(self.dirpath) + print e + print "Done" + class nusDownloading(Unpacking): def __init__(self, titleid, version, outputdir, decrypt, QMW): Unpacking.__init__(self, None, outputdir, QMW) @@ -376,6 +407,29 @@ class nusDownloading(Unpacking): self.qobject.emit(SIGNAL("Exception"),Errormsg) self.qobject.emit(SIGNAL("Done")) +class nusDownloadingCLI(UnpackingCLI): + def __init__(self, titleid, version, outputdir, decrypt, pack): + UnpackingCLI.__init__(self, None, outputdir) + if version != None: + self.version = int(version) + else: + self.version = None + self.decrypt = decrypt + self.titleid = titleid + self.pack = pack + self.outputdir = outputdir + def run(self): + try: + if self.pack: + self.dirpath = tempfile.gettempdir() + "/NUS_"+ str(time.time()).replace(".","") + NUS(self.titleid, self.version).download(self.dirpath, decrypt = False) + self.packing = PackingCLI(self.dirpath, str(self.outputdir), True) + self.packing.start() + else: + NUS(self.titleid,self.version).download(self.dirpath, decrypt = self.decrypt) + except Exception, e: + print e + #Statusbar messages #FIXME: Why don't they get translated? It's frustrating DOWNLOADING = QT_TR_NOOP("Downloading files from NUS... This may take a while, please, be patient.") diff --git a/Qwad.pyw b/Qwad.pyw index ee2c104..932ad38 100644 --- a/Qwad.pyw +++ b/Qwad.pyw @@ -1,25 +1,64 @@ #!/usr/bin/env python #coding=utf-8 import sys -import optparse +from optparse import OptionParser +from optparse import Option, OptionValueError from PyQt4.QtGui import QApplication from PyQt4.QtCore import QTranslator, QString, QLocale from GUI.VenPri import MWQwad +from GUI.VenPri import nusDownloadingCLI +from TitleIDs import TitleDict -parser = optparse.OptionParser("qwad