-
Notifications
You must be signed in to change notification settings - Fork 2
/
UserOptions.py
107 lines (72 loc) · 3.27 KB
/
UserOptions.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
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
import pathlib
import os, re
from PIL import Image
# this class check and validate all of the user inputs to make sure the program wont fail.
# it also generate a whole lot of other important info
class UserOptions():
gameName = ""
gameURL = ""
originalIconPath = ""
steamPath = ""
customShortcutFolder = ""
userName = ""
steamDirtectory = ""
shortcutPath = ""
gameFolderPath = ""
vbsFile = ""
visualElementsManifestFile = ""
visualElementsFolder = ""
mediumIconPath = ""
smallIconPath = ""
mediumIconMetaPath = ""
smallIconMetaPath = ""
def __init__(self, gameName, gameURL, icon, steamPath, customShortcutFolder):
self.setGameName(gameName)
self.setGameURL(gameURL)
self.setOriginalIconPath(icon)
self.setSteamPath(steamPath)
self.setCustomShortcutFolder(customShortcutFolder)
self.generate()
def generate(self):
self.steamDirtectory = "\\".join(self.steamPath.split("\\")[:-1]) + "\\"
self.shortcutPath = os.path.join(pathlib.Path.home(), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "TileIconify", "Custom Shortcuts", self.gameName, self.gameName + ".lnk")
self.gameFolderPath = os.path.join(self.customShortcutFolder, self.gameName)
self.vbsFile = os.path.join(self.gameFolderPath, self.gameName + ".vbs")
self.visualElementsManifestFile = os.path.join(self.gameFolderPath, self.gameName + ".VisualElementsManifest.xml")
self.visualElementsFolder = os.path.join(self.gameFolderPath, "VisualElements")
self.mediumIconPath = os.path.join(self.visualElementsFolder, f"MediumIcon{self.gameName}.png")
self.smallIconPath = os.path.join(self.visualElementsFolder, f"SmallIcon{self.gameName}.png")
self.mediumIconMetaPath = os.path.join(self.visualElementsFolder, f"MediumIcon{self.gameName}_Metadata.xml")
self.smallIconMetaPath = os.path.join(self.visualElementsFolder, f"SmallIcon{self.gameName}_Metadata.xml")
def setGameName(self, title):
if(title == ""):
raise ValueError("Invalid game title.")
self.gameName = title
def setGameURL(self, url):
if(url == ""):
raise ValueError("Invalid game url.")
re_steamURL = re.compile("^steam://rungameid/[0-9]+$")
if(not re_steamURL.match(url)):
raise ValueError("Invalid game url.")
self.gameURL = url
def setOriginalIconPath(self, path):
if(path == ""):
raise ValueError("Invalid icon path.")
if(not os.path.exists(path)):
raise ValueError("Cannot find " + path + ".")
try: # check if the file is valid for PILLOW
icon = Image.open(path)
del icon
except OSError:
raise ValueError("Incompatible image file.")
self.originalIconPath = path
def setSteamPath(self, path):
if(path == ""):
raise ValueError("Invalid steam path.")
if(not os.path.exists(path)):
raise ValueError("Cannot find " + path + ".")
self.steamPath = path
def setCustomShortcutFolder(self, path):
if(path == ""):
raise ValueError("Invalid custom shortcut path.")
self.customShortcutFolder = path