Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic symlinks #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def message_dir(msg):
if os_path.isdir(directory):
return directory
try:
# wth???
# great way to verify that the directory is at least valid
makedirs(directory)
rmdir(directory) # lol
return directory
Expand All @@ -68,8 +68,7 @@ def message_end(msg, code):
Show a message and exit.
"""
print("[bold green]" + msg)
input("Press Enter to exit.")
if os.environ.get("WT_SESSION"):
print("[bold]You are safe to close this window.")
else:
input("Press Enter to exit.")
exit(code)
103 changes: 65 additions & 38 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,60 +49,87 @@ def sourcemods_path():
except Exception:
return None

#def set_sourcemods_path(path):
# """
# Set sourcemod folder path.
# """
# if system() == 'Windows':
# global REGISTRY
# global REGISTRY_KEY
# if REGISTRY == 0:
# REGISTRY = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
# REGISTRY_KEY = winreg.OpenKeyEx(REGISTRY, 'SOFTWARE\Valve\Steam')
#
# value = winreg.SetValue(REGISTRY_KEY, 'SourceModInstallPath', winreg.REG_SZ, path)
# else:
# gui.message("Setting SourceModInstallPath isn't supported on Linux yet, resetting...", 5)
# setup_path(False)
#
def set_sourcemods_path():
"""
Set sourcemod folder path.
"""
if not vars.MAKE_SYMLINK:
return

try:
src = vars.SOURCEMODS_PATH
dest = vars.DEFAULT_SOURCEMODS_PATH

if vars.MOVE_TF2CLASSIC_FOLDER:
src += "/tf2classic"
dest += "/tf2classic"

# attempt to remove empty folder, otherwise it'll whine about it
if os.path.isdir(dest):
os.rmdir(dest)

# do the symlink
os.symlink(src, dest)
except Exception:
print("Warning: could not create symlink. is the program running with elevated permissions? This only means TF2Classic will have trouble showing up on Steam.");

def setup_default_path():
vars.DEFAULT_SOURCEMODS_PATH = sourcemods_path()
if vars.DEFAULT_SOURCEMODS_PATH is not None:
vars.DEFAULT_SOURCEMODS_PATH = sourcemods_path().rstrip('\"')

def setup_path(manual_path):
"""
Choose setup path.
"""
confirm = False
if sourcemods_path() is not None:
vars.SOURCEMODS_PATH = sourcemods_path().rstrip('\"')

smodsfound = isinstance(vars.SOURCEMODS_PATH, str)
if smodsfound is True and manual_path is not True:
gui.message('Sourcemods folder was automatically found at: ' + vars.SOURCEMODS_PATH)
smodsfound = isinstance(vars.DEFAULT_SOURCEMODS_PATH, str)
if smodsfound and (not manual_path):
vars.MOVE_TF2CLASSIC_FOLDER = False
vars.MAKE_SYMLINK = False

gui.message('Sourcemods folder was automatically found at: ' + vars.DEFAULT_SOURCEMODS_PATH)
if gui.message_yes_no('It\'s the recommended installation location. Would you like to install TF2Classic there?'):
vars.SOURCEMODS_PATH = vars.DEFAULT_SOURCEMODS_PATH
confirm = True
else:
# check if any sourcemods exists there
#no_sourcemods = True
#if os.path.exists(vars.SOURCEMODS_PATH):
# for file in os.listdir(vars.SOURCEMODS_PATH):
# if os.path.isdir(file):
# no_sourcemods = False
#if no_sourcemods:
# if system() == 'Windows':
# if gui.message_yes_no('Then, would you like to move the sourcemods folder location?'):
# vars.SOURCEMODS_PATH = gui.message_dir('Please enter the location of the new sourcemods folder')
# set_sourcemods_path(vars.SOURCEMODS_PATH)
# confirm = True
# else:
# manual_path = True
setup_path(True)
no_sourcemods = True
if os.path.exists(vars.DEFAULT_SOURCEMODS_PATH):
for file in os.listdir(vars.DEFAULT_SOURCEMODS_PATH):
# there's something in the sourcemods folder, will have to assume it isn't empty
no_sourcemods = False
break

if no_sourcemods:
if gui.message_yes_no('Then, would you like to move the sourcemods folder location?'):
vars.SOURCEMODS_PATH = gui.message_dir('Please enter the location of the new sourcemods folder')
vars.MAKE_SYMLINK = True
else:
setup_path(True)
return
else:
setup_path(True)
return
else:
gui.message('WARNING: Steam\'s sourcemods folder has not been found, or you chose not to use it.')
if gui.message_yes_no('Would you like to extract in ' + os.getcwd() + '? You must move it to your sourcemods manually.'):
vars.MOVE_TF2CLASSIC_FOLDER = True
vars.MAKE_SYMLINK = smodsfound

msg = 'Would you like to install in ' + os.getcwd() + '?'

if not smodsfound:
gui.message('WARNING: Steam\'s sourcemods folder has not been found.')
msg += " You must move it to your sourcemods manually."
else:
gui.message('WARNING: You chose not to use the Steam\'s sourcemods folder.')

if gui.message_yes_no(msg):
vars.SOURCEMODS_PATH = os.getcwd()
confirm = True
else:
vars.SOURCEMODS_PATH = gui.message_dir('Please, enter the location in which TF2Classic will be installed to.\n')

# one final confirmation
if not confirm:
if not gui.message_yes_no('TF2Classic will be installed in ' + vars.SOURCEMODS_PATH + '\nDo you accept?'):
print('Resetting...\n')
Expand Down
5 changes: 3 additions & 2 deletions tf2c_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ def sanity_check():
exit(1)
try:
sanity_check()
setup.setup_default_path()
setup.setup_path(False)
setup.setup_binaries()
install.free_space_check()
install.tf2c_download()
install.tf2c_extract()
setup.set_sourcemods_path()
except:
traceback.print_exc()
print("[italic magenta]----- Exception details above this line -----")
print("[bold red]:warning: The program has failed. Post a screenshot in #technical-issues on the Discord. :warning:[/bold red]")
input("Press Enter to exit.")
if os.environ.get("WT_SESSION"):
print("[bold]You are safe to close this window.")
else:
input("Press Enter to exit.")
exit(1)


Expand Down
4 changes: 3 additions & 1 deletion vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@
# ARC_BINARY is only used on Windows.
ARC_BINARY = None
SOURCEMODS_PATH = None
TF2C_PATH = None
MAKE_SYMLINK = False
MOVE_TF2CLASSIC_FOLDER = False
DEFAULT_SOURCEMODS_PATH = None