Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull location of users Documents folder directly from the windows registry #393

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import os
import platform
from typing import Hashable
import winreg
import src.color_formatter as cf
import src.utils as utils
import pandas as pd
Expand All @@ -16,10 +18,20 @@ def set_cwd_to_exe_dir():
os.chdir(os.path.dirname(sys.executable))

def get_my_games_directory():
home: str = os.path.expanduser("~")
save_dir = Path(os.path.join(home,"Documents","My Games","Mantella"))
save_dir.mkdir(parents=True, exist_ok=True)
return str(save_dir)+'\\'
documents_path = ""
if platform.system() == "Windows":
reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
documents_path = winreg.QueryValueEx(reg_key, "Personal")[0]
winreg.CloseKey(reg_key)
else:
homepath = os.getenv('HOMEPATH')
if homepath:
documents_path = os.path.realpath(homepath+'/Documents')
if documents_path == "":
print("ERROR: Could not find 'Documents' folder or equivalent!")
save_dir = Path(os.path.join(documents_path,"My Games","Mantella"))
save_dir.mkdir(parents=True, exist_ok=True)
return str(save_dir)+'\\'

def setup_logging(file_name, config: ConfigLoader):
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s', handlers=[])
Expand Down