Skip to content

Commit a3c45b2

Browse files
committed
Launcher folder
1 parent 7d18af3 commit a3c45b2

File tree

3 files changed

+68
-30
lines changed

3 files changed

+68
-30
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ A cross-platform CLI launcher for Toontown Rewritten written in Python and insta
88
pip install gttrl
99
```
1010
3. Run on the command line:
11+
```
12+
gttrl
13+
```
14+
or specify your account credentials using arguments:
1115
```
1216
gttrl -u username -p password
1317
```
1418
15-
## Account file
16-
The account file is a text file with the following format:
19+
## Launcher folder
20+
Once you run the launcher, a folder will be created at `<user home directory>/.gttrl` to store the configuration file and the game files.
21+
22+
## Configuration
23+
You can configure the launcher by editing the `config.json` file in the launcher folder.
24+
25+
## Auto login
26+
To enable auto login, create a file named `account.txt` in the launcher folder and put your account credentials in it, separated by a newline:
1727
```
1828
username
1929
password
@@ -22,29 +32,28 @@ password
2232
## Usage
2333
```
2434
usage: gttrl [-h] [-u USERNAME] [-p PASSWORD] [-a ACCOUNT_FILE]
25-
[-f GAME_PATH] [-c PLAY_COOKIE] [-g GAME_SERVER] [-s] [-k]
35+
[-m GAME_PATH] [-c PLAY_COOKIE] [-g GAME_SERVER] [-s] [-k]
2636
[-e] [-v]
2737

2838
Glomatico's Toontown Rewritten Launcher
2939

3040
options:
3141
-h, --help show this help message and exit
3242
-u USERNAME, --username USERNAME
33-
Account username (default: None)
43+
Account username
3444
-p PASSWORD, --password PASSWORD
35-
Account password (default: None)
45+
Account password
3646
-a ACCOUNT_FILE, --account-file ACCOUNT_FILE
37-
Account file location (default: ./account.txt)
38-
-f GAME_PATH, --game-path GAME_PATH
39-
Game path (default: ./Toontown Rewritten)
47+
Account file location
48+
-m GAME_PATH, --game-path GAME_PATH
49+
Game path
4050
-c PLAY_COOKIE, --play-cookie PLAY_COOKIE
41-
Play cookie (default: None)
51+
Play cookie
4252
-g GAME_SERVER, --game-server GAME_SERVER
43-
Game server (default: None)
44-
-s, --skip-update Skip game update (default: False)
53+
Game server
54+
-s, --skip-update Skip game update
4555
-k, --print-play-cookie
46-
Print play cookie and game server and exit (default:
47-
False)
48-
-e, --enable-log Enable log (default: False)
56+
Print play cookie and game server and exit
57+
-e, --enable-log Enable logging to the console
4958
-v, --version show program's version number and exit
5059
```

gttrl/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import argparse
2+
import getpass
23
from pathlib import Path
34

4-
from .gttrl import Gttrl
5+
from .gttrl import Config, Gttrl
56

6-
__version__ = "1.0"
7+
__version__ = "1.1"
78

89

910
def main():
1011
parser = argparse.ArgumentParser(
1112
description="Glomatico's Toontown Rewritten Launcher",
12-
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
1313
)
1414
parser.add_argument(
1515
"-u",
@@ -24,13 +24,11 @@ def main():
2424
parser.add_argument(
2525
"-a",
2626
"--account-file",
27-
default="./account.txt",
2827
help="Account file location",
2928
)
3029
parser.add_argument(
31-
"-f",
30+
"-m",
3231
"--game-path",
33-
default="./Toontown Rewritten",
3432
help="Game path",
3533
)
3634
parser.add_argument(
@@ -59,7 +57,7 @@ def main():
5957
"-e",
6058
"--enable-log",
6159
action="store_true",
62-
help="Enable log",
60+
help="Enable logging to the console",
6361
)
6462
parser.add_argument(
6563
"-v",
@@ -68,15 +66,18 @@ def main():
6866
version=f"%(prog)s {__version__}",
6967
)
7068
args = parser.parse_args()
69+
config = Config()
70+
config.create_if_not_exists()
71+
config_file = config.read_config_file()
7172
username = args.username
7273
password = args.password
73-
account_file = args.account_file
74-
game_path = args.game_path
74+
account_file = args.account_file or config_file["account_file"]
75+
game_path = args.game_path or config_file["game_path"]
7576
play_cookie = args.play_cookie
7677
game_server = args.game_server
77-
skip_update = args.skip_update
78+
skip_update = args.skip_update or config_file["skip_update"]
7879
print_play_cookie = args.print_play_cookie
79-
enable_log = args.enable_log
80+
enable_log = args.enable_log or config_file["enable_log"]
8081
if (username and not password) or (password and not username):
8182
raise Exception("Username and password must be provided together")
8283
elif (play_cookie and not game_server) or (game_server and not play_cookie):
@@ -86,9 +87,8 @@ def main():
8687
with open(account_file, "r") as file:
8788
username, password = file.read().splitlines()
8889
elif not username and not play_cookie:
89-
raise Exception(
90-
"Account file does not exist and no others forms of authentication were provided"
91-
)
90+
username = input("Username: ")
91+
password = getpass.getpass("Password: ")
9292
gttrl = Gttrl(username, password, game_path, enable_log)
9393
if username:
9494
print("Logging in...")

gttrl/gttrl.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import bz2
22
import hashlib
3+
import json
34
import os
45
import platform
56
import subprocess
@@ -73,10 +74,11 @@ def get_file_sha1(self, file_location: Path):
7374
return hasher.hexdigest()
7475

7576
def download_game_files(self):
77+
if not self.game_path.exists():
78+
self.game_path.mkdir(parents=True, exist_ok=True)
7679
manifest = self.session.get(
7780
"https://cdn.toontownrewritten.com/content/patchmanifest.txt"
7881
).json()
79-
self.game_path.mkdir(parents=True, exist_ok=True)
8082
keys = list(manifest.keys())
8183
for key in keys:
8284
if self.os not in manifest[key]["only"]:
@@ -161,9 +163,36 @@ def launch_game(self, play_cookie, game_server):
161163
creationflags=subprocess.CREATE_NO_WINDOW,
162164
)
163165
else:
164-
os.chmod(self.game_exe, 0o755)
166+
if not os.access(self.game_exe, os.X_OK):
167+
os.chmod(self.game_exe, 0o755)
165168
subprocess.Popen(
166169
[self.game_exe],
167170
stdout=subprocess.DEVNULL,
168171
stderr=subprocess.DEVNULL,
169172
)
173+
174+
175+
class Config:
176+
def __init__(self):
177+
self.config_path = Path.home() / ".gttrl"
178+
self.config_location = self.config_path / "config.json"
179+
180+
def create_if_not_exists(self):
181+
if not self.config_path.exists():
182+
self.config_path.mkdir(parents=True, exist_ok=True)
183+
if not self.config_location.exists():
184+
with open(self.config_location, "w") as f:
185+
json.dump(
186+
{
187+
"game_path": str(self.config_path / "Toontown Rewritten"),
188+
"skip_update": False,
189+
"enable_log": False,
190+
"account_file": str(self.config_path / "account.txt"),
191+
},
192+
f,
193+
indent=4,
194+
)
195+
196+
def read_config_file(self):
197+
with open(self.config_location, "r") as f:
198+
return json.load(f)

0 commit comments

Comments
 (0)