-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
139 lines (117 loc) · 5.24 KB
/
Copy pathcli.py
File metadata and controls
139 lines (117 loc) · 5.24 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
#!/usr/bin/env python3
"""
VelocityRL CLI — standalone interactive item swap tool.
Run 'velocityrl' to enter interactive mode.
Run 'velocityrl --config' to update your game directory.
"""
import json
import sys
import threading
from pathlib import Path
VERSION = "1.2.2"
RELEASES_URL = "https://github.com/bitsfdb/VelocityRL/releases/latest"
_RELEASES_API = "https://api.github.com/repos/bitsfdb/VelocityRL/releases/latest"
def _print_update_notice():
try:
import urllib.request
req = urllib.request.Request(_RELEASES_API, headers={"User-Agent": f"velocityrl-cli/{VERSION}"})
with urllib.request.urlopen(req, timeout=4) as r:
data = json.loads(r.read())
latest = data.get("tag_name", "").lstrip("v")
if latest and latest != VERSION:
print(f"\n *** Update available: v{latest} → {RELEASES_URL}\n")
except Exception:
pass
# ── Resource paths ────────────────────────────────────────────────────────────
# PyInstaller bundles files into sys._MEIPASS; when running from source,
# look in the same directory as this script.
RESOURCE_DIR = Path(getattr(sys, '_MEIPASS', Path(__file__).parent))
if str(RESOURCE_DIR) not in sys.path:
sys.path.insert(0, str(RESOURCE_DIR))
import rl_asset_swapper as engine # noqa: E402
# ── Config ────────────────────────────────────────────────────────────────────
CONFIG_FILE = Path.home() / '.velocityrl.json'
def load_config() -> dict:
try:
return json.loads(CONFIG_FILE.read_text())
except Exception:
return {}
def save_config(cfg: dict):
CONFIG_FILE.write_text(json.dumps(cfg, indent=2))
# ── Windows game-dir auto-detection ──────────────────────────────────────────
_CANDIDATE_DIRS = [
'C:/Program Files (x86)/Steam/steamapps/common/rocketleague/TAGame/CookedPCConsole',
'C:/Program Files/Steam/steamapps/common/rocketleague/TAGame/CookedPCConsole',
'D:/SteamLibrary/steamapps/common/rocketleague/TAGame/CookedPCConsole',
'E:/SteamLibrary/steamapps/common/rocketleague/TAGame/CookedPCConsole',
'D:/Games/rocketleague/TAGame/CookedPCConsole',
'C:/Games/rocketleague/TAGame/CookedPCConsole',
]
def detect_game_dir():
for p in _CANDIDATE_DIRS:
pp = Path(p)
if pp.exists():
return pp
if sys.platform == 'win32':
try:
import winreg
for hive in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER):
for sub in (
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 252950',
r'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 252950',
):
try:
with winreg.OpenKey(hive, sub) as k:
loc = winreg.QueryValueEx(k, 'InstallLocation')[0]
pp = Path(loc) / 'TAGame' / 'CookedPCConsole'
if pp.exists():
return pp
except (FileNotFoundError, OSError):
pass
except ImportError:
pass
return None
# ── Main ──────────────────────────────────────────────────────────────────────
def main():
print(f"VelocityRL CLI v{VERSION}")
print("A desktop application with a full UI is available at: https://velocityrl.tech")
print()
threading.Thread(target=_print_update_notice, daemon=True).start()
cfg = load_config()
if '--config' in sys.argv:
cur = cfg.get('game_dir', 'not set')
print(f'Current game directory: {cur}')
path = input('New CookedPCConsole path (Enter to keep): ').strip().strip('"')
if path:
cfg['game_dir'] = path
save_config(cfg)
print(f'Saved to {CONFIG_FILE}')
sys.exit(0)
# First-run: detect or ask for game directory
if 'game_dir' not in cfg:
print('VelocityRL — first run setup')
print('─' * 50)
found = detect_game_dir()
if found:
print(f'Found Rocket League: {found}')
answer = input('Use this directory? [Y/n]: ').strip().lower()
if answer in ('', 'y', 'yes'):
cfg['game_dir'] = str(found)
save_config(cfg)
if 'game_dir' not in cfg:
path = input('Enter CookedPCConsole path: ').strip().strip('"')
if not path:
sys.exit('Aborted.')
cfg['game_dir'] = path
save_config(cfg)
print()
game_dir = Path(cfg['game_dir'])
parser = engine.build_arg_parser()
args = parser.parse_args()
if not args.donor_dir:
args.donor_dir = game_dir
if not args.output_dir:
args.output_dir = game_dir
sys.exit(engine.cli_run(args))
if __name__ == '__main__':
main()