Skip to content

Commit

Permalink
Use user_directory from __main__ instead of duping it, and jump out o…
Browse files Browse the repository at this point in the history
…f src in cloned installs
  • Loading branch information
C0rn3j committed Dec 31, 2024
1 parent 15a6026 commit 5b181df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
16 changes: 12 additions & 4 deletions src/tauon/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ def transfer_args_and_exit() -> None:
if str(install_directory).startswith("/usr/") and Path("/usr/share/TauonMusicBox").is_dir():
install_directory = Path("/usr/share/TauonMusicBox")

user_directory = install_directory / "user-data"
config_directory = user_directory
asset_directory = install_directory / "assets"

if str(install_directory).startswith("/app/"):
# Its Flatpak
t_id = "com.github.taiko2k.tauonmb"
Expand All @@ -180,8 +176,19 @@ def transfer_args_and_exit() -> None:
if (install_directory / "portable").is_file():
install_mode = False

# Handle regular install, running from a directory and finally a portable install, usually a venv
if install_mode:
# logging.info("Running in installed mode")
user_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
elif install_directory.parent.name == "src":
# logging.info("Running in portable mode from cloned dir")
user_directory = install_directory.parent.parent / "user-data"
else:
# logging.info("Running in portable mode")
user_directory = install_directory / "user-data"

asset_directory = install_directory / "assets"

if not user_directory.is_dir():
user_directory.mkdir(parents=True)

Expand Down Expand Up @@ -413,6 +420,7 @@ def transfer_args_and_exit() -> None:
holder.window_opacity = window_opacity
holder.old_window_position = old_window_position
holder.install_directory = install_directory
holder.user_directory = user_directory
holder.pyinstaller_mode = pyinstaller_mode
holder.phone = phone
holder.window_title = window_title
Expand Down
1 change: 1 addition & 0 deletions src/tauon/t_modules/t_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Holder:
transfer_args_and_exit: Callable[[]] # transfer_args_and_exit() - TODO(Martin): This should probably be moved to extra module
old_window_position: tuple [int, int] | None # X Y res
install_directory: Path
user_directory: Path
pyinstaller_mode: bool
phone: bool
window_default_size: tuple[int, int] # X Y res
Expand Down
17 changes: 5 additions & 12 deletions src/tauon/t_modules/t_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@
transfer_args_and_exit = holder.transfer_args_and_exit
old_window_position = holder.old_window_position
install_directory = holder.install_directory
user_directory = holder.user_directory
pyinstaller_mode = holder.pyinstaller_mode
phone = holder.phone
window_default_size = holder.window_default_size
Expand Down Expand Up @@ -569,7 +570,6 @@ def setup_ssl() -> ssl.SSLContext:
logging.exception("Error accessing GTK settings")

# Set data folders (portable mode)
user_directory = install_directory
config_directory = user_directory
cache_directory = user_directory / "cache"
home_directory = os.path.join(os.path.expanduser("~"))
Expand Down Expand Up @@ -618,11 +618,11 @@ def setup_ssl() -> ssl.SSLContext:
# If we're installed, use home data locations
if (install_mode and system == "Linux") or macos or msys:
cache_directory = Path(GLib.get_user_cache_dir()) / "TauonMusicBox"
user_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
config_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
#user_directory = Path(GLib.get_user_data_dir()) / "TauonMusicBox"
config_directory = user_directory

if not user_directory.is_dir():
os.makedirs(user_directory)
# if not user_directory.is_dir():
# os.makedirs(user_directory)

if not config_directory.is_dir():
os.makedirs(config_directory)
Expand All @@ -634,8 +634,6 @@ def setup_ssl() -> ssl.SSLContext:
else:
logging.info("Running from installed location")

logging.info(f"User files location: {user_directory}")

if not (user_directory / "encoder").is_dir():
os.makedirs(user_directory / "encoder")

Expand All @@ -654,13 +652,8 @@ def setup_ssl() -> ssl.SSLContext:

else:
logging.info("Running in portable mode")

user_directory = install_directory / "user-data"
config_directory = user_directory

if not user_directory.is_dir():
os.makedirs(user_directory)

if not (user_directory / "state.p").is_file() and cache_directory.is_dir():
logging.info("Clearing old cache directory")
logging.info(cache_directory)
Expand Down

0 comments on commit 5b181df

Please sign in to comment.