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

Commit 27a135d

Browse files
committed
feat(directory): ✨ initial work on an FO dir
1 parent 06a0d5c commit 27a135d

4 files changed

Lines changed: 60 additions & 13 deletions

File tree

vanilla_installer/config.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import os
23
import platform
34
from pathlib import Path
@@ -6,7 +7,7 @@
67
import tomlkit
78
from tomlkit import toml_file
89

9-
from vanilla_installer.log import logger
10+
logger = logging.getLogger(__name__)
1011

1112
FILE_PATH = str(Path("vanilla_installer.toml").resolve())
1213

@@ -23,8 +24,15 @@ def init():
2324

2425
config = tomlkit.table()
2526
# maybe call darkdetect from here?
26-
# might want to just leave this alone to be
27+
# might want to just leave this alone to be honest
2728
config.add("theme", "dark")
29+
config.add(
30+
tomlkit.comment(
31+
"Whether to use FO's directory or ask the user for a custom one."
32+
)
33+
)
34+
config.add("fo_dir", True)
35+
config.add(tomlkit.comment("This is only used is fo_dir (above) is false."))
2836
config.add("path", mll.utils.get_minecraft_directory())
2937
if platform.system() == "Windows":
3038
font = "Inter Regular"

vanilla_installer/gui.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,23 @@ def changeFont(self, state) -> None:
502502
self.reloadTheme()
503503
self.parentWindow.reloadTheme()
504504

505+
def setFODir(self, state: bool) -> None:
506+
"""Set whether the FO dir should be used.
507+
508+
Args:
509+
state (bool): Whether the FO directory is being enabled or disabled.
510+
"""
511+
if state is True:
512+
config.write("fo_dir", True)
513+
self.parentWindow.locationSelector.setDisabled(True)
514+
self.parentWindow.selectedLocation.setDisabled(True)
515+
else:
516+
config.write("fo_dir", False)
517+
self.parentWindow.locationSelector.setDisabled(False)
518+
self.parentWindow.selectedLocation.setDisabled(False)
519+
self.reloadTheme()
520+
self.parentWindow.reloadTheme()
521+
505522

506523
class Worker(QRunnable):
507524
def __init__(self, fn) -> None:

vanilla_installer/log.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""Starts logging for Vanilla Installer."""
44
import logging
55
import logging.handlers # pylance moment
6-
from pathlib import Path
76
import sys
7+
from pathlib import Path
88

99

1010
class LoggerWriter:
@@ -13,9 +13,9 @@ def __init__(self, logfct):
1313
self.buf = []
1414

1515
def write(self, msg):
16-
if msg.endswith('\n'):
17-
self.buf.append(msg.removesuffix('\n'))
18-
self.logfct(''.join(self.buf))
16+
if msg.endswith("\n"):
17+
self.buf.append(msg.removesuffix("\n"))
18+
self.logfct("".join(self.buf))
1919
self.buf = []
2020
else:
2121
self.buf.append(msg)
@@ -32,11 +32,11 @@ def flush(self):
3232
with logfile_path as file:
3333
open(file, "x", encoding="utf-8").write("")
3434
handler = logging.handlers.RotatingFileHandler(
35-
filename=logfile_path,
36-
encoding="utf-8",
37-
maxBytes=32 * 1024 * 1024, # 32 MiB
38-
backupCount=5, # Rotate through 5 files
39-
)
35+
filename=logfile_path,
36+
encoding="utf-8",
37+
maxBytes=32 * 1024 * 1024, # 32 MiB
38+
backupCount=5, # Rotate through 5 files
39+
)
4040

4141
dt_fmt = "%Y-%m-%d %H:%M:%S"
4242
formatter = logging.Formatter(

vanilla_installer/main.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66
# IMPORTS
77

8-
98
import base64
109
import io
1110
import json
@@ -14,7 +13,7 @@
1413
import subprocess
1514
import zipfile
1615
from pathlib import Path
17-
from typing import Optional
16+
from typing import Optional, Union
1817

1918
import click
2019
import minecraft_launcher_lib as mll
@@ -196,6 +195,29 @@ def get_version() -> str:
196195
return __version__
197196

198197

198+
def get_fo_dir() -> str:
199+
"""Get the default directory to use when the independent FO directory is selected.
200+
201+
Returns:
202+
str: The path.
203+
"""
204+
if platform.system() == "Windows":
205+
fo_dir_path = (
206+
Path("~/AppData/Roaming/Fabulously Optimized").expanduser().resolve()
207+
)
208+
elif platform.system() == "macOS":
209+
fo_dir_path = (
210+
Path("~/Library/Application Support/Fabulously Optimized")
211+
.expanduser()
212+
.resolve()
213+
)
214+
else:
215+
fo_dir_path = Path("~/.local/share/Fabulously Optimized").expanduser().resolve()
216+
if fo_dir_path.exists() is False:
217+
fo_dir_path.mkdir()
218+
return str(fo_dir_path)
219+
220+
199221
def text_update(
200222
text: str, widget=None, mode: str = "info", interface: str = "GUI"
201223
) -> None:

0 commit comments

Comments
 (0)