Skip to content

Commit 40502f3

Browse files
committed
Avoid making a mess in the current working directory when using system python.
1 parent cfcad44 commit 40502f3

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

alternative-install/RLBotGUI.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ rem Install and / or upgrade RLBot components
3939
%rlbotpy% -m pip install --upgrade rlbot_gui rlbot
4040

4141
rem Launch the GUI
42-
42+
cd %LocalAppData%\RLBotGUIX
4343
%rlbotpy% -c "from rlbot_gui import gui; gui.start()"

rlbot_gui/gui.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,17 +419,35 @@ def is_botpack_up_to_date():
419419
return github_commit_id == local_commit_id
420420

421421

422+
def get_content_folder():
423+
if Path(os.getcwd()).name == 'RLBotGUI':
424+
# This is the classic case where we're using embedded python, and our current working directory is already
425+
# something like C:\Users\tareh\AppData\Local\RLBotGUI. It will also match if you have cloned RLBotGUI.
426+
return Path(os.getcwd())
427+
428+
# If we get here, we're likely using system python or something along those lines.
429+
local_app_data = os.getenv('LOCALAPPDATA')
430+
if local_app_data:
431+
# We appear to be on Windows platform. This is where the new Windows launch script puts things.
432+
guix_path = Path(os.getenv('LOCALAPPDATA')) / 'RLBotGUIX'
433+
guix_path.mkdir(exist_ok=True)
434+
return guix_path
435+
436+
# Probably on linux or mac at this point. Go with CWD again, because that's what they've used historically.
437+
return Path(os.getcwd())
438+
439+
440+
422441
@eel.expose
423442
def download_bot_pack():
443+
content_folder = get_content_folder()
444+
botpack_location = content_folder / BOTPACK_FOLDER
445+
424446
# The bot pack in now hosted at https://github.com/RLBot/RLBotPack
425-
BotpackDownloader().download(BOTPACK_REPO_OWNER, BOTPACK_REPO_NAME, BOTPACK_REPO_BRANCH, BOTPACK_FOLDER)
447+
BotpackDownloader().download(BOTPACK_REPO_OWNER, BOTPACK_REPO_NAME, BOTPACK_REPO_BRANCH, botpack_location)
426448

427449
# Configure the folder settings.
428-
bot_folder_settings['folders'][os.path.abspath(BOTPACK_FOLDER)] = {'visible': True}
429-
430-
if os.path.abspath(OLD_BOTPACK_FOLDER) in bot_folder_settings['folders']:
431-
# Toggle off the old one since it's been replaced.
432-
bot_folder_settings['folders'][os.path.abspath(OLD_BOTPACK_FOLDER)] = {'visible': False}
450+
bot_folder_settings['folders'][str(botpack_location)] = {'visible': True}
433451

434452
settings = load_settings()
435453
settings.setValue(BOT_FOLDER_SETTINGS_KEY, bot_folder_settings)
@@ -450,11 +468,11 @@ def hot_reload_python_bots():
450468

451469

452470
def ensure_bot_directory():
453-
bot_directory = CREATED_BOTS_FOLDER
454-
if not os.path.exists(bot_directory):
455-
os.mkdir(bot_directory)
471+
content_folder = get_content_folder()
472+
bot_directory = content_folder / CREATED_BOTS_FOLDER
473+
bot_directory.mkdir(exist_ok=True)
456474

457-
bot_folder_settings['folders'][os.path.abspath(CREATED_BOTS_FOLDER)] = {'visible': True}
475+
bot_folder_settings['folders'][str(bot_directory)] = {'visible': True}
458476
settings = load_settings()
459477
settings.setValue(BOT_FOLDER_SETTINGS_KEY, bot_folder_settings)
460478
settings.sync()

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import setuptools
22

3-
__version__ = '0.0.60'
3+
__version__ = '0.0.61'
44

55
with open("README.md", "r") as readme_file:
66
long_description = readme_file.read()

0 commit comments

Comments
 (0)