Skip to content

Instantly share code, notes, and snippets.

@lokifer
Last active August 29, 2015 13:59
Show Gist options
  • Save lokifer/10893555 to your computer and use it in GitHub Desktop.
Save lokifer/10893555 to your computer and use it in GitHub Desktop.
Shortcut creation script for LAN games
from __future__ import print_function
import os
import ctypes
import win32api
import win32con
import win32com.client
import getpass
#Get windows username
username = getpass.getuser()
#Get screen res
user32 = ctypes.windll.user32
x = user32.GetSystemMetrics(0)
y = user32.GetSystemMetrics(1)
#Set our parent dir path
if 'BushLAN' not in os.path.abspath(os.path.dirname(__file__)):
print('Script must be run from BushLAN folder')
exit(1)
else:
bushlanpath = os.path.abspath(os.path.dirname(__file__))
# Get some steam vars
try:
hKey = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, r"Software\Valve\Steam")
steampath, type = win32api.RegQueryValueEx(hKey, "SteamPath")
nick, type = win32api.RegQueryValueEx(hKey, "LastGameNameUsed")
except WindowsError:
print('')
# Decided to use a list to iterate over, then dicts for each game. Could be handled as json I think
games = [
{
'tpath': 'Quake',
'name': 'Quake',
'exe': 'Darkplaces.exe',
'arguments': '-width {x} -height {y} -bpp 32 -fullscreen 1'
},
{
'tpath': 'Quake3',
'name': 'Quake3',
'exe': 'ioquake3.x86.exe',
'arguments': '+set r_customwidth {x} +set r_customheight {y} +set r_mode -1 {o}'
},
{
'tpath': 'Age of Mythology',
'name': 'AoM',
'exe': "aomx.exe",
'arguments': 'xres={x} yres={y} bpp=32 +noIntroCinematics'
},
{
'tpath': 'Unreal Tournament\\System',
'name': 'UT99',
'exe': 'UnrealTournament.exe',
'arguments': ''
}
]
def makeshortcut(tpath, name, exe, arguments):
workingdir = os.path.join(
bushlanpath,
tpath
)
shell = win32com.client.Dispatch("WScript.Shell")
fullpath = os.path.join(
workingdir,
os.path.abspath(os.path.dirname(__file__)),
"{0}.lnk".format(name)
)
shortcut = shell.CreateShortCut(fullpath)
shortcut.Targetpath = os.path.join(
workingdir,
exe
)
shortcut.Arguments = arguments
shortcut.WorkingDirectory = workingdir
shortcut.save()
print('Created shortcut {} at {}'.format(
name, fullpath
))
if __name__ == '__main__':
print('Hello {}!'.format(username))
print('I think your resolution is {}x{}'.format(x, y))
print('Your Steam is located at {}'.format(steampath))
print('The last name you used on steam was {}'.format(nick))
#makeshortcut('Quake3', 'Quake3', 'ioquake3.x86.exe', '')
# setting up o for options, still thinking about how to do this properly for mods etc
o = None
for game in games:
makeshortcut(game['tpath'], game['name'], game['exe'], game['arguments'].format(
x=x, y=y, o=o)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment