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
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
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "An installer of Fabulously Optimized for the vanilla launcher."
authors = [
"osfanbuff63 <[email protected]>",
"nsde <[email protected]>",
"Kichura <blobfox.coffee/@Kichura>"
"Kichura <Kichura@blobfox.coffee>"
]
documentation = "https://fabulously-optimized.gitbook.io/vanilla-installer"
homepage = "https://fabulously-optimized.gitbook.io/vanilla-installer"
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"
}
73 changes: 68 additions & 5 deletions vanilla_installer/assets/versions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,69 @@
{
"1.19.4": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.19.4/pack.toml",
"1.18.2": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.18.2/pack.toml",
"1.17.1": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.17.1/pack.toml",
"1.16.5": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.16.5/pack.toml"
}
"format_version": 2,
"versions": {
"1.19.4": {
"packwiz": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.19.4/pack.toml",
"major_version": 4,
"enabled": true
},
"1.19.3": {
"major_version": 4,
"enabled": false
},
"1.19.2": {
"major_version": 4,
"enabled": false
},
"1.19.1": {
"major_version": 4,
"enabled": false
},
"1.19": {
"major_version": 4,
"enabled": false
},
"1.18.2": {
"packwiz": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.18.2/pack.toml",
"major_version": 3,
"enabled": true
},
"1.18.1": {
"major_version": 3,
"enabled": false
},
"1.18": {
"major_version": 3,
"enabled": false
},
"1.17.1": {
"packwiz": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.17.1/pack.toml",
"major_version": 2,
"enabled": true
},
"1.17": {
"major_version": 2,
"enabled": false
},
"1.16.5": {
"packwiz": "https://raw.githubusercontent.com/Fabulously-Optimized/fabulously-optimized/main/Packwiz/1.16.5/pack.toml",
"major_version": 1,
"enabled": true
},
"1.16.4": {
"major_version": 1,
"enabled": false
},
"1.16.3": {
"major_version": 1,
"enabled": false
},
"1.16.2": {
"major_version": 1,
"enabled": false
},
"1.16.1": {
"major_version": 1,
"enabled": false
}
}
}
108 changes: 103 additions & 5 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 @@ -205,7 +208,6 @@ def setupUi(self, MainWindow: QMainWindow) -> None:
Ui_MainWindow.getAsset("settings.svg"), self.settingsButton
)
self.settingsButtonIcon.setGeometry(70, 0, 24, 24)

self.windowIcon = Ui_MainWindow.getAsset("icon.png")
MainWindow.setWindowIcon(QIcon(self.windowIcon))

Expand Down Expand Up @@ -420,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 @@ -442,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 @@ -541,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
24 changes: 22 additions & 2 deletions vanilla_installer/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,24 @@ def flush(self):
pass


def setup_logging() -> logging.Logger:
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
try:
if log_setup is not True: # noqa: F821
log_setup = False
logger.setLevel(logging.DEBUG)
logfile_path = Path("./logs").resolve() / "vanilla_installer.log"
if logfile_path.exists() is False:
Path("./logs").resolve().mkdir(exist_ok=True)
with logfile_path as file:
open(file, "x", encoding="utf-8").write("")
handler = logging.handlers.RotatingFileHandler(
filename=logfile_path,
encoding="utf-8",
maxBytes=32 * 1024 * 1024, # 32 MiB
backupCount=5, # Rotate through 5 files
)
except UnboundLocalError:
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 +68,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
Loading