Skip to content

Commit

Permalink
More robust home directory handling (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenpie authored Nov 16, 2023
1 parent 9c4038c commit e642a7e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def load_data(self):
self.configs["params"]["parser"].read("config/params.ini")
self.configs["game"]["parser"].read(f"config/game_{Cam().res_key}.ini")

user = os.getlogin()
custom_params_path = Path(f"C:/Users/{user}/.d4lf/params.ini")
user_dir = os.path.expanduser("~")
custom_params_path = Path(f"{user_dir}/.d4lf/params.ini")
if os.environ.get("RUN_ENV") != "test" and os.path.exists(custom_params_path):
try:
self.configs["custom"]["parser"].read(custom_params_path)
Expand Down
4 changes: 2 additions & 2 deletions src/item/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def load_files(self):
self.files_loaded = True
profiles: list[str] = Config().general["profiles"]

user = os.getlogin()
custom_profile_path = Path(f"C:/Users/{user}/.d4lf/profiles")
user_dir = os.path.expanduser("~")
custom_profile_path = Path(f"{user_dir}/.d4lf/profiles")
params_profile_path = Path(f"config/profiles")

for profile_str in profiles:
Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def main():
wait(0.2)

# Create folders for logging stuff
user = os.getlogin()
config_dir = Path(f"C:/Users/{user}/.d4lf")
user_dir = os.path.expanduser("~")
config_dir = Path(f"{user_dir}/.d4lf")
for dir_name in ["log/screenshots", config_dir, config_dir / "profiles"]:
os.makedirs(dir_name, exist_ok=True)

Expand Down
3 changes: 2 additions & 1 deletion src/utils/game_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

def is_fontsize_ok() -> bool:
custom_path = Config().general["local_prefs_path"]
default_path = f"C:\\Users\\{os.getlogin()}\\Documents\\Diablo IV/LocalPrefs.txt"
user_dir = os.path.expanduser("~")
default_path = f"{user_dir}\\Documents\\Diablo IV/LocalPrefs.txt"
file_path = custom_path if custom_path != "" else default_path
if not os.path.exists(file_path):
Logger.warning("Could not find LocalPrefs.txt to check font size. Make sure you have font size set to small!")
Expand Down

0 comments on commit e642a7e

Please sign in to comment.