# Path: processing_thread.py
# class processing(threading.Thread):
#     def __init__(self, progressbar , file):
#         super(processing, self).__init__()
#         self.progressbar = progressbar
#         self.progressbar.set_fraction(0.05)
#         self.file = file
# 
#     def run(self):
#         parent_dir =  os.path.abspath(os.path.join(__file__, os.pardir))
#         app_name =  self.path_leaf(os.path.splitext(self.file)[0])
#         dir = parent_dir + os.sep + app_name
#         os.mkdir(dir)
#         new_apk_dir = dir + os.sep + self.path_leaf(self.file)
#         
#         #copy apk to folder <apk_name> in the parent directory of this app.
#         copyfile(self.file, new_apk_dir)
#         
#         #copy after changing .apk extension to .zip
#         new_apk_zip = dir + os.sep + app_name + ".zip"
#         copyfile(new_apk_dir, new_apk_zip)
#         
#         #extracting zipfile
#         output_path = dir + os.sep + app_name
#         with zipfile.ZipFile(new_apk_zip, 'r') as z:
#             z.extractall(output_path)
#         
#         #moving classes.dex file to dex2jar folder
#         copyfile(output_path + os.sep +  "classes.dex", parent_dir + os.sep + dexjar + os.sep + dex2jar-0.0.9.15 + "classes.dex")
#         
#         #running dexjar command
#         
#         
#         
#     def path_leaf(self,path):
#         head, tail = ntpath.split(path)
#         return tail or ntpath.basename(head)


import sys
import os
import gtk
import threading
from processing_thread import processing
        self.show_all()

    def display_file_chooser(self, fileChooser):
        #creating apk chossing dialog
        dialog = gtk.FileChooserDialog("Open..", None,
                                        gtk.FILE_CHOOSER_ACTION_OPEN,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                         gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)
        filter = gtk.FileFilter()
        filter.set_name(".apk")
        filter.add_pattern("*.apk")
        dialog.add_filter(filter)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.file = dialog.get_filename()
            self.fileChooser.set_sensitive(False)
            self.progressbar.set_text(dialog.get_filename())
            self.next.set_sensitive(True)

        elif response == gtk.RESPONSE_CANCEL:
            print 'closed, no files selected'
        dialog.destroy()

    def decompile(self, button):
        if(self.file != ""):
            try:
                self.progressbar.set_text("Creating a new folder")
                print self.file

# Path: processing_thread.py
# class processing(threading.Thread):
#     def __init__(self, progressbar , file):
#         super(processing, self).__init__()
#         self.progressbar = progressbar
#         self.progressbar.set_fraction(0.05)
#         self.file = file
# 
#     def run(self):
#         parent_dir =  os.path.abspath(os.path.join(__file__, os.pardir))
#         app_name =  self.path_leaf(os.path.splitext(self.file)[0])
#         dir = parent_dir + os.sep + app_name
#         os.mkdir(dir)
#         new_apk_dir = dir + os.sep + self.path_leaf(self.file)
#         
#         #copy apk to folder <apk_name> in the parent directory of this app.
#         copyfile(self.file, new_apk_dir)
#         
#         #copy after changing .apk extension to .zip
#         new_apk_zip = dir + os.sep + app_name + ".zip"
#         copyfile(new_apk_dir, new_apk_zip)
#         
#         #extracting zipfile
#         output_path = dir + os.sep + app_name
#         with zipfile.ZipFile(new_apk_zip, 'r') as z:
#             z.extractall(output_path)
#         
#         #moving classes.dex file to dex2jar folder
#         copyfile(output_path + os.sep +  "classes.dex", parent_dir + os.sep + dexjar + os.sep + dex2jar-0.0.9.15 + "classes.dex")
#         
#         #running dexjar command
#         
#         
#         
#     def path_leaf(self,path):
#         head, tail = ntpath.split(path)
#         return tail or ntpath.basename(head)


# Path: apkdecompiler.py
import sys
import os
import gtk
import threading
from processing_thread import processing

        self.show_all()

    def display_file_chooser(self, fileChooser):
        #creating apk chossing dialog
        dialog = gtk.FileChooserDialog("Open..", None,
                                        gtk.FILE_CHOOSER_ACTION_OPEN,
                                        (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                                         gtk.STOCK_OPEN, gtk.RESPONSE_OK))
        dialog.set_default_response(gtk.RESPONSE_OK)
        filter = gtk.FileFilter()
        filter.set_name(".apk")
        filter.add_pattern("*.apk")
        dialog.add_filter(filter)

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            self.file = dialog.get_filename()
            self.fileChooser.set_sensitive(False)
            self.progressbar.set_text(dialog.get_filename())
            self.next.set_sensitive(True)

        elif response == gtk.RESPONSE_CANCEL:
            print 'closed, no files selected'
        dialog.destroy()

    def decompile(self, button):
        if(self.file != ""):
            try:
                self.progressbar.set_text("Creating a new folder")
                print self.file

                processing_thread = processing(self.progressbar, self.file)