Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

feat(warnings): add unsupported warnings #122

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
...take 2 on that commit
  • Loading branch information
osfanbuff63 committed May 4, 2023
commit b5728a32f0d390992d6fb43d010b80e97362f4d7
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
*.jar
data/
temp/
config/
data/
resourcepacks/
# tests/
%USERPROFILE%
logs/
Expand Down
7 changes: 6 additions & 1 deletion vanilla_installer/assets/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"vanilla_installer.gui.location": "Location:",
"vanilla_installer.gui.issues_button": "Report bugs",
"vanilla_installer.gui.theme_toggle": "Toggle theme",
"vanilla_installer.gui.settings": "Settings"
"vanilla_installer.gui.settings": "Settings",
"vanilla_installer.gui.downgrade": "Downgrade Warning",
"vanilla_installer.gui.downgrade.text": "You are attempting to downgrade the Minecraft version. This is NOT SUPPORTED by Mojang or Fabulously Optimized and it may cause world corruption or crashes. \nIf you want to do this safely, you should backup mods, config and saves folders to a different location and delete them from your .minecraft folder.",
"vanilla_installer.gui.downgrade.install_checkbox": "I agree that downgrades are unsupported by Mojang and Fabulously Optimized, but I want to do this anyway.",
"vanilla_installer.gui.warnings.open_folder": "Open .minecraft",
"vanilla_installer.gui.warnings.install_anyway": "Install anyway"
}
107 changes: 103 additions & 4 deletions vanilla_installer/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

# IMPORTS
import logging
import pathlib
import platform
import sys
Expand All @@ -26,9 +25,11 @@
QGraphicsColorizeEffect,
QLabel,
QMainWindow,
QMessageBox,
QPushButton,
QTextEdit,
QWidget,
QAbstractButton,
)

# LOCAL
Expand Down Expand Up @@ -68,12 +69,14 @@ def run() -> None:
def setFont(opendyslexic: bool):
global global_font
if opendyslexic:
logger.debug("Set font to OpenDyslexic")
global_font = "OpenDyslexic"
else:
# For some reason the Inter font on Linux is called `Inter` and on Windows it's called `Inter Regular`
# And thus, this is a janky solution
# I'm not sure what it's called on MacOS so hopefully it's the same as linux cause i can't test it
# Either way it would be a better idea to move to a font that doesn't have this issue
logger.debug("Set font to Inter")
inter_name = "Inter"
if platform.system() == "Windows":
inter_name = "Inter Regular"
Expand Down Expand Up @@ -419,6 +422,18 @@ def startInstall(self) -> None:
)
version = self.versionSelector.itemText(self.versionSelector.currentIndex())
location = self.selectedLocation.toPlainText()
if main.downgrade_check(version, location) is True:
logger.warning("Downgrade detected, opening downgrade warning.")
continue_on_downgrade = False
response = DowngradeWarning(self).exec()
if response == DowngradeWarning.cancelButton:
pass
if continue_on_downgrade is False:
return
else:
logger.warning(
"User chose to continue on a version downgrade, anything past this is UNSUPPORTED."
)
self.installing = True
if version.startswith("1.16"):
java_ver = 8
Expand All @@ -441,9 +456,6 @@ def startInstall(self) -> None:
class SettingsDialog(QDialog):
"""
The settings dialog.

Args:
QDialog (QDialog): The dialog.
"""

parentWindow: Ui_MainWindow
Expand Down Expand Up @@ -540,6 +552,93 @@ def changeFont(self, state) -> None:
self.parentWindow.reloadTheme()


class DowngradeWarning(QMessageBox):
parentWindow: Ui_MainWindow

def __init__(self, parent) -> None:
self.parentWindow = parent
super().__init__(self.parentWindow.centralwidget)
self.setupUi()

def setupUi(self) -> None:
"""Setup the UI for the downgrade warning."""
if not self.objectName():
self.setObjectName("Warning")
self.setIcon(QMessageBox.Icon.Warning)
self.openFolderButton = self.addButton(
"Open .minecraft",
QMessageBox.ButtonRole.ActionRole,
)
self.installAnywayButton = self.addButton(
"Install anyway",
QMessageBox.ButtonRole.ActionRole,
)
self.installAnywayButton.setDisabled(True)
self.cancelButton = self.addButton(QMessageBox.Cancel)
self.installCheckbox = QCheckBox()
self.setCheckBox(self.installCheckbox)
self.setDefaultButton(QMessageBox.Cancel)
self.retranslateUi(self)
self.reloadTheme()

def retranslateUi(self, Warning) -> None:
"""
Retranslate UI for the set dialog.

Args:
Warning: The dialog.
"""
i18n_strings = i18n.get_i18n_values("en_us")
Warning.setWindowTitle(
QCoreApplication.translate(
"Warning", i18n_strings["vanilla_installer.gui.downgrade"], None
)
)
self.openFolderButton.setText(
QCoreApplication.translate(
"Warning",
i18n_strings["vanilla_installer.gui.warnings.open_folder"],
None,
)
)
self.installAnywayButton.setText(
QCoreApplication.translate(
"Warning",
i18n_strings["vanilla_installer.gui.warnings.install_anyway"],
None,
)
)
self.installCheckbox.setText(
QCoreApplication.translate(
"Warning",
i18n_strings["vanilla_installer.gui.downgrade.install_checkbox"],
None,
)
)

def reloadTheme(self) -> None:
"""
Reload the theme.
"""
loaded_theme = theme.load()
self.setStyleSheet(
f'[objectName^="Warning"] {{ background-color: {loaded_theme.get("base")}}}'
)
self.openFolderButton.setStyleSheet(
f'QPushButton {{ border: none; background-color: { loaded_theme.get("button") } ; color: {loaded_theme.get("text")}; padding: 8px; border-radius: 5px; font-family: "{global_font}"}}'
f'QPushButton:hover {{ background-color: { loaded_theme.get("buttonhovered") }}}'
f'QPushButton:hover {{ background-color: { loaded_theme.get("buttonpressed") }}}'
)
self.installAnywayButton.setStyleSheet(
f'QPushButton {{ border: none; background-color: { loaded_theme.get("button") } ; color: {loaded_theme.get("text")}; padding: 8px; border-radius: 5px; font-family: "{global_font}"}}'
f'QPushButton:hover {{ background-color: { loaded_theme.get("buttonhovered") }}}'
f'QPushButton:hover {{ background-color: { loaded_theme.get("buttonpressed") }}}'
)
self.installCheckbox.setStyleSheet(
f'color: {loaded_theme.get("label")}; font-family: "{global_font}"'
)


class Worker(QRunnable):
def __init__(self, fn) -> None:
super(Worker, self).__init__()
Expand Down
12 changes: 10 additions & 2 deletions vanilla_installer/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ def flush(self):
pass


def setup_logging() -> logging.Logger:
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
try:
if log_setup != bool:
pass
except:
log_setup = False
logger.setLevel(logging.DEBUG)
logfile_path = Path("./logs").resolve() / "vanilla_installer.log"
if logfile_path.exists() is False:
Expand All @@ -52,4 +56,8 @@ def setup_logging() -> logging.Logger:
# To access the original stdout/stderr, use sys.__stdout__/sys.__stderr__
sys.stdout = LoggerWriter(logger.info)
sys.stderr = LoggerWriter(logger.error)
log_setup = True


def setup_logging() -> logging.Logger:
return logger
62 changes: 39 additions & 23 deletions vanilla_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from vanilla_installer import __version__, config, log

logger = log.setup_logging()
logger.info("Starting Vanilla Installer")


FOLDER_LOC = ""

Expand Down Expand Up @@ -55,7 +55,6 @@ def get_dir() -> str:
Returns:
str: Path
"""

path = config.read()
return path["config"]["path"]

Expand Down Expand Up @@ -276,10 +275,10 @@ def install_pack(
java_ver (float): The Java version to use. Defaults to 17.3
"""
logger.debug("Installing the pack now.")
os.chdir(mc_dir)
os.makedirs(f"{get_dir()}/", exist_ok=True)
pack_toml = convert_version(mc_version)
try:
os.chdir(mc_dir)
os.makedirs(f"{get_dir()}/", exist_ok=True)
command(
f"{get_java(java_ver)} -jar {packwiz_installer_bootstrap} {pack_toml} --timeout 0"
)
Expand Down Expand Up @@ -422,7 +421,7 @@ def convert_version(input_mcver: str) -> str:
str: The converted version as a URL.
"""
versions = get_pack_mc_versions()
return_value = versions.get(input_mcver)
return_value = versions[input_mcver]["packwiz"]
if return_value is None:
raise TypeError("Invalid or unsupported Minecraft version.")
else:
Expand All @@ -440,6 +439,7 @@ def downgrade_check(
Returns:
bool: Whether this is a downgrade.
"""
downgrade = True
version_dict = read_versions()
installed_version_file = Path(install_dir).resolve() / ".fovi" / "mc_version.txt"
try:
Expand All @@ -448,24 +448,39 @@ def downgrade_check(
except FileNotFoundError:
logger.exception("No version file found. Assuming this is not a downgrade")
downgrade = False
try:
current_version = float(version_dict[current_version_file])
if float(version) < current_version:
downgrade = True
else:
downgrade = False
except KeyError:
logger.exception("Invalid or unknown version installed, making extra checks.")
install_dir_path = Path(install_dir).resolve()
install_dir_path.mods = install_dir_path / "mods"
install_dir_path.config = install_dir_path / "config"
install_dir_path.saves = install_dir_path / "saves"
if install_dir_path.mods.exists() is False and install_dir_path.config.exists() is False and install_dir_path.saves.exists() is False:
logger.info("No mods, config, or saves directory found, this cannot be a downgrade.")
downgrade = False
elif not any(install_dir_path.mods.iterdir()) and not any(install_dir_path.config.iterdir()) and not any(install_dir_path.saves.iterdir()):
logger.info("Mods, config, and saves directories were empty, this cannot be a downgrade.")
downgrade = False
if downgrade is not False:
try:
current_version = float(version_dict[current_version_file])
if float(version) < current_version:
downgrade = True
else:
downgrade = False
except KeyError:
logger.exception(
"Invalid or unknown version installed, making extra checks."
)
install_dir_path = Path(install_dir).resolve()
install_dir_path_mods = install_dir_path / "mods"
install_dir_path_config = install_dir_path / "config"
install_dir_path_saves = install_dir_path / "saves"
if (
install_dir_path_mods.exists() is False
and install_dir_path_config.exists() is False
and install_dir_path_saves.exists() is False
):
logger.info(
"No mods, config, or saves directory found, this cannot be a downgrade."
)
downgrade = False
elif (
not any(install_dir_path_mods.iterdir())
and not any(install_dir_path_config.iterdir())
and not any(install_dir_path_saves.iterdir())
):
logger.info(
"Mods, config, and saves directories were empty, this cannot be a downgrade."
)
downgrade = False
return downgrade


Expand Down Expand Up @@ -522,3 +537,4 @@ def run(
create_profile(mc_dir, fabric_version)
text_update("Complete!", widget, "info", interface)
logger.info("Success!")
log_installed_version(version, mc_dir)