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}")
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}")
chunks = prep[2] # connecting print('Connecting to the Homebrew Channel..') try: conn = wiiload.connect(args.destination) except Exception as e: print('Connection error: Error while connecting to the Homebrew Channel.\n' 'Please check the IP address and try again.') print(f'Exception: {e}') print('Error: Could not connect to the Homebrew Channel. :(') exit(1) wiiload.handshake(conn, compressed_size, file_size) # Sending file print('[ 0%] Sending app..') chunk_num = 1 for chunk in chunks: conn.send(chunk) chunk_num += 1 progress = round(chunk_num / len(chunks) * 50) + 50 if progress < 100: print(f'[ {progress}%] Sending app..') if progress == 100: print(f'[{progress}%] Sending app..')