-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSetup.py
More file actions
165 lines (125 loc) · 4.26 KB
/
Setup.py
File metadata and controls
165 lines (125 loc) · 4.26 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
#
# Libraries
#
import os
import shutil
import ctypes
#
# Getting the DOCUMENTS path
#
def get_documents_path( ) -> str:
#
# For Windows 7 and later
#
CSIDL_PERSONAL = 5
#
# Get the path using Windows API
#
buf = ctypes.create_unicode_buffer( 260 )
ctypes.windll.shell32.SHGetFolderPathW(None, CSIDL_PERSONAL, None, 0, buf)
return buf.value
#
# Get VS installation
#
def get_templates_path( documents_path ) -> str:
if os.path.exists( f"{ documents_path }\\Visual Studio 2015" ):
return f"{ documents_path }\\Visual Studio 2015"
if os.path.exists( f"{ documents_path }\\Visual Studio 2019" ):
return f"{ documents_path }\\Visual Studio 2019"
if os.path.exists( f"{ documents_path }\\Visual Studio 2022" ):
return f"{ documents_path }\\Visual Studio 2022"
return None
#
# Copy folder & Content
#
def copy_folder( source_dir, destination_dir ) -> bool :
#
# Status
#
status = True
#
# Checking the source directory & the destination directory
#
if not os.path.exists( source_dir ):
print(" [ ERROR ] Could not find the source path!")
return
if not os.path.exists( destination_dir ):
os.makedirs( destination_dir )
#
# Copying the files
#
for item in os.listdir( source_dir ):
source_item = os.path.join( source_dir, item )
destination_item = os.path.join( destination_dir, item )
try:
if os.path.isdir( source_item ):
shutil.copytree( source_item, destination_item )
else:
shutil.copy2( source_item, destination_item )
print( f" [ SETUP ] Copied '{ source_item }' to '{ destination_item }'" )
except shutil.Error as e:
print( f" [ ERROR ] Could not copy '{ source_item }': { e }" )
status = False
except OSError as e:
print( f" [ ERROR ] OS error occurred while copying '{ source_item }': { e }" )
status = False
return status
#
# Main function
#
def main( ) -> None:
#
# Changing the console color
#
os.system( "color a" )
#
# Credits
#
print( "\n------------------------------------------------------------------" )
print( " Simple MSVC_UEFI By: Th3Spl\n" )
print( " Credits:")
print( " - VisualUEFI: https://github.com/ionescu007/VisualUefi" )
print( " - EDK2: https://github.com/tianocore/edk2" )
print( "------------------------------------------------------------------\n" )
print( " [ SETUP ] Initializing the setup..." )
#
# Notifying
#
print( " [ SETUP ] Environment variables successfully found" )
#
# Copying the components within a universal path
#
if copy_folder( ".\\MSVC_UEFI", "C:\\Program Files\\MSVC_UEFI" ):
print( " [ SETUP ] All files copied successfully!" )
else:
print( " [ ERROR ] Could not copy all the needed files!" )
#
# Making the user compile VisualUefi
#
print( " [ SETUP ] Opening the folder\n" )
print( " [ SETUP ] Please open 'EDK-II.sln' and build the entier solution.\n" )
os.system( f"explorer \"C:\\Program Files\\MSVC_UEFI\\VisualUefi\\EDK-II\"" )
print( " Presss any key once you compiled VisualUefi...\n" )
os.system( "pause>nul" )
#
# Findig out which VisualStudio installation the user has
#
templates_path = get_templates_path( get_documents_path() )
if templates_path != None:
print( " [ SETUP ] Templates path found successfully" )
else:
print( " [ ERROR ] Could not find a VS templates path!" )
return
#
# Once the user has compield VisualUefi
#
if copy_folder( ".\\Templates", f"{ templates_path }\\Templates\\ProjectTemplates" ):
print( " [ SETUP ] All templates copied successfully!" )
else:
print( " [ SETUP ] Could not copy all the templates!" )
return
#
# Starting the main routine
#
if __name__ == "__main__":
main( )