Ejemplo n.º 1
0
    def wiiload_button(self):
        ip, ok = QInputDialog.getText(self, 'WiiLoad IP Address',
                                      'Enter the IP address of your Wii:',
                                      QLineEdit.Normal)
        if not ok:
            return

        ip_match = wiiload.validate_ip_regex(ip)

        if ip_match is None:
            logging.warning('Invalid IP Address: ' + ip)
            QMessageBox.warning(self, 'Invalid IP Address',
                                'This IP address is invalid.')
            return

        self.app_name = self.ui.listAppsWidget.currentItem().text()
        self.status_message("Downloading " + self.app_name +
                            " from Open Shop Channel..")
        self.ui.progressBar.setValue(25)

        # download.get() cannot save to our own file-like object.
        # Alt fix: add a file parameter to write to instead?
        url = f"https://{HOST}/hbb/{self.app_name}/{self.app_name}.zip"
        r = requests.get(url)

        self.status_message("Preparing app...")
        self.ui.progressBar.setValue(40)

        zipped_app = io.BytesIO(r.content)
        zip_buf = io.BytesIO()

        # Our zip file should only contain one directory with the app data in it,
        # but the downloaded file contains an apps/ directory. We're removing that here.
        wiiload.organize_zip(zipped_app, zip_buf)

        # preparing
        prep = wiiload.prepare(zip_buf)

        file_size = prep[0]
        compressed_size = prep[1]
        chunks = prep[2]

        # connecting
        self.status_message('Connecting to the HBC...')
        self.ui.progressBar.setValue(50)

        try:
            conn = wiiload.connect(ip)
        except socket.error as e:
            logging.error(
                'Error while connecting to the HBC. Please check the IP address and try again.'
            )
            QMessageBox.warning(
                self, 'Connection error',
                'Error while connecting to the HBC. Please check the IP address and try again.'
            )
            print(f'WiiLoad: {e}')
            self.ui.progressBar.setValue(0)
            self.status_message(
                'Error: Could not connect to the Homebrew Channel. :(')

            return

        wiiload.handshake(conn, compressed_size, file_size)

        # Sending file
        self.status_message('Sending app...')

        chunk_num = 1
        for chunk in chunks:
            conn.send(chunk)

            chunk_num += 1
            progress = round(chunk_num / len(chunks) * 50) + 50
            self.ui.progressBar.setValue(progress)
            self.repaint()

        file_name = f'{self.app_name}.zip'
        conn.send(bytes(file_name, 'utf-8') + b'\x00')

        self.ui.progressBar.setValue(100)
        self.status_message('App transmitted!')
        logging.info(f"App transmitted to HBC at {ip}")
Ejemplo n.º 2
0
if args.cmd == "get":
    if args.app == "all":
        OpenShopChannel = metadata.API()
        OpenShopChannel.set_host(args.host)
        print(f"Starting download of all packages from \"{args.host}\" @ {repos.name(args.host)['host']}..")
        for package in OpenShopChannel.packages:
            download.get(app_name=package["internal_name"], repo=repos.name(args.host)["host"])
    else:
        download.get(app_name=args.app, repo=repos.name(args.host)["host"])

# Send
if args.cmd == "send":
    # get hostname of host
    host_url = repos.name(args.host)["host"]

    ok = wiiload.validate_ip_regex(ip=args.destination)
    if not ok:
        print(f"Error: The address '{args.destination}' is invalid! Please correct it!")
        exit(1)

    url = f"https://{host_url}/hbb/{args.app}/{args.app}.zip"
    r = requests.get(url)
    zipped_app = io.BytesIO(r.content)
    zip_buf = io.BytesIO()

    # Our zip file should only contain one directory with the app data in it,
    # but the downloaded file contains an apps/ directory. We're removing that here.
    wiiload.organize_zip(zipped_app, zip_buf)

    # preparing
    print("Preparing app..")
Ejemplo n.º 3
0
    def wiiload_button(self):
        data = self.ui.listAppsWidget.currentItem().data(Qt.UserRole)
        app_name = data["internal_name"]
        app_display_name = data["display_name"]

        ip, ok = QInputDialog.getText(
            self, 'Send to Wii: Enter IP address',
            'Enter the IP address of your Wii.\n'
            'The selected app will be sent through the network to your Wii.\n\n'
            f'App to send: {app_display_name}\n\n'
            'To find your Wii\'s IP address:\n'
            '1) Enter the Homebrew Channel.\n'
            '2) Press the home button on the Wii Remote.\n'
            '3) Copy the IP address written in the top left corner.\n\n'
            'IP address (e.g. 192.168.1...):', QLineEdit.Normal)
        if not ok:
            return

        ip_match = wiiload.validate_ip_regex(ip)

        if ip_match is None:
            logging.warning('Invalid IP Address: ' + ip)
            QMessageBox.warning(self, 'Invalid IP Address',
                                'This IP address is invalid.')
            return

        self.status_message("Downloading " + app_name +
                            " from Open Shop Channel..")
        self.ui.progressBar.setValue(25)

        # get app
        path_to_app = self.download_button()

        with open(path_to_app, 'rb') as f:
            content = f.read()

        zipped_app = io.BytesIO(content)
        zip_buf = io.BytesIO()

        # Our zip file should only contain one directory with the app data in it,
        # but the downloaded file contains an apps/ directory. We're removing that here.
        wiiload.organize_zip(zipped_app, zip_buf)

        # preparing
        prep = wiiload.prepare(zip_buf)

        file_size = prep[0]
        compressed_size = prep[1]
        chunks = prep[2]

        # connecting
        self.status_message('Connecting to the HBC...')
        self.ui.progressBar.setValue(50)

        try:
            conn = wiiload.connect(ip)
        except socket.error as e:
            logging.error(
                'Error while connecting to the HBC. Please check the IP address and try again.'
            )
            QMessageBox.warning(
                self, 'Connection error',
                'Error while connecting to the HBC. Please check the IP address and try again.'
            )
            print(f'WiiLoad: {e}')
            self.ui.progressBar.setValue(0)
            self.status_message(
                'Error: Could not connect to the Homebrew Channel. :(')

            # delete application zip file
            os.remove(path_to_app)

            return

        wiiload.handshake(conn, compressed_size, file_size)

        # Sending file
        self.status_message('Sending app...')

        chunk_num = 1
        for chunk in chunks:
            conn.send(chunk)

            chunk_num += 1
            progress = round(chunk_num / len(chunks) * 50) + 50
            self.ui.progressBar.setValue(progress)
            try:
                app.processEvents()
            except NameError:
                pass

        file_name = f'{app_name}.zip'
        conn.send(bytes(file_name, 'utf-8') + b'\x00')

        # delete application zip file
        os.remove(path_to_app)

        self.ui.progressBar.setValue(100)
        self.status_message('App transmitted!')
        logging.info(f"App transmitted to HBC at {ip}")
Ejemplo n.º 4
0
    print("\nRun \"" + osc_dl + " --help\" for help.")

# list of apps on server command
if args.cmd == 'list':
    if args.host is None:
        args.host = "hbb1.oscwii.org"

    parsecontents.get(repo=args.host, raw=args.raw)

# Modern Code here :S
if args.cmd == 'transmit':
    if args.host is None:
        args.host = "hbb1.oscwii.org"
        # args.ip

    ok = wiiload.validate_ip_regex(ip=args.ip)
    if not ok:
        print(
            f"Error DL0001: The IP address '{args.ip}' is invalid! Please correct it!"
        )
        exit(1)

    parsecontents.query(term=args.name, repo=args.host)

    url = f"https://{args.host}/hbb/{args.name}/{args.name}.zip"
    r = requests.get(url)
    zipped_app = io.BytesIO(r.content)
    zip_buf = io.BytesIO()

    # Our zip file should only contain one directory with the app data in it,
    # but the downloaded file contains an apps/ directory. We're removing that here.