Post by conster on May 2, 2021 9:18:12 GMT
For some reason Monkey2 can't autodetect my MSVC version so I had to update it manually.
But this time I just got bored and tried to write this script.
If you use MSVC to compile your code, place this python file right aside your env_windows.txt, it will update the versions.
But this time I just got bored and tried to write this script.
If you use MSVC to compile your code, place this python file right aside your env_windows.txt, it will update the versions.
import os
def updatemsvc():
##
msvcdir = 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC'
windowskitsdir = 'C:\\Program Files (x86)\\Windows Kits\\10'
try:
if not os.path.exists(msvcdir): Exception('MSVC directory could not be found')
if not os.path.exists(windowskitsdir): Exception('Windows Kits directory could not be found')
except e:
print(e)
##
msvcversion = ''
msvctoolsdir = os.path.join(msvcdir, 'Tools\\MSVC')
try:
versions = os.listdir(msvctoolsdir)
msvcversion = versions[-1]
msvctoolsdir = os.path.join(msvctoolsdir, msvcversion)
except:
print('could not get MSVC version')
return
##
try:
envfile = open('env_windows.txt')
lines = envfile.readlines()
envfile.close()
except:
print('could not open env_windows.txt')
print('place this script into the same directory')
return
##
kitversion = ''
try:
kitdirs = os.listdir(os.path.join(windowskitsdir, 'Lib'))
kitversion = kitdirs[-1]
if len(kitversion) == 0: Exception()
except:
print('could not get latest `Windows Kits` version')
print('make sure that the file paths are correct')
return
##
for i in range(len(lines)):
if lines[i].startswith('MX2_USE_MSVC='):
lines[i] = 'MX2_USE_MSVC=1'
elif lines[i].startswith('MX2_ARCH_WINDOWS='):
lines[i] = 'MX2_ARCH_WINDOWS=x64'
elif lines[i].startswith('MX2_MSVC_TOOLS_DIR='):
path = msvctoolsdir.split('Tools\\MSVC\\')
lines[i] = 'MX2_MSVC_TOOLS_DIR=${MX2_MSVC_DIR}\\Tools\\MSVC\\' + path[1]
elif lines[i].startswith('MX2_WINDOWS_KIT='):
lines[i] = 'MX2_WINDOWS_KIT=' + kitversion
break
if len(lines[i]) == 0: # fix to retain blank lines
lines[i] += '\n'
##
import time
os.rename('env_windows.txt', 'env_windows'+str(time.time())+'.txt')
outfile = open('env_windows.txt', 'w')
outfile.writelines(lines)
outfile.close()
##
print(f'updated to MSVC:{msvcversion} KIT:{kitversion}')
updatemsvc()