This repository was archived by the owner on Apr 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.py
More file actions
175 lines (155 loc) · 5.74 KB
/
Copy pathmethods.py
File metadata and controls
175 lines (155 loc) · 5.74 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# GamesManager methods
# ver.1
# By Clok Much
import config
from os.path import isfile as winsys_isfile
from os.path import isdir as winsys_isdir
from tkinter.filedialog import askdirectory, askopenfilename
from tkinter.simpledialog import askstring
from tkinter import Tk, messagebox
import win32com.client
from json import load as load_json
def xprint(content=None):
"""
costumed print
input the content to be printed.
This is the template for input tuple or list:
[
[(queue), ("Plants VS Zombies FinVer.")],
[(default), ("Hollow Knight")],
[(default), ("Control")],
[(processing), ("Need For Speed Heat")]
]
, it will output like this:
1. Plants VS Zombies FinVer. / queue color
2. Hollow Knight / default color
3. Control / default color
4. Need for Speed Heat / processing color
Practical no. depends on the len of list or tuple.
if input None or not input, xprint will NOT output;
if input others, xprint will work like print.
"""
if (type(content) == list) or (type(content) == tuple):
for item in content:
try:
print(item[0][0] + item[1] + item[0][1])
except IndexError:
print("############INNER ERROR ON xprint due to content index, please contact author to fix it.")
else:
pass
elif not content:
pass
else:
print(content)
def try_find_volume():
"""
try to find a volume with games pool
Find the target: Return driver litter in a list
Not found: Return False
"""
volume_list = []
for i in range(67, 91):
volume_litter = chr(i) + ":\\"
if winsys_isfile(volume_litter + config.GamesPoolOfExternalStorage.pool_subdir
+ config.GamesPoolOfExternalStorage.pool_games_list):
volume = volume_litter
volume_list.append(volume)
if not volume_list:
return False
else:
return volume_list
def get_a_dir(tip_info=None, is_volume=False):
"""
Get a location via tkinter.filedialog.askdirectory
if is_volume = True: will return the target's volume
return a dir end with '\\'
"""
if not tip_info:
tip_info = ""
Tk().withdraw()
if is_volume:
messagebox.showinfo(title="Tip", message=(tip_info + "\nSelect a volume in next form...\n\n\
Or select a folder to take its volume."))
askdirectory_title = "Select a volume..."
else:
messagebox.showinfo(title="Tip", message=(tip_info + "\nSelect a folder in next form...."))
askdirectory_title = "Select a folder..."
target = askdirectory(title=askdirectory_title)
if is_volume:
target = target.replace("/", "\\")[:3]
return target
else:
if target[-1] != '/':
target = target.replace("/", "\\") + "\\"
else:
target = target.replace("/", "\\")
return target
def get_a_file(tip=None, special_filetype=None, initial_selector_dir=config.Default.games_main_dir):
"""
Get a game with tip.
special_filetype: [(description, ['.exe', '.doc']), +++++]
Return tuple: (game_full_path, file_type, file_dir)
file_type: "game" - ".exe", "launcher" - ".cmd", ".bat", "other" - other.
file_dir: with \\
"""
if not tip:
tip = "Select a file..."
if not special_filetype:
special_filetype = [('Executable game file', config.Default.games_file_type),
('Game launcher file', config.Default.launcher_file_type)]
Tk().withdraw()
target = askopenfilename(title=tip, filetypes=special_filetype,
initialdir=initial_selector_dir)
file_dir = "\\".join(target.replace("/", "\\").split('\\')[:-1]) + "\\"
if target[-4:] in config.Default.games_file_type:
result = (target, 'game', file_dir)
elif target[-4:] in config.Default.launcher_file_type:
result = (target, 'launcher', file_dir)
else:
result = (target, 'other', file_dir)
return result
def create_a_shortcut(source, name, target_dir, icon=None):
"""
Create a shortcut.
:param source: Original game or launcher.
:param name: Shortcut name with NO '.lnk'.
:param target_dir: Folder where shortcut will appear.
:param icon: Shortcut icon, need if target is a launcher.
"""
if source[-4:] in config.Default.launcher_file_type:
if not icon:
return 'ERROR, launcher need an icon!'
else:
icon = icon + ', 0'
else:
icon = source + ', 0'
shortcut = win32com.client.Dispatch("WScript.Shell").CreateShortCut(target_dir + name + '.lnk')
shortcut.TargetPath = source
shortcut.IconLocation = icon
shortcut.save()
def load_games_list(games_list):
"""
Games list full path.
Return: games_list load result as a dictionary:
(
{index/int/0:{'full_name', 'target', 'icon', 'state'}, index/int/1+++}, # Games
{'pool_index/int/0':{'pool_0':[1]}} # Games in pool index
)
"""
all_games = {}
pools = {}
with open(games_list, 'rb') as games_list:
load_result = load_json(games_list)
for game in load_result["games"]:
all_games[game["index"]] = {game["full_name"], game["target"], game["icon"], game["state"]}
for pool in load_result["pools"]:
pools[pool["pool_index"]] = pool["pool_contents"]
result = (all_games, pools)
return result
def save_games_list(games_list, location):
"""
Save a games list.
games_list/tuple: (game_full_name, game_full_path, game_icon, game_dir, game_state)
location/dir: full path.
"""
pass