-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_wtf_folder.py
81 lines (64 loc) · 2.96 KB
/
get_wtf_folder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# %% LOCAL IMPORTS
from logger_config import logger
from select_dir import select_folder
# %% MODULE IMPORTS
import os
from platform import system
import asyncio
# %% FUNCTIONS
def get_possible_paths():
"""
Get a list of possible paths where Ascension WoW might be installed based on the OS.
:return: A list of paths to search.
"""
os.type = system()
possible_paths = []
if os.type != "Windows":
raise Exception("The app is only available for Windows")
drives = [f"{chr(x)}:\\" for x in range(65, 91) if os.path.exists(f"{chr(x)}:\\")]
for drive in drives:
# Add default known locations
possible_paths.append(os.path.join(drive, "Program Files", "Ascension Launcher", "resources", "client"))
possible_paths.append(os.path.join(drive, "Program Files (x86)", "Ascension Launcher", "resources", "client"))
possible_paths.append(os.path.join(drive, "Games", "Ascension Launcher", "resources", "client"))
possible_paths.append(os.path.join(drive, "Ascension Launcher", "resources", "client"))
# # LINUX IS UNTESTED
# elif os.type == "Linux":
# home_dir = os.path.expanduser("~")
# # Add default known locations
# possible_paths.append(os.path.join(home_dir, ".ascension", "client"))
# possible_paths.append(os.path.join(home_dir, "Games", "Ascension Launcher", "resources", "client"))
# possible_paths.append(os.path.join(home_dir, "Ascension", "resources", "client"))
# possible_paths.append(os.path.join("/", "opt", "Ascension Launcher", "resources", "client"))
# possible_paths.append(os.path.join("/", "usr", "local", "Ascension Launcher", "resources", "client"))
return possible_paths
def get_wtf_folder():
"""
Run the WTF folder search with user input for custom paths.
"""
# Get the possible paths based on OS
starting_paths = get_possible_paths()
# Search for the WTF folder
wtf_folder = find_wtf_folder(starting_paths)
if wtf_folder:
return wtf_folder
while True:
logger.info("Couldn't find WTF folder automatically. Select it yourself")
folder_selected_path = asyncio.run(select_folder())
if folder_selected_path.endswith(r"/WTF"):
break
else:
logger.info("Selected wrong folder. You must select the 'WTF' folder in Ascension directory. Try again")
return folder_selected_path
def find_wtf_folder(starting_paths, target_folder_name="WTF"):
"""
Search for the WTF folder within the specified starting paths.
:param starting_paths: List of paths where the search should begin.
:param target_folder_name: The name of the folder to search for.
:return: The full path to the WTF folder if found, otherwise None.
"""
for starting_path in starting_paths:
for root, dirs, files in os.walk(starting_path):
if target_folder_name in dirs:
return os.path.join(root, target_folder_name)
return None