minnor fixes

This commit is contained in:
Nix 2025-01-09 23:20:35 -03:00 committed by GitHub
parent 5202f8fb25
commit 51dc126c8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@ import subprocess
import threading import threading
from threading import Thread from threading import Thread
import logging import logging
import re
import shutil import shutil
import platform import platform
import requests import requests
@ -775,7 +776,20 @@ class PicomcVersionSelector(QWidget):
self.installed_version_combo.addItems(versions) self.installed_version_combo.addItems(versions)
def populate_installed_versions_normal_order(self): def populate_installed_versions_normal_order(self):
# Run the command and get the output # Run the 'picomc instance create default' command at the start
try:
process = subprocess.Popen(['picomc', 'instance', 'create', 'default'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
output, error = process.communicate()
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, process.args, error)
except FileNotFoundError:
logging.error("'picomc' command not found. Please make sure it's installed and in your PATH.")
return
except subprocess.CalledProcessError as e:
logging.error("Error creating default instance: %s", e.stderr)
return
# Run the 'picomc version list' command and get the output
try: try:
process = subprocess.Popen(['picomc', 'version', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) process = subprocess.Popen(['picomc', 'version', 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
output, error = process.communicate() output, error = process.communicate()
@ -946,6 +960,38 @@ class PicomcVersionSelector(QWidget):
dialog.exec_() dialog.exec_()
self.open_dialogs.remove(dialog) self.open_dialogs.remove(dialog)
def create_account(self, dialog, username, is_microsoft):
# Remove leading and trailing spaces from the username
username = username.strip()
if not username:
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
return
if not self.is_valid_username(username):
QMessageBox.warning(dialog, "Warning", "Invalid username. Usernames must be 3-16 characters long and can only contain letters, numbers, and underscores.")
return
try:
command = ['picomc', 'account', 'create', username]
if is_microsoft:
command.append('--ms')
subprocess.run(command, check=True)
QMessageBox.information(dialog, "Success", f"Account '{username}' created successfully!")
self.populate_accounts_for_all_dialogs()
dialog.accept()
except subprocess.CalledProcessError as e:
error_message = f"Error creating account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(dialog, "Error", error_message)
def is_valid_username(self, username):
# Validate the username according to Minecraft's rules
if 3 <= len(username) <= 16 and re.match(r'^[a-zA-Z0-9_]+$', username):
return True
return False
def authenticate_account(self, dialog, account_name): def authenticate_account(self, dialog, account_name):
# Authenticate a selected account # Authenticate a selected account
account_name = account_name.strip().lstrip(" * ") account_name = account_name.strip().lstrip(" * ")
@ -980,24 +1026,6 @@ class PicomcVersionSelector(QWidget):
logging.error(error_message) logging.error(error_message)
QMessageBox.critical(dialog, "Error", error_message) QMessageBox.critical(dialog, "Error", error_message)
def create_account(self, dialog, username, is_microsoft):
# Create a new account
if not username.strip():
QMessageBox.warning(dialog, "Warning", "Username cannot be blank.")
return
try:
command = ['picomc', 'account', 'create', username]
if is_microsoft:
command.append('--ms')
subprocess.run(command, check=True)
QMessageBox.information(dialog, "Success", f"Account '{username}' created successfully!")
self.populate_accounts_for_all_dialogs()
except subprocess.CalledProcessError as e:
error_message = f"Error creating account: {e.stderr.decode()}"
logging.error(error_message)
QMessageBox.critical(dialog, "Error", error_message)
def populate_accounts(self, account_combo): def populate_accounts(self, account_combo):
# Populate the account dropdown # Populate the account dropdown
@ -1703,4 +1731,4 @@ if __name__ == '__main__':
app.setWindowIcon(QIcon('launcher_icon.ico')) # Set regular icon app.setWindowIcon(QIcon('launcher_icon.ico')) # Set regular icon
window = PicomcVersionSelector() window = PicomcVersionSelector()
window.show() window.show()
sys.exit(app.exec_()) sys.exit(app.exec_())